I am -1 with this change.  This is NOT a simplification, but rather a complication.  This suggest will be more difficult to document, more difficult to extend in the future, and will also introduce two mechanisms for creating comparators (options on the method vs. direct instantiation) which will be confusing to many users. 

You still have 4 different methods, but now the spelling is is a complicated combination of options that crams all of the variations into a single method.  Good object-oriented practice is a method should perform one function and do it well.  Class subclasses will then only need to deal with the particular functions they wish to override without requiring an awareness of all of the other options (and being vulnerable to potential additions in the future).

Rick

On 5/28/07, Rony G. Flatscher <Rony.Flatscher@wu-wien.ac.at> wrote:
Hi there,

while looking into the new sorting abilities made available via four sort methods in the array class (namely "sort", "sortWith", "stableSort", "stableSortWith") in combination with the comparator concept supplied in the form of the classes "Comparator", "CaslessComparator", "DescendingComparator", "DescendingCaselessComparator", "InvertingComparator", "ColumnComparator" and "DescendingColumnComparator" the application of the various sort capabilities could be probably simplified for most sorting needs, if folding all four sort methods into one. This would probably make applying the sort simpler and easier, i.e. more "human-centric"/Rexx-like.

Consider the following code which demonstrates using the various sort features as mandated by the current 3.2.0 implementation:
arr=.array~of("Rick", "Mark", "mark", "mark", "Mark", "rick", "David", "rony")

/* standard comparators (ascending/descending, ignoreCase, sort/stableSort) */
arr~sort
arr~sortWith(.comparator~new)
arr~sortWith(.CaselessComparator~new)

arr~stableSortWith(.comparator~new)
arr~stableSortWith(.CaselessComparator~new)

arr~sortWith(.DescendingComparator~new)
arr~sortWith(.InvertingComparator~new(.Comparator~new))

arr~stableSortWith(.DescendingComparator~new)
arr~stableSortWith(.InvertingComparator~new(.DescendingComparator~new))

arr~sortWith(.DescendingCaselessComparator~new)
arr~sortWith(.InvertingComparator~new(.DescendingCaselessComparator~new))

arr~stableSortWith(.DescendingCaselessComparator~new)
arr~stableSortWith(.InvertingComparator~new(.DescendingCaselessComparator~new))

/* columnComparators */
arr~sortWith(.ColumnComparator~new(5,10))
arr~sortWith(.CaselessColumnComparator~new(5,10))

arr~stableSortWith(.ColumnComparator~new(5,10))
arr~stableSortWith(.CaselessColumnComparator~new(5,10))

arr~sortWith(.InvertingComparator~new(.ColumnComparator~new(5,10)))
arr~stableSortWith(.InvertingComparator~new(.ColumnComparator~new(5,10)))

arr~sortWith(.InvertingComparator~new(.CaselessColumnComparator~new(5,10)))
arr~stableSortWith(.InvertingComparator~new(.CaselessColumnComparator~new(5,10)))
In order to simplify the sorting I propose to fold the Array's four sort methods "sort", "sortWith", "stableSort", "stableSortWith" into one "sort" method: the first optional argument is a string containing concatenated letters (like in SysFileTree) or blank-delimited words (like in the STREAM-BIF) indicating the desired sort type, the second optional argument can be a comparator object. Hence the first argument would be one of:
  • A[ascend] |  D[escending] ... default: "A"
  • I[gnoreCase] ... default: do honor case
  • S[tableSort] ... default: quicksort
The SysFileTree()-like version (argument letters concatenated with each other, order not significant):
/* SysFileTree()-like argument ------------------- */
arr~sort1 /* ascending */
arr~sort1("A") /* ascending */
arr~sort1("I") /* ascending, ignore case */

arr~sort1("S") /* ascending, stable sort */
arr~sort1("SI") /* ascending, stable sort, ignore case */

arr~sort1("D") /* descending */
arr~sort1("DS") /* descending, stable sort */
arr~sort1("DI") /* descending, ignore case */
arr~sort1("DSI") /* descending, stable sort, ignore case */

/* columnComparators */
arr~sort1("A", .ColumnComparator~new(5,10)) /* ascending */
arr~sort1("A", .CaselessColumnComparator~new(5,10)) /* ascending */

arr~sort1("AS", .ColumnComparator~new(5,10)) /* ascending, stable sort */
arr~sort1("AS", .CaselessColumnComparator~new(5,10)) /* ascending, stable sort */

arr~sort1("D", .ColumnComparator~new(5,10)) /* descending */
arr~sort1("DS", .ColumnComparator~new(5,10)) /* descending, stable sort */

arr~sort1("D", .CaselessColumnComparator~new(5,10)) /* descending */
arr~sort1("DS", .CaselessColumnComparator~new(5,10)) /* descending, stable sort */
The Stream()-BIF-like version (argument consists of blank delimited words, where the first letter is significant, order not significant):
/* Stream()-BIF-like argument ------------------- */
arr~sort2 /* ascending */
arr~sort2("Asc") /* ascending */
arr~sort2("IgnoreCase") /* ascending, ignore case */

arr~sort2("Stable") /* ascending, stable sort */
arr~sort2("S I") /* ascending, stable sort, ignore case */
arr~sort2("Stable IgnoreCase") /* ascending, stable sort, ignore case */

arr~sort2("D") /* descending */
arr~sort2("D S") /* descending, stable sort */
arr~sort2("D I") /* descending, ignore case */
arr~sort2("D S I") /* descending, stable sort, ignore case */
arr~sort2("Desc Stable Ignore") /* descending, stable sort, ignore case */

/* columnComparators */
arr~sort2("A", .ColumnComparator~new(5,10)) /* ascending */
arr~sort2("A", .CaselessColumnComparator~new(5,10)) /* ascending */

arr~sort2("A S", .ColumnComparator~new(5,10)) /* ascending, stable sort */
arr~sort2("A S", .CaselessColumnComparator~new(5,10)) /* ascending, stable sort */

arr~sort2("D", .ColumnComparator~new(5,10)) /* descending */
arr~sort2("D S", .ColumnComparator~new(5,10)) /* descending, stable sort */

arr~sort2("D", .CaselessColumnComparator~new(5,10)) /* descending */
arr~sort2("D S", .CaselessColumnComparator~new(5,10)) /* descending, stable sort */
A test program which allows you for testing this on a 3.2.0beta is attached.

Any comments?

---rony



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel