I received this message via the EMO inbox today:
haha noobs
your number sorting in project explorer is like a mistake from windows 95
this is ridiculously funny
He’s right. It is ridiculously funny. I’m assuming that the sender is part of some nerd mafia and sent this message to earn some kind of merit badge.
Here’s my response:
This is working as designed. In the real world, you will almost never have projects named like this, so investing any time in writing a sorting algorithm that handles this case just isn’t worth the investment.
You may want to spend some time researching alphanumeric sorting. If you’re concerned about sorting order, then maybe consider padding your project names with spaces or zeroes, e.g “Home Work – Week 01″
Since you’re apparently very smart, I’m curious to know if you have any idea how you might design an algorithm that considers numeric order while sorting. That might be a good project for one of your first year courses.
Normally, I wouldn’t add in that last part. This morning, I couldn’t help myself…
How would you respond?

It’s typically called “natural sort order”. See e.g. http://sourcefrog.net/projects/natsort/ for an implementation. Try the same folders in Konqueror for a testdrive.
It’s typically called “natural sort order”. See e.g. http://sourcefrog.net/projects/natsort/ for an implementation. Try the same files in Konqueror for a testdrive.
Even if you do not have projects or folders named like this — having files like this is not too uncommon.
Here’s your demonstration code for how to do natural order comparators in java.
https://gist.github.com/4458483
compare(“foo[0]“, “foo[1]“) is buggy.
I suggest to slightly change the algo:
———————–8<————————
// skip over leading spaces or zeros
while (Character.isSpaceChar(ca) || ca == '0') {
if (ca == '0') {
if (Character.isDigit(charAt(a, ia+1))) {
nza++;
ca = charAt(a, ++ia);
} else {
break;
}
} else {
// only count consecutive zeroes
nza = 0;
ca = charAt(a, ++ia);
}
}
while (Character.isSpaceChar(cb) || cb == '0') {
if (cb == '0') {
if (Character.isDigit(charAt(b, ib+1))) {
nzb++;
cb = charAt(b, ++ib);
} else {
break;
}
} else {
// only count consecutive zeroes
nzb = 0;
cb = charAt(b, ++ib);
}
}
———————–8<————————
I’d respond similarly, probably depending on the sun light exposure i’d got these days (not much in Berlin
That may be it. I need to get more sunlight…
I’m surprised by the interest in natural sort order. Somebody really should submit a patch…
The reporter is a bit of a jackass but I was pleased to see that the OSX Finder sorts ‘untitled folder’s naturally. -1 for jackassery, but not so bad.
EGit already has an implementation of this which could be reused, see here:
https://git.eclipse.org/c/egit/egit.git/tree/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CommonUtils.java#n37
https://git.eclipse.org/c/egit/egit.git/tree/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/CommonUtilsTest.java
It was added to sort Branch and Tag names naturally. So the request makes sense technically, although I strongly disagree with the way it was made.