| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Next » |
|
I like how he divided the long string of zeroes into several smaller ones for readability.
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001th
|
Yeah, and he even politely added in differing length constant strings... |
|
Oddly enough, we do the same thing at our company. At least Routing and Transit numbers are only 9 digits long...
|
|
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? |
|
I like how the first parameter always calculates to zero.
|
|
It's performance optimisation
|
|
I hope this was computer-generated code.
|
|
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.
|
|
Now that's a Maxi-Pad!
And it appears to contain NO LEAKS. |
Under the circumstances, that's a clever way to deal with it. |
really clever indeed! |
The rest of us were hoping no one would make that joke. Thanks, you've ruined the Internet for the rest of us, buddy. |
Re: Maximum Pad
2010-06-16 09:16
•
by
monkeyPushButton
(unregistered)
|
|
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:
|
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! |
|
He obviously used TDD, and just made the tests pass, one by one.
|
What self-respecting computer would generate code like this? |
|
Somebody's never heard of the switch statement.
CAPTCHA: "secundum" (not firstum) |
|
I like the syntax highlighter. That's new, isn't it?
"Vale tudo" means something like "everything goes"/"everything's fair" in Portuguese. |
|
Why did he even bother to do the substring? It's always from 0 to length!
|
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. |
|
Clearly it should've been this...
var oneHundredZeroes = "0000....0000"; var length = Data.length; return oneHundredZeroes.substring(100-length) + data; /sarcasm |
|
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(); } |
Yes - big kudos go out to Remy for suggesting and implementing. |
Take it that's from SQL I think that's ok if you need to do it in DB. |
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! |
|
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... |
|
It is. I grabbed it from here.
|
|
"I have become death, destroyer of rather pleasant mornings."
|
|
why noat just add "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" as a suffix and then do a substring? :)
|
|
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 ... } |
|
At least use "else if" for Christ's sake.
|
Awesome! It has a print feature, so I can print out TDWTF code! Now all I need is some matches... |
And you didn't see the huge note at the top of the page? Look again more carefully. |
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? |
|
It's easily understantable. That's the good part.
It gives me killing insticts. That's the bad part. |
|
Wow, and amazingly it wasn't written in VB. I guess you can code poorly in other languages as well.
|
|
Any self-respecting computer would properly handle a length of 0.
|
|
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?
|
|
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? :-)
|
Fuck Christ, how about subsequent maintainers? |
|
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.
|
|
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. |
Re: Maximum Pad
2010-06-16 09:59
•
by
madmaxpou
(unregistered)
|
or string oneHundredZeros = new string('0', 100); return (oneHundredZeros + data).Substring(0, 100); or better yet return data.PadLeft(100, '0'); |
|
Like Buggz said, the "length-XX" as a first parameter to substring() makes it even more WTF-y.
|
A clever perl way: $new_data = '0' x 100; $new_data++ until (!$data--); |
|
I feel like this would have been better if he had gotten the Database involved somehow....
|
| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Next » |