- 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
wow. just wow.
Admin
After reading the description and code comment my brain hurt too much to read the code.
Admin
Um... This is TOO bad to be true....
Admin
Is the real WTF the fact that this code is commented?
Admin
Is there any input at all that this thing does right? (Other than both inputs the same.)
Admin
New terms for standard mathematical words (eg "dividend" for "numerator"): check.
Absurdly wrong answers (eg 10 / 2 == 28 / 20): check.
Allergic to exception handling that would've solved the entire problem - not patched it, but solved it: check.
Nice.
Admin
// Version 2: Optimized
Random r = new Random(); return r;
Admin
So, lets see...
For 10/2 you get...
Admin
Admin
OOUCHAAAAAAAAARGGH! The goggles, they do nothing!
Admin
Alex you should warn before reading that code:
"Please backup your mind as this WILL cause you permanent damage"...
Admin
Junior... very very Junior..... ARRRGHH..................
The junior developer is creating a framework for the something that the compiler/tool already handles by throwing exceptions, who knows he/she may create a try/catch framework to cover more error handling. Somebody needs to re-take Programming 101.
What is being taught these days.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Junior... very very Junior..... ARRRGHH..................
Admin
Aaaaaa! WTF?!
Seriously, I can't even figure out what the hell it's trying to do. What's wrong with:
Admin
I thought maybe, just maybe this was intended to work with very large numbers since it's a double...but alas, it doesn't:
1e25 / 9e25 =~ 0.5294117647058824
WTF!?
Admin
That won't work because a divider is that thing that seperates a room into two parts. A divisor however... that's a different story.
Admin
Strange results
MessageBox.Show("100/10= " + DivisionWithZero(100, 10).ToString()); MessageBox.Show("1000000/10= " + DivisionWithZero(1000000, 10).ToString());
Let us hope this program doesn't calculate our taxes :D
Admin
//remembers to keep the sign digit right
Why would you need to put the sign on the right? Shouldn't it always be on the left? </sarcasm>
Admin
0/0 = FILE_NOT_FOUND
Admin
It might avoid "having to get trouble with zero values," but it doesn't manage to avoid having to get trouble with overflow. Just pass it the values Double.MAX_VALUE and 1 and you'll achieve overflow as soon as you execute this line:
if (dividend > divider) { separateZero = dividend - divider + 10; }
Admin
Wouldn't this whole thing be easier with:
try { result = oneNumber / notherNumber; } catch (Exception.DivisionByZero) { //we just divided by zero!!!!!!!!!!!! }
Admin
The person who wrote this ...code was my coworker. You can not imagine how happy I was when company decided to let him go. Alltough we got rid of the meanace he left behind hundreds and hundreds of lines bad code. But there is something good even that. I have never laughed as much when I read some of his code trough. You really should have seen how he managed to convert integer to decimal :D
Admin
Or maybe even something as exotic as (if you'll pardon my pseudo-code)
if divider = 0 then don't even bother trying to divide because it will cause an error.
CS101 anyone?
Admin
Except of course when both inputs are zero. :)
Admin
I'm not smart enough to appreciate the horror of the code, but I like the faux markup (FauXML?) in the comments. To people actually do that or is it further WTFery?
Admin
This isn't just a junior developer. If a junior developer tried to catch divide-by-zero himself, the worst he'd do is make things a little more complex by requiring a function call for division. This is an utterly incompetant junior developer. His function attempts to return an answer to the divide by zero when there is no correct answer, and in doing so breaks division for almost every other case.
Admin
No, dividing by zero yields OH SHI--
Admin
With integers it's even easier:
lim(1/x) tends towards infinity as x approaches 0, and lim(2^(1/x)) also tends towards infinity as x approaches 0. And since the integer operation "*= 2" is identical with "<<= 2", any non-zero number divided by zero can be bit-shifted infinitely, which obviously results in 0 sooner or later, regardless of platform.
Therefore,
Admin
Wow, at least we now know where to go to get the best drugs. Seriously what was he thinking?
Admin
The pseudo XML might be used by some tool to extract documentation from the source code.
TopTension
Admin
Visual Studio uses this format by default. There is not wtf in here. Doxygen (documentation program) can also read this kind of a markup.
Admin
That's standard comment markup for C#.
Admin
Damn. I tried to quote this: I'm not smart enough to appreciate the horror of the code, but I like the faux markup (FauXML?) in the comments. To people actually do that or is it further WTFery?
Admin
Well, exceptions would typically be faster than running that test 1,000,000 times in the off chance that it might actually return True once.
Admin
Although this seems C# code, I'd like to point out that Java can divide by zero without errors. System.out.println(5.0 / 0); will print "Infinity". System.out.println(0.0 / 0); will print "NaN".
Admin
It could be considered a bit of a wtf though, because people often assume that if they do this, they don't have to write any actual documentation...
Admin
Admin
Nah, this just confirms that the "coder" is a German...
Admin
But of course, that doesn't really make the result "correct". It's hard to do much useful with a NaN. :)
Admin
Captcha: hmm, I got this captcha once before, it's even in the auto-form-filler as the last used....
Admin
Can we combine this with isTrue() and doNothing() to get some reusability please?
Admin
Admin
It's called XML comments, and they are much better than your standard comments. By enabling compiling of XML Comments in Visual Studio, you can use a program like Sandcastle (http://www.codeplex.com/SHFB) to take your compiled code, and build a fully documented help file (or HTML file), complete with links (to your different classes and functions) and formatting derived from your code.
Essentially you can create a whole MSDN-like help file for your code just from creating a little more descriptive and properly formatted (which the compiler checks) comments.
-- KM
Admin
Stunning.
Admin
I do not want to know. I'm afraid it would require insanity of some sort to fully understand him. So I will pass the understanding and just laugh :)
Admin
There is a potential flaw in your argument. You basically say that "Visual Studio does X by default therefore it's not a WTF." That assumes something that's not necessarily true. Some of us think that XML comments are a WTF. For instance, they lead to boilerplate type crap like:
Truly, XML at its finest.
Admin
Admin
The most surprising thing to me was that this code actually does prevent DivideByZeroErrors. Of course, so does akatherder's optimized version
Admin
Admin
Anyone that codes like this, please leave the profession... NOW! Do not pass go, do not collect $200 ...
Admin
For one horrible moment, I thought something that one of my predecessors had done had come to light, that something I'd told someone in kinda-confidence had ended up on t'intertubes, and I was about to get whammy'd for breaking NDAs.
Then I realised I'd never seen the code before, and there must be another MikeC out there somewhere. Phew. There's no way I'd forget something like that!