Hi all,

While reading thourhg the code I came upon the snipet of documentation that describes the way two transactions are compared with eachother. According to that documentation, the num field is sorted alphabetically, not numerically.

If feel that this is not what users expect, since not many people expect 10 to come before 2. However, since also alphanumeric data may be entered in the 'num' field, we cannot just begin sorting numerically.

There are some alternatives, and that is why I'm asking the developer community.

The first one would keep the scheme as it is, leaving it as a small discomfort. It would sort like: "1, 12, 2, 2a, 2b, 2c, 3, 4, duck, wood"

The second alternative would work like the following algorithm:
sort (a, b) {
 if (a and b is an integer) {
   return a < b ? -1 : a > b ? 1 : 0;
 } else if (a is an integer, but b not) {
    return -1;
 } else if (a is not an integer, but b is) {
    return 1;
 } else return strcoll(a, b);
}
This would sort like: 1, 2, 3, 4, 12, 2a, 2b, 2c, duck, wood

A last, and in my oppinion best alternative would be to first check if in both comparables the first character is a number. If it is first sort numerically on all the numbers you can fetch from both comparables and then sort on the remaining characters. Otherwise if both do not start with a number, sort alphabetically. Otherwise if one of the two starts with a number, put the number first.
This would sort like: 1, 2, 2a, 2b, 2c, 12, duck , wood


What is your input on this problem?

Greets,

Edwin de Jong (yes, a developer wannabe)

_______________________________________________
gnucash-devel mailing list
[EMAIL PROTECTED]
http://www.gnucash.org/cgi-bin/mailman/listinfo/gnucash-devel

Reply via email to