• (disco)

    Wake up @PaulaBean!

    http://thedailywtf.com/articles/accurate-comments

    Kevin L saw the program crash with a null pointer exception. This lead to digging through stack traces, logs, and eventually the commit history to figure out who was responsible....


    Paging @mark_bowytz, @apapadimoulis

  • (disco)

    We are looking into the Paula Bean issue. We just need someone more brillant.

  • (disco)

    Maybe @PaulaBean is trying to do a string padding on the article title?

  • (disco) in reply to VinDuv
                                                                                                                                                                                                                                                                                        fourth!
    

    Is there a limit on spaces?!?!

  • (disco) in reply to aliceif

    Apparently not...

    [image]

    Perhaps they need to be rate limited...

  • (disco)

    About that final note:

    Note: it'n
    

    Didn't you mean it's?


    Filed under: Spellar'd that for you

  • (disco) in reply to JBert
    JBert:
    Filed under: Spellar@accalia'd that for you

    FTFY

    Filed under: or would that more correctly be "anti-@accalia'd"...?

  • (disco) in reply to accalia

    un-@accalia'd?

  • (disco) in reply to NedFodder

    that works too.

    :laughing:

  • (disco)

    Picks up the phone, calls the IT help desk: "Hello, I need a new keyboard. This one has run out of spaces."

  • (disco)

    Accurate Comments

    [image]

    Well... that's one way to ensure none of them are wrong...

  • (disco)

    Those who cannot remember printf are condemned to reimplement it... poorly.

    Edit: I actually meant printf and its variants, so if this were C it'd be sprintf. Since this looks like Java, it'd be String.format.

  • (disco)

    Maybe I am missing the point but why would this result in a null pointer exception? My C is very rusty since I found Python.

  • (disco) in reply to Dlareg
    Dlareg:
    Maybe I am missing the point but why would this result in a null pointer exception? My C is very rusty since I found Python.
    1. It's not C.

    2. It would result in a null pointer exception if registrationNumber were null.

  • (disco)

    I've seen these type of comments before, I don't get it. Why add a stupid "This isn't really good" comment instead of you know actually refactoring the damn code to be improved.

  • (disco) in reply to DocMonster

    If you've never been in a situation where a boss was afraid to touch anything and had developed an instinctive flight reaction against the word "refactor", consider yourself lucky. "It's a 5 minute fix, chief" "I don't care. QA says it'll take them 3 days to test it" "Um, shouldn't they just have to enter a couple strings?" "Probably, but I'm not going to tell them how to do their jobs" "Apparently they're telling us how to do ours...."

  • (disco) in reply to HardwareGeek
    // this is a much better way to do this.... 
        public static String padRegistrationNumber(String registrationNumber) {
            if (registrationNumber.length() == 11) {
                return " " + registrationNumber;
            }
            //
            // SNIP ....
            //
            if (registrationNumber.length() == 1) {
                return "           " + registrationNumber;
            }
            else if (registrationNumber.length() == 0 || registrationNumber == null){
                return "            ";
            }
            return registrationNumber;
        }
    

    FIXED

  • (disco) in reply to mruhlin
    mruhlin:
    FIXED

    :laughing: "You keep using that word. I do not think it means what you think it means."

  • (disco) in reply to mruhlin
    mruhlin:
    FIXED

    I assume that this is a joke. At least, I hope so.

    The thing that interests me about string padding is that it is an extremely simple problem to state, and there are many solutions, but there is no obviously optimal solution. (Feel free to prove me wrong).

  • (disco) in reply to kupfernigk

    There are several obviously-better-than-this solutions though.

  • (disco) in reply to mruhlin

    That's generally because QA doesn't know what goes into programming. Nor do they have a full understanding of how a fix changes the system or affects surrounding code. The developer should be able to help QA understand that and that the test shouldn't take too long.

    Of course, that would be in a sane, communicative environment.

  • (disco) in reply to mruhlin

    Oh, no, no, no... This is a perfect chance to use a for loop! :anguished:

  • (disco) in reply to machtyn
    machtyn:
    Nor do they have a full understanding of how a fix changes the system or affects surrounding code

    The number of times I've had a programmer tell me "But I didn't touch that part, why did it break!???!?!?" indicates to me that that sword cuts both ways

  • (disco) in reply to machtyn
    machtyn:
    Oh, no, no, no... This is a perfect chance to use a for loop!

    ITYM recursion

    public static String padRegistrationNumber(String registrationNumber) {
        if (registrationNumber.length() < 12) {
            return " " + padRegistrationNumber( registrationNumber );
        } else {
            return registrationNumber
        }
    }
    
  • (disco) in reply to machtyn
    machtyn:
    QA doesn't know what goes into programming

    Also, I know what you meant, but STFU :angry: The assumption that nobody in QA understands code is part of why many in QA never bother to learn code and why many coders utterly disregard QA

  • (disco) in reply to PleegWat

    9/10, needs more factories.

  • (disco) in reply to kupfernigk

    there are many solutions, but there is no obviously optimal solution.

    This one pretty much does the job, with some variation based on how you're storing your strings:

    pad(original, targetLength, padChar=" "):
         padded = malloc(targetLength)
         orig_length = original.length  -- sometimes this is an O(n) traversal of the entire original
         split = max(targetLength - orig_length, 0)
         for i from 0 to split:
              padded[i] = padChar
         for i from 0 to min(orig_length, targetLength):
              padded[i + split] = original[i]
         return padded
    

    That's guaranteed to be O(targetLength).

  • (disco) in reply to EatenByAGrue

    That'll do horrible stuff if length(original) > targetLength

  • (disco) in reply to machtyn
    machtyn:
    Oh, no, no, no... This is a perfect chance to use a for loop! :anguished: Duff's Device

    FTFY

  • (disco) in reply to cconroy
        public static String padRegistrationNumber(String registrationNumber) {
            try {
                switch (registrationNumber.length()) {
                case 0:
                    registrationNumber += " ";
                case 1:
                    registrationNumber += " ";
                case 2:
                    registrationNumber += " ";
                case 3:
                    registrationNumber += " ";
                case 4:
                    registrationNumber += " ";
                case 5:
                    registrationNumber += " ";
                case 6:
                    registrationNumber += " ";
                case 7:
                    registrationNumber += " ";
                case 8:
                    registrationNumber += " ";
                case 9:
                    registrationNumber += " ";
                case 10:
                    registrationNumber += " ";
                case 11:
                    registrationNumber += " ";
                case 12:
                default:
                    return registrationNumber;
                }
            } catch (NullPointerException e) {
                return padRegistrationNumber("");
            }
        }
    
  • (disco) in reply to HardwareGeek
    HardwareGeek:
    It would result in a null pointer exception if registrationNumber were null.

    If a function gives a null pointer exception when you pass a null input, then don't do that.

    So in all "1,234" places where this function is called, all team members are required to do this:

    String result = null;
    if (regnum != null) result = padRegistrationNumber(regnum);
    

    Fixed.

  • (disco) in reply to machtyn
    machtyn:
    Of course, that would be in a sane, communicative environment.

    What's that?

  • (disco)

    What about this strategy?

    public static String padRegistrationNumber(String registrationNumber) {
       if (registrationNumber == null || registrationNumber.length > 12) return registrationNumber;
       return ("            " + registrationNumber).substring(registrationNumber.length);
    }
    

    (It's a bit easier in languages that have a "right" function.)

    Edit: Still fails for null. Fixed.

  • (disco) in reply to CoyneTheDup
    CoyneTheDup:
    If a function gives a null pointer exception when you pass a null input, then don't do that.

    So in all "1,234" places where this function is called, all team members are required to do this:

    String result = null; if (regnum != null) result = padRegistrationNumber(regnum);

    Fixed.

    +1 Funny

    Filed under: inb4 slashdot is leaking again

  • (disco) in reply to CoyneTheDup
    CoyneTheDup:
    return ("            " + registrationNumber).substring(registrationNumber.length);
    

    I don't think so

  • (disco) in reply to PleegWat
    PleegWat:
    There are several obviously-better-than-this solutions though.

    Well, yes, especially all the ones that start with a test for null and behave appropriately.

    The problem is to find one that is the most efficient in resources. I have in the past had the problem of reconstructing a space padded fixed field text file from a database for legacy reasons. When you are constructing a file that will exceed 100Mbytes and has, say, ten space padded fields, the efficiency of the padding algorithm makes an awful lot of difference to execution time.

    Don't ask, it was over 10 years ago.

  • (disco) in reply to aliceif

    That'll pad right instead of left.

  • (disco)

    As awful as that function is, it would take a special set of circumstances for it to be the root cause of a null pointer exception. While it might be expected that it would either assert or throw a specialized exception on null argument, a string manipulation function shouldn't be required to silently ignore null string references.

  • (disco)

    It was supposed to be tongue-in-cheek. Sheesh.

  • (disco) in reply to PleegWat

    Whoops. I'll do a quick fix:

        public static String padRegistrationNumber(String registrationNumber) {
            try {
                switch (registrationNumber.length()) {
                case 0:
                    registrationNumber += " ";
                case 1:
                    registrationNumber += " ";
                case 2:
                    registrationNumber += " ";
                case 3:
                    registrationNumber += " ";
                case 4:
                    registrationNumber += " ";
                case 5:
                    registrationNumber += " ";
                case 6:
                    registrationNumber += " ";
                case 7:
                    registrationNumber += " ";
                case 8:
                    registrationNumber += " ";
                case 9:
                    registrationNumber += " ";
                case 10:
                    registrationNumber += " ";
                case 11:
                    registrationNumber += " ";
                case 12:
                default:
                    int lastSpace = registrationNumber.lastIndexOf(" ");
                    return lastSpace == -1 ? registrationNumber
                            : registrationNumber.substring(lastSpace + 1)
                                    + registrationNumber
                                            .substring(0, lastSpace + 1);
                }
            } catch (NullPointerException e) {
                return padRegistrationNumber("");
            }
        }
    

    Much better!

  • (disco) in reply to aliceif
    aliceif:
    It was supposed to be tongue-in-cheek.Sheesh.

    Sorry. On teh interwebs, we have still not sorted out tags for humor and irony.

  • (disco) in reply to aliceif

    I wonder what's wrong with:

    public static String padRegistrationNumber(String registrationNumber) {
        assert registrationNumber != null;
        if (registrationNumber.length() >= 12)
            return registrationNumber;
        String s = "            " + registrationNumber;
        return s.substring(s.length() - 12);
    }
    
  • (disco) in reply to aliceif
    aliceif:
    Much better!

    C# isn't my native language, but I thought they didn't allow fall through. So you need lots of gotos.

  • (disco) in reply to dcon
    dcon:
    C# isn't my native language, but I thought they didn't allow fall through. So you need lots of gotos.

    The capitalized String should tip you off: it's Java…

  • (disco) in reply to dkf
    dkf:
    The capitalized String should tip you off: it's Java…

    It's not C/C++, so no.

  • (disco) in reply to dkf

    Pretty sure I got a capitalized S as an option in c#.

  • (disco) in reply to PleegWat
    PleegWat:

    ITYM recursion

    public static String padRegistrationNumber(String registrationNumber) { if (registrationNumber.length() < 12) { return " " + padRegistrationNumber( registrationNumber ); } else { return registrationNumber } }

    Won't this cause a stack recursion fault? You need to put the " " inside the recursive call.
  • (disco) in reply to dcon
    dcon:
    It's not C/C++, so no.

    WAT?

    Nprz:
    Pretty sure I got a capitalized S as an option in c#.

    Maybe, but no. The method capitalizations are wrong. The exception name is wrong. While yes, you could assemble this whole thing in C# if you wanted to and have it compile… No, you're just demonstrating your general ignorance.

  • (disco) in reply to aliceif
    aliceif:
    Much better!

    Are you sure?

  • (disco) in reply to Nprz
    Nprz:
    Won't this cause a stack recursion fault? You need to put the " " inside the recursive call.

    You're correct.

    Mine has bugs too.

Leave a comment on “Accurate Comments”

Log In or post as a guest

Replying to comment #:

« Return to Article