- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
So, vale tudo means that everything has worth.
Admin
Someone who doesn't know about sprintf("%100d", ...)
Admin
Admin
Admin
This can be implemented with five lines of code and zero bugs in Java 5.0_22.
Admin
Admin
I actually adore LISP. I left a note to that effect inside the article if you view-source.
Admin
LOL!
Admin
Whats if Data is null. :)
Admin
Please accept my sincerest apologies for not being more clear.
Admin
select right(replicate('0',100) + ltrim(rtrim(cast(Data as varchar(100)))),100)
Admin
You go to hell! You go to hell and you die!
Admin
Somebody call the brain police, clearly that programmer's has been stolen.
Admin
Admin
He obviously tried to make it thread-safe, in case the length changed in between if-test and substr.
Admin
That is not possible. No sane person would have done that.
I highly doubt about the truth of that WTF.
Admin
Or, you can use some ice and a wire: http://www.csiro.au/resources/slicing-ice-activity.html
CYA
Admin
Why on earth the substring part? He substrings between 0 and length each time.
Admin
that ass, he should've used switch not if
looool, JK
Admin
One that gets extra memory for ever line it codes?
Admin
It looks like php, which has a handy dandy built in function str_pad:
return str_pad($input, 100, '0', STR_PAD_LEFT);
Admin
What a wonderful peace of code! The "developer" has left room for future extensions with calculating the substrings starting point (even thoug they all starts from zero)
Indeed nice one!
Admin
Yep.
Java strings are immutable and any changes to a string cause mallocs. You don't want to be adding the zeros one at a time or performance will take a nosedive.
Admin
Admin
Python:
Or without
:Admin
Yes, it does, I was too lazy to look up the details:
Admin
I feel ill
Admin
try null as parameter
Admin
Oh, the one that I had not seen because it requires Javascript, and therefore repeats the work over and over again on each viewer's browser, instead of just once statically before putting it on the webserver...
Admin
LOL and it has O(1) complexity
Admin
Maybe it is self-loathing one?
Admin
Admin
Well, seeing as no-one else is going to do it...
This sort of thing is actually common in embedded systems, where there isn't space for library functions.
Admin
Cornify on LISP! Awesome Remy :)
Admin
-________________________________________________________-
Admin
As it's about the only language it hasn't been written here
strVBAPad= String(100 - Len(strInput), "0") & strInput
Admin
The real WTF is to do not use a divide and conquier algo:
function ZeroFill(Data) { if (Data.length + 64 <= 100) { Data= padleft0("", 64) + Data; } if (Data.length + 32 <= 100) { Data= padleft0("", 32) + Data; } if (Data.length + 16 <= 100) { Data= padleft0("", 16) + Data; } if (Data.length + 8 <= 100) { Data= padleft0("", 8) + Data; } if (Data.length + 4 <= 100) { Data= padleft0("", 4) + Data; } if (Data.length + 2 <= 100) { Data= padleft0("", 2) + Data; } if (Data.length + 1 <= 100) { Data= padleft0("", 1) + Data; } return Data; }
Of course this way of doing presuppose that you already have the padleft0(s, i) function. /sarcasm
Admin
If you're havin' girl problems i feel bad for you son I got 99 problems but a bitch ain't one
Admin
I deplore the absence of XML in the implementation
Admin
I'm sure he meant
And to whoever had the 'one brace' line, well done
Admin
If the meat in the sandwich is prime rib, you can only divide it by itself, so you only get one piece.
Admin
I've seen that style of coding before... so your company utilizes the amazing skillz of offshore developers too?
Admin
yup, javascript is the basic of our times. retards inc!
Admin
If you're paid hourly to do a job, you would want to stretch it as far as possible. ;)
Admin
Well, it works, doesn't it?!?
Admin
One with very low self esteem
Captca: verror- the fith error
Admin
This was as stupid an attempt as I could come up with:
I tried to make it more convoluted but lost initiative.
On the plus side, if $w <= $n, it'll give you an infinite loop, and the return value is actually a string (not that it matters much).
But the cool part is that you could really screw with someone down the line, since "print pad(123, 'four');" would work just fine in a very non-obvious way.
Admin
My usual trick is to prepend 100 0s and then truncate at 100 right justified
Admin
.Net version:
Admin
I know my post is late, but I was busy integrating the mainframe again. Anyway...
WTF was this developer thinking?! Obviously they should have done the length tests from low-to-high, like this:
Which will 1) optimize the code so that only one "0" per test is needed, saving space, and 2) that each test is true for (length >= n), ensuring full CPU usage.