• glyph (unregistered)

    I like how he divided the long string of zeroes into several smaller ones for readability.

  • Alargule (unregistered)

    Onehundredth!

  • SPiT (unregistered)

    00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001th

  • James O'Meara (unregistered)

    0

  • (cs) in reply to glyph
    glyph:
    I like how he divided the long string of zeroes into several smaller ones for readability.

    Yeah, and he even politely added in differing length constant strings...

  • Brian (unregistered)

    Oddly enough, we do the same thing at our company. At least Routing and Transit numbers are only 9 digits long...

  • Rusty (unregistered)

    Heh...we have to do this all the time in our app.

    RIGHT('0000000...(one hundred zeros)' + userInput, 100)

    Captcha: Valetudo Someone so smart they were Valedictorian and Salutatorian?

  • (cs)

    I like how the first parameter always calculates to zero.

  • трпаьтонр (unregistered)

    It's performance optimisation

  • Snarf (unregistered)

    I hope this was computer-generated code.

  • (cs)

    I don't know which is the more entertaining wtf: allowing strings longer than 100 characters, or calling substring with an index of 0 and length equal to the string's total length.

  • (cs)

    Now that's a Maxi-Pad! And it appears to contain NO LEAKS.

  • (cs) in reply to Rusty
    Rusty:
    Heh...we have to do this all the time in our app.

    RIGHT('0000000...(one hundred zeros)' + userInput, 100)

    Under the circumstances, that's a clever way to deal with it.

  • Mateus (unregistered) in reply to glyph
    glyph:
    I like how he divided the long string of zeroes into several smaller ones for readability.

    really clever indeed!

  • Some guy (unregistered) in reply to ParkinT
    ParkinT:
    Now that's a Maxi-Pad! And it appears to contain NO LEAKS.

    The rest of us were hoping no one would make that joke. Thanks, you've ruined the Internet for the rest of us, buddy.

  • monkeyPushButton (unregistered) in reply to Buggz

    He doesn't even validate that the data is a valid routing number.

    Assuming the routing number is only supposed to have digits should be:

    if (length == 99) && (Data == "1") {   
        NewData = "0" + Data.substring(length-99,length);   
    } 
    if (length == 99) && (Data == "2") {   
        NewData = "0" + Data.substring(length-99,length);   
    }  
    if (length == 99) && (Data == "3") {   
        NewData = "0" + Data.substring(length-99,length);   
    } 
    
    /*snip*/
    
    if (length == 98) && (Data =="10") {   
        NewData = "00" + Data.substring(length-98,length);   
    }    
    if (length == 98) && (Data =="11") {   
        NewData = "00" + Data.substring(length-98,length);   
    }   
    
  • (cs) in reply to трпаьтонр
    трпаьтонр:
    It's performance optimisation

    Especially since it has to run through all of the if-statements every single time. Why stop when you have your answer? Let's keep checking!

  • fragilist (unregistered)

    He obviously used TDD, and just made the tests pass, one by one.

  • (cs) in reply to Snarf
    Snarf:
    I hope this was computer-generated code.
    What self-respecting computer would generate code like this?
  • Matt (unregistered)

    Somebody's never heard of the switch statement.

    CAPTCHA: "secundum" (not firstum)

  • (cs) in reply to Rusty

    I like the syntax highlighter. That's new, isn't it?

    Rusty:
    Captcha: Valetudo Someone so smart they were Valedictorian and Salutatorian?
    "Vale tudo" means something like "everything goes"/"everything's fair" in Portuguese.
  • (cs)

    Why did he even bother to do the substring? It's always from 0 to length!

  • (cs)

    Pay per line FTW!

  • (cs) in reply to akatherder
    akatherder:
    Rusty:
    Heh...we have to do this all the time in our app.

    RIGHT('0000000...(one hundred zeros)' + userInput, 100)

    Under the circumstances, that's a clever way to deal with it.

    Nah, the clever way is ...

    REPLICATE('0', 99 - CAST((LOG(userInput)/LOG(10)) AS int)) + CONVERT(varchar(100), userInput)

    However, clever is a derogatory term in programming.

  • Drew (unregistered)

    Clearly it should've been this...

    var oneHundredZeroes = "0000....0000"; var length = Data.length;

    return oneHundredZeroes.substring(100-length) + data;

    /sarcasm

  • Anon (unregistered)

    public String rateThisCode() { List<String> comment = new ArrayList<String>(); int length = 3;

    while (comment.size()< length) { if (comment.size() == length-1) { comment.add("Fail"); } if (comment.size() == length-2) { comment.add("Than"); } if (comment.size() == length-3) { comment.add("Worse"); } } return comment.toString(); }

  • (cs) in reply to Zecc
    Zecc:
    I like the syntax highlighter. That's new, isn't it?.

    Yes - big kudos go out to Remy for suggesting and implementing.

  • Pete (unregistered) in reply to Rusty
    Rusty:
    Heh...we have to do this all the time in our app.

    RIGHT('0000000...(one hundred zeros)' + userInput, 100)

    Captcha: Valetudo Someone so smart they were Valedictorian and Salutatorian?

    Take it that's from SQL I think that's ok if you need to do it in DB.

  • (cs) in reply to glyph
    glyph:
    I like how he divided the long string of zeroes into several smaller ones for readability.

    Especially since the substrings are not a consistent length. Am I the only that actually counted? In case you haven't counted and wondered, the substring lengths are: 25, 17, 16, 16 25

    Now that's just wrong!

  • (cs)

    And here I thought today had started out pretty well...

    No bad traffic on the way to work, the latest software update build passed through QA with nary a hitch, no nasty-grams from clients or managers waiting in the inbox, then I read today's WTF...

    and now I am filled with despair...

  • (cs) in reply to Zecc
  • (cs) in reply to chron3

    "I have become death, destroyer of rather pleasant mornings."

  • baka0815 (unregistered)

    why noat just add "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" as a suffix and then do a substring? :)

  • baka0815 (unregistered)

    And using Java you would surely do something like

    public String fill(String data) { return (data.length() > 100 ? data.substring(100) : data.length() = 99 ? "0" + data : data.length() = 98 ? "00" + data ... }

  • sam (unregistered)

    At least use "else if" for Christ's sake.

  • (cs) in reply to Mark Bowytz
    Mark Bowytz:
    Zecc:
    I like the syntax highlighter. That's new, isn't it?.

    Yes - big kudos go out to Remy for suggesting and implementing.

    Awesome! It has a print feature, so I can print out TDWTF code! Now all I need is some matches...

  • Ben L. (unregistered) in reply to Remy Porter
    Remy Porter:
    And you didn't see the huge note at the top of the page? Look again more carefully.
  • Anon (unregistered) in reply to Buggz
    Buggz:
    I like how the first parameter always calculates to zero.

    That's called true zero. Clearly you can't trust the computer to provide true zero itself, you have to calculate it each time. Just in case. If you put a constant 0 in your code, who knows what the compiler will do with it?

  • kikito (unregistered)

    It's easily understantable. That's the good part.

    It gives me killing insticts. That's the bad part.

  • Wade (unregistered) in reply to snoofle

    Wow, and amazingly it wasn't written in VB. I guess you can code poorly in other languages as well.

  • Botia (unregistered) in reply to snoofle

    Any self-respecting computer would properly handle a length of 0.

  • Anonymous (unregistered)

    That's a great WTF but my immediate thought on reading this article was that the real WTF is surely the fact that TDWTF has only just implemented syntax highlighting after all these years! Good job Remy, and welcome to the 21st century! Did you know they have talking picture boxes these days, too?

  • Uncle Al (unregistered)

    Breaking the 0's down into substrings means the coder was oh-so-close to a brilliant solution. What he should have done, of course, was to compute the length of the padding and then treat the length as a bit field. If the 1's digit is set, add "0". If the 2's digit is set, add "00". And so on. Much more scalable, don't you think? :-)

  • (cs) in reply to sam
    sam:
    At least use "else if" for Christ's sake.

    Fuck Christ, how about subsequent maintainers?

  • NoAstronomer (unregistered)

    What I like about this one is that you just know one (at least) of those pads has the wrong number of zeros in it. Leading to a beautifully hard to diagnose intermittent error.

  • (cs) in reply to Ben L.

    Yes, I did, but after I had already grabbed this and was getting it setup. I'll probably get it upgraded shortlyish.

    All things considered, it's still a huge step up from pasting code into Pastie.org, viewing source, and copying the HTML. Which I've done. I've also got a Ruby script that generates HTML too.

    This is much nicer.

  • madmaxpou (unregistered) in reply to Drew
    Drew:
    Clearly it should've been this...

    var oneHundredZeroes = "0000....0000"; var length = Data.length;

    return oneHundredZeroes.substring(100-length) + data;

    /sarcasm

    or

    string oneHundredZeros = new string('0', 100); return (oneHundredZeros + data).Substring(0, 100);

    or better yet

    return data.PadLeft(100, '0');

  • Medinoc (unregistered)

    Like Buggz said, the "length-XX" as a first parameter to substring() makes it even more WTF-y.

  • Brent (unregistered) in reply to Jaime
    Jaime:
    akatherder:
    Rusty:
    Heh...we have to do this all the time in our app.

    RIGHT('0000000...(one hundred zeros)' + userInput, 100)

    Under the circumstances, that's a clever way to deal with it.

    Nah, the clever way is ...

    REPLICATE('0', 99 - CAST((LOG(userInput)/LOG(10)) AS int)) + CONVERT(varchar(100), userInput)

    However, clever is a derogatory term in programming.

    A clever perl way:

    $new_data = '0' x 100; $new_data++ until (!$data--);

  • (cs)

    I feel like this would have been better if he had gotten the Database involved somehow....

Leave a comment on “Maximum Pad”

Log In or post as a guest

Replying to comment #:

« Return to Article