C/C++, although quite a powerful platform, doesn’t have much built-in functionality. Array bounds? Nope, it's not my job. Buffer overruns? Hey, I'm just writing what data you tell me to. Garbage collection? Seriously, do I look like your mother?

Still not content with this limited set of functionality, David Shay's colleague boycotted the String.compareTo() method and implemented his own. Of course, it doesn't actually work, but that's not the point ... C++ does enough as it is ... why should it have to compare strings to?

    public int compareTo(Object o) {
        MirageObject to = (MirageObject)o;
        String toName;
        try {
            toName = to.getUserLabel();
        } catch(Exception ex) {
            toName = "";
        String myName;
        try {
            myName = getUserLabel();
        } catch(Exception ex) {
            myName = new String();
        int myL = myName.length();
        int toL = toName.length();
        if (toL==myL) {
            int i = -1;
            int ret = 0;
            Character toC;
            Character myC;
            while (++i<toL && ret==0) {
                myC = new Character(myName.charAt(i));
                toC = new Character(toName.charAt(i));
                ret = myC.compareTo(toC);
            return ret;
        else {
            return (myL<toL ? -myL : toL);

UPDATE: As one of the comments pointed out, this code is definately Java. But being Java, which is definately not one of those “do it yer damn self“ languages, I think this brings the code to a whole new level ...

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!