| « Prev | Page 1 | Page 2 | Page 3 | Next » |
Re: Division By Zero, Solved Yet Again
2007-10-15 09:25
•
by
steve
(unregistered)
|
|
wow. just wow.
|
|
After reading the description and code comment my brain hurt too much to read the code.
|
|
Um... This is TOO bad to be true....
|
Re: Division By Zero, Solved Yet Again
2007-10-15 09:32
•
by
amoore
(unregistered)
|
|
Is the real WTF the fact that this code is commented?
|
|
Is there any input at all that this thing does right? (Other than both inputs the same.)
|
|
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. |
|
// Version 2: Optimized
Random r = new Random(); return r; |
|
So, lets see...
For 10/2 you get... if (10 > 2) { separateZero = 10 - 2 + 10; } // separateZero = 18
|
Re: Division By Zero, Solved Yet Again
2007-10-15 09:41
•
by
amoore
(unregistered)
|
That's the only case that I can find. |
Re: Division By Zero, Solved Yet Again
2007-10-15 09:43
•
by
Anonymous Coward
(unregistered)
|
|
OOUCHAAAAAAAAARGGH! The goggles, they do nothing!
|
|
Alex you should warn before reading that code:
"Please backup your mind as this WILL cause you permanent damage"... |
Re: Division By Zero, Solved Yet Again
2007-10-15 09:53
•
by
Wameng Vang
(unregistered)
|
|
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.................. |
|
Aaaaaa! WTF?!
Seriously, I can't even figure out what the hell it's trying to do. What's wrong with: if (divider == 0) /* handle it however you want */; |
Re: Division By Zero, Solved Yet Again
2007-10-15 09:55
•
by
codemonkey
(unregistered)
|
|
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!? |
Re: Division By Zero, Solved Yet Again
2007-10-15 09:59
•
by
Anonymous
(unregistered)
|
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. |
|
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 |
|
//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> |
|
0/0 = FILE_NOT_FOUND
|
Re: Division By Zero, Solved Yet Again
2007-10-15 10:05
•
by
Sgt. Preston
(unregistered)
|
|
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; } |
|
Wouldn't this whole thing be easier with:
try { result = oneNumber / notherNumber; } catch (Exception.DivisionByZero) { //we just divided by zero!!!!!!!!!!!! } |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:17
•
by
HappilyEverAfter
(unregistered)
|
|
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
|
|
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? |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:23
•
by
Sulka
(unregistered)
|
Except of course when both inputs are zero. :) |
|
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?
|
Re: Division By Zero, Solved Yet Again
2007-10-15 10:27
•
by
SuperousOxide
|
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. |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:27
•
by
Quietust
|
No, dividing by zero yields OH SHI-- |
|
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, // Ultimate error-free division |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:34
•
by
Not Dorothy
(unregistered)
|
Wow, at least we now know where to go to get the best drugs. Seriously what was he thinking? |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:34
•
by
TopTension
(unregistered)
|
|
The pseudo XML might be used by some tool to extract documentation from the source code.
TopTension |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:35
•
by
John
(unregistered)
|
|
Visual Studio uses this format by default. There is not wtf in here. Doxygen (documentation program) can also read this kind of a markup.
|
Re: Division By Zero, Solved Yet Again
2007-10-15 10:36
•
by
John Price
(unregistered)
|
|
That's standard comment markup for C#.
|
Re: Division By Zero, Solved Yet Again
2007-10-15 10:37
•
by
John
(unregistered)
|
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? |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:45
•
by
Just Some Guy
(unregistered)
|
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. |
|
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". |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:49
•
by
Waffles
(unregistered)
|
Yeah, that's reasonably common. You do it so you can run a tool over your code to extract the comments, and generate a class/function reference such as http://www.icu-project.org/apiref/icu4c/index.html or http://msdn2.microsoft.com/en-us/library/system.string_members(VS.80).aspx 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... |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:49
•
by
Sgt. Preston
(unregistered)
|
That's what I'd like to know. This is truly a phenomenal WTF. I haven't the slightest idea what the coder's rationale was for any of it. He must have had something in mind, but it's a complete mystery to me. Any insights? Any guesses? |
Re: Let us count the ways...
2007-10-15 10:52
•
by
Anonymous German
(unregistered)
|
Nah, this just confirms that the "coder" is a German... |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:52
•
by
Waffles
(unregistered)
|
Yup, pretty much any language can do that. Including C# or C++ for that matter. It's a property of the IEEE floating point standard. Few languages bother to actually throw exceptions on a divide-by-zero. But of course, that doesn't really make the result "correct". It's hard to do much useful with a NaN. :) |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:55
•
by
Eric
(unregistered)
|
That's not always true though, 5.0 / 0 could easily be NaN or negative infinity. Captcha: hmm, I got this captcha once before, it's even in the auto-form-filler as the last used.... |
|
Can we combine this with isTrue() and doNothing() to get some reusability please?
|
Re: Let us count the ways...
2007-10-15 10:57
•
by
Sgt. Preston
(unregistered)
|
When I was in elementary school in Canada during the late Cretacious, we called the two operands of a division the 'dividend' and the 'divisor' and called the result the 'quotient'. 'Numerator' and 'denominator' were used only in the context of the manipulation of fractions. |
Re: Division By Zero, Solved Yet Again
2007-10-15 10:59
•
by
KM
(unregistered)
|
|
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 |
|
Stunning.
|
Re: Division By Zero, Solved Yet Again
2007-10-15 11:05
•
by
HappilyEverAfter
(unregistered)
|
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 :) |
Re: Division By Zero, Solved Yet Again
2007-10-15 11:08
•
by
Beau "Porpus" Wilkinson
(unregistered)
|
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: /// <summary> /// shifts all windows /// </summary> /// <param name="processName">name of process</param> Truly, XML at its finest. |
Re: Division By Zero, Solved Yet Again
2007-10-15 11:10
•
by
snoofle
|
Fixed that for ya! |
Re: Division By Zero, Solved Yet Again
2007-10-15 11:11
•
by
quantum
(unregistered)
|
|
The most surprising thing to me was that this code actually does prevent DivideByZeroErrors. Of course, so does akatherder's optimized version
|
Re: Division By Zero, Solved Yet Again
2007-10-15 11:11
•
by
snoofle
|
Please, do post !!! |
Re: Division By Zero, Solved Yet Again
2007-10-15 11:15
•
by
Mitch
(unregistered)
|
|
Anyone that codes like this, please leave the profession... NOW! Do not pass go, do not collect $200 ...
|
Re: Division By Zero, Solved Yet Again
2007-10-15 11:15
•
by
MikeC
(unregistered)
|
|
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! |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |