The EMO Mailbag: This is ridiculously funny

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

hahahanoobs

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?

This entry was posted in Cranky Old Programmer. Bookmark the permalink.

9 Responses to The EMO Mailbag: This is ridiculously funny

  1. Carsten Pfeiffer says:

    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.

  2. Carsten says:

    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.

  3. Joakim Erdfelt says:

    Here’s your demonstration code for how to do natural order comparators in java.

    • Xavier Raynaud says:

      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<————————

  4. Jörg von Frantzius says:

    I’d respond similarly, probably depending on the sun light exposure i’d got these days (not much in Berlin🙂

  5. waynebeaton says:

    I’m surprised by the interest in natural sort order. Somebody really should submit a patch…

    • k10g says:

      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.

  6. Robin says:

    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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s