Comment On The Int Divide

Mark Baker and Aaron Jenkins had one thing in common: they were both in the midst of a transition at Initech Global. It was Aaron's last day on the job and Mark's very first, and Aaron was tasked with helping Mark get acquainted with the applications, servers, and whatever else a new employee might need. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: The Int Divide

2009-06-10 09:03 • by leppie (unregistered)
Ouch!

Re: The Int Divide

2009-06-10 09:07 • by D C Ross (unregistered)
Seems simple enough. The built-in division function returned all kind of crazy "NaN" stuff sometimes. Only IntDivide can be relied upon to tell you that any number divided by zero is zero.

Re: The Int Divide

2009-06-10 09:08 • by RandomPersona (unregistered)
268238 in reply to 268236
Wow. I do not think I have ever seen code that is wrong on so many levels.

In fact, before now, I wouldn't have thought it would be possible to introduce 200ms latency in to a divide operation.

I feel like I'm being trolled, but I can't help but believe someone actually wrote this.

Re: The Int Divide

2009-06-10 09:09 • by sponk (unregistered)
I can't say I really believe this.

Re: The Int Divide

2009-06-10 09:10 • by Pol
Just awesome!

Re: The Int Divide

2009-06-10 09:11 • by my name is missing (unregistered)
Using SQL to divide two integers is like using an atomic bomb to swat a fly.

Re: The Int Divide

2009-06-10 09:11 • by Textual Advanced (unregistered)
OK, this one counts as an actual WTF. I was expecting the poorly implemented and completely redundant function with unspecified results under certain cases (like dividing by zero) but the SQL caught me by surprise to the point that I said "What?" out loud! Good one.

Re: The Int Divide

2009-06-10 09:12 • by GameFreak (unregistered)
Concatenating SQL for a statement that is unnecessary in the first place?

Re: The Int Divide

2009-06-10 09:13 • by Hoodaticus (unregistered)
ROFL. Well at least he set Result to zero when he declared it! Because no one knows what its value would have been if he hadn't.

Is there a SQL Math for Dummies book or something?

Re: The Int Divide

2009-06-10 09:15 • by Moredate Madness (unregistered)
I notice this gem was born on 08/29/08.

So is that YMD or DMY?

Re: The Int Divide

2009-06-10 09:15 • by steenbergh
268246 in reply to 268239
sponk:
I can't say I really believe this.


Well, this is really too stupid to be made up. I believe that the (ugly) truth IS out there...

Re: The Int Divide

2009-06-10 09:17 • by campkev
268247 in reply to 268242
Textual Advanced:
OK, this one counts as an actual WTF. I was expecting the poorly implemented and completely redundant function with unspecified results under certain cases (like dividing by zero) but the SQL caught me by surprise to the point that I said "What?" out loud! Good one.


Same here. Actually I was expecting the implemented function to end up working properly in all cases except where the numerators were actually evenly divisible by the denominators. But making a call to the database to divide two numbers is just...seriously what the hell were they thinking?

Re: The Int Divide

2009-06-10 09:17 • by Pjotr G
If the database is down, an exception is thrown during some int division, instead of during an actual intended database operation; potentially averting horrendous failure. Solid!

Re: The Int Divide

2009-06-10 09:18 • by drachenstern
Why bother with returning the floor in place of this IntDivide if you're just going to add one to it? Why not return the ceiling instead. Granted, I don't know how the SQL result will be returned in this particular implementation, but it seems from the article that it returns the floor. Therefore, if you take the floor plus one, that should equal the ceiling, no?

Or am I thinking of the ceiling of (numerator+.5)/denominator?

Re: The Int Divide

2009-06-10 09:20 • by silent d (unregistered)
It's so cute that he checks the row count of a SQL statement that is not selecting from a table.

Re: The Int Divide

2009-06-10 09:21 • by dpm
268251 in reply to 268239
sponk:
I can't say I really believe this.
Bwa ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha

(deep breath)

ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha

I get one hell of a kick out of people who believe something is "so stupid" that it couldn't possibly happen in real life. Oh my dear $DEITY, the secondary entertainment value is so exquisite . . .

I not only believe this code is in production somewhere, I cannot help but admire the "Who: ????" as well.

Re: The Int Divide

2009-06-10 09:21 • by Max (unregistered)
...what about the handy integer division operator "\" ?
No no no...on second thought that would've been far too easy.

Re: The Int Divide

2009-06-10 09:21 • by Steve the Cynic (unregistered)
268253 in reply to 268249
drachenstern:
Why bother with returning the floor in place of this IntDivide if you're just going to add one to it? Why not return the ceiling instead. Granted, I don't know how the SQL result will be returned in this particular implementation, but it seems from the article that it returns the floor. Therefore, if you take the floor plus one, that should equal the ceiling, no?

Or am I thinking of the ceiling of (numerator+.5)/denominator?


ceil(7) is not floor(7)+1.

I reckon this is so that they can have 2/3 => 7

and related sins...

Re: The Int Divide

2009-06-10 09:23 • by Steve the Cynic (unregistered)
268254 in reply to 268253
I suck. Ignore me, didn't read the SQL. Bah.

Steve the Cynic:
drachenstern:
Why bother with returning the floor in place of this IntDivide if you're just going to add one to it? Why not return the ceiling instead. Granted, I don't know how the SQL result will be returned in this particular implementation, but it seems from the article that it returns the floor. Therefore, if you take the floor plus one, that should equal the ceiling, no?

Or am I thinking of the ceiling of (numerator+.5)/denominator?


ceil(7) is not floor(7)+1.

I reckon this is so that they can have 2/3 => 7

and related sins...

Re: The Int Divide

2009-06-10 09:23 • by ThomsonsPier
268255 in reply to 268245
Moredate Madness:
I notice this gem was born on 08/29/08.

So is that YMD or DMY?

The twenty-ninth month of 2008 is May 2010, whereas the twenty-ninth month of 2008 is May 2010. From this, the answer should be obvious.

Re: The Int Divide

2009-06-10 09:27 • by Yeah Baby (unregistered)
268256 in reply to 268248
Pjotr G:
If the database is down, an exception is thrown during some int division, instead of during an actual intended database operation; potentially averting horrendous failure. Solid!

Protip: Near the beginning of every program, include a test IntDivide(2,1) to make sure the database is up. If not, bail out now before you waste time initializing all those variables and plowing halfway through the logic. Optimized!

Re: The Int Divide

2009-06-10 09:28 • by Whoevar (unregistered)
Can someone expose this as a web service, please? I'm in desperate need of division but cannot set up an SQL server!

Re: The Int Divide

2009-06-10 09:30 • by zolf
Now I know why they told me that divisions were expensive.

Re: The Int Divide

2009-06-10 09:30 • by Moredate Madness (unregistered)
268259 in reply to 268255
ThomsonsPier:
Moredate Madness:
I notice this gem was born on 08/29/08.

So is that YMD or DMY?

The twenty-ninth month of 2008 is May 2010, whereas the twenty-ninth month of 2008 is May 2010. From this, the answer should be obvious.

This code is from the future!!! Arrrgggghhhhhhhh!!!!

(There be terminators about...)

Re: The Int Divide

2009-06-10 09:32 • by kastein
268260 in reply to 268257
Whoevar:
Can someone expose this as a web service, please? I'm in desperate need of division but cannot set up an SQL server!


http://www.google.com/search?q=[insert math to perform here]

Done. It's even abstracted to handle assorted unit conversions, trigonometry, complex numbers... the list goes on!

Now you just have to write a neural network to learn how to extract the answer from any arbitrarily formatted Google result page (what if they change the logo?) and you're all set. No Quack.

Re: The Int Divide

2009-06-10 09:34 • by amischiefr
268261 in reply to 268245
Moredate Madness:
I notice this gem was born on 08/29/08.

So is that YMD or DMY?

How about neither, unless on your planet there are 29 months...

How about the standard Month - Day - Year?

Re: The Int Divide

2009-06-10 09:38 • by Moredate Madness (unregistered)
268262 in reply to 268261
amischiefr:
Moredate Madness:
I notice this gem was born on 08/29/08.

So is that YMD or DMY?

How about neither, unless on your planet there are 29 months...

How about the standard Month - Day - Year?

Whoosh!

Ummm, which "standard" is that?

Year-Month-Day is the International Standard http://en.wikipedia.org/wiki/ISO_8601

And, as is the nature of standards, there is only one right way to do it.

Re: The Int Divide

2009-06-10 09:40 • by ashmud (unregistered)
Is your very first day different from your first day?

Re: The Int Divide

2009-06-10 09:40 • by Warren (unregistered)
What a shame they had to write another version for Longs not, er, long, afterwards. .NET just isn't good enough!

Re: The Int Divide

2009-06-10 09:40 • by Wheaties (unregistered)
He's not alone. I've seen worse. In fact just yesterday I decided to help a forum poster who had switched to SQL Server because Access didn't allow enough column on a data table. He was recursively using a function which downloaded the a database table to flesh out a parse tree and couldn't understand why he was running out of system memory.

These people really do exist

Re: The Int Divide

2009-06-10 09:41 • by Dinnerbone
268266 in reply to 268262
Moredate Madness:
And, as is the nature of standards, there is only one right way to do it.


Unless it's perl... Or Microsoft.

Re: The Int Divide

2009-06-10 09:42 • by Code Dependent
268267 in reply to 268251
dpm:
I not only believe this code is in production somewhere, I cannot help but admire the "Who: ????" as well.
Yes. I was afraid you were going to shoot down my abuse of a jaded meme:

'------------------------------------------------------------------

'-- REVISION HISTORY:
'--
'-- WHEN WHO WHAT
'-- 08/29/08 ???? Initial creation.
'-- 06/10/09 Profit!!! Ultimate demise.

Re: The Int Divide

2009-06-10 09:42 • by Tycho (unregistered)
268268 in reply to 268257
Whoevar:
Can someone expose this as a web service, please? I'm in desperate need of division but cannot set up an SQL server!


Just a minute, I'm trying to figure out how to put the wooden table in for, ya know, enterprisey-ness.

Re: The Int Divide

2009-06-10 09:53 • by Whoevar (unregistered)
268271 in reply to 268262
Moredate Madness:

And, as is the nature of standards, ...


... there are lots to choose from?

Re: The Int Divide

2009-06-10 09:55 • by Jonathan
268272 in reply to 268260
kastein:
Whoevar:
Can someone expose this as a web service, please? I'm in desperate need of division but cannot set up an SQL server!


http://www.google.com/search?q=[insert math to perform here]

Done. It's even abstracted to handle assorted unit conversions, trigonometry, complex numbers... the list goes on!

Now you just have to write a neural network to learn how to extract the answer from any arbitrarily formatted Google result page (what if they change the logo?) and you're all set. No Quack.



Please send teh codez.

Re: The Int Divide

2009-06-10 09:56 • by Brompot (unregistered)
268273 in reply to 268241
my name is missing:
Using SQL to divide two integers is like using an atomic bomb to swat a fly.


Except that the atomic bomb efficiently swats the fly, with some side effects.

Re: The Int Divide

2009-06-10 10:00 • by ubersoldat
See, is not the language's fault that stupid people like this guy use them.

BTW, is it bad that my debit card PIN is the same as their security lock?

Re: The Int Divide

2009-06-10 10:01 • by Dinnerbone
268275 in reply to 268274
ubersoldat:
See, is not the language's fault that stupid people like this guy use them.

BTW, is it bad that my debit card PIN is the same as their security lock?


Really? Can I see your card? I don't believe you.

Re: The Int Divide

2009-06-10 10:05 • by qbe (unregistered)
at least a machine was asked to do the division... he could have asked the user with a captcha...

Prove that you're not a robot. Divide the numbers you see in the image.

953281 / 713 ______________

Re: The Int Divide

2009-06-10 10:13 • by SR (unregistered)
268277 in reply to 268276
qbe:
at least a machine was asked to do the division... he could have asked the user with a captcha...

Prove that you're not a robot. Divide the numbers you see in the image.

953281 / 713 ______________


I'll get back to you on that one. Database is down at the moment.

Re: The Int Divide

2009-06-10 10:21 • by girly programmer (unregistered)
268278 in reply to 268245
I notice this gem was born on 08/29/08.

So is that YMD or DMY?


and the 29th month is...?

Re: The Int Divide

2009-06-10 10:24 • by My name is missing too (unregistered)
268279 in reply to 268241
But nuking it from orbit is the only way to be sure.

Re: The Int Divide

2009-06-10 10:24 • by Dinnerbone
268280 in reply to 268276
qbe:
at least a machine was asked to do the division... he could have asked the user with a captcha...

Prove that you're not a robot. Divide the numbers you see in the image.

953281 / 713 ______________



Try
VitalCodeThatNeedsThatNumber(input)
Catch Exception
DisplayCaptchaError()
End Try

Re: The Int Divide

2009-06-10 10:26 • by Rocky (unregistered)
I like the fact that if any of his If clauses should fail for whatever reason, the function will happily return 0.

I can just imagine this being used in a financial application.

Re: The Int Divide

2009-06-10 10:27 • by snoofle
268283 in reply to 268278
girly programmer:
I notice this gem was born on 08/29/08.

So is that YMD or DMY?


and the 29th month is...?

...WTFuary!

Re: The Int Divide

2009-06-10 10:34 • by Kutzi (unregistered)
This is probably just some ingenious way to move some load from the application server to the database server.
Ever heard of cloud computing or data grids? :)

Re: The Int Divide

2009-06-10 10:35 • by Bob (unregistered)
The design document probably specified that all computations be performed on the database.

Re: The Int Divide

2009-06-10 10:36 • by vi (unregistered)
268288 in reply to 268276
And the correct answer to this will prove the user IS a robot, right?

Re: The Int Divide

2009-06-10 10:37 • by vi (unregistered)
268291 in reply to 268288
vi:
And the correct answer to this will prove the user IS a robot, right?


I mean, "953281 / 713 ______________" :)

Re: The Int Divide

2009-06-10 10:41 • by Brady Kelly (unregistered)
268293 in reply to 268261
amischiefr:
Moredate Madness:
I notice this gem was born on 08/29/08.

So is that YMD or DMY?

How about neither, unless on your planet there are 29 months...

How about the standard Month - Day - Year?


This forum really needs a (hand slapping forehead) "Duh!" icon.

Welcome, genius.
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment