• leppie (unregistered)

    Ouch!

  • 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.

  • RandomPersona (unregistered) in reply to leppie

    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.

  • sponk (unregistered)

    I can't say I really believe this.

  • (cs)

    Just awesome!

  • my name is missing (unregistered)

    Using SQL to divide two integers is like using an atomic bomb to swat a fly.

  • 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.

  • GameFreak (unregistered)

    Concatenating SQL for a statement that is unnecessary in the first place?

  • 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?

  • Moredate Madness (unregistered)

    I notice this gem was born on 08/29/08.

    So is that YMD or DMY?

  • (cs) in reply to sponk
    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...

  • (cs) in reply to Textual Advanced
    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?

  • (cs)

    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!

  • (cs)

    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?

  • silent d (unregistered)

    It's so cute that he checks the row count of a SQL statement that is not selecting from a table.

  • (cs) in reply to sponk
    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.

  • Max (unregistered)

    ...what about the handy integer division operator "" ? No no no...on second thought that would've been far too easy.

  • Steve the Cynic (unregistered) in reply to drachenstern
    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...

  • Steve the Cynic (unregistered) in reply to Steve the Cynic

    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...

  • (cs) in reply to Moredate Madness
    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.

  • Yeah Baby (unregistered) in reply to Pjotr G
    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!
  • 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!

  • (cs)

    Now I know why they told me that divisions were expensive.

  • Moredate Madness (unregistered) in reply to ThomsonsPier
    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...)

  • (cs) in reply to Whoevar
    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.

  • (cs) in reply to Moredate Madness
    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?

  • Moredate Madness (unregistered) in reply to amischiefr
    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.

  • ashmud (unregistered)

    Is your very first day different from your first day?

  • Warren (unregistered)

    What a shame they had to write another version for Longs not, er, long, afterwards. .NET just isn't good enough!

  • 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

  • (cs) in reply to Moredate Madness
    Moredate Madness:
    And, as is the nature of standards, there is only one right way to do it.

    Unless it's perl... Or Microsoft.

  • (cs) in reply to dpm
    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.
  • Tycho (unregistered) in reply to Whoevar
    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.

  • Whoevar (unregistered) in reply to Moredate Madness
    Moredate Madness:
    And, as is the nature of standards, ...

    ... there are lots to choose from?

  • (cs) in reply to kastein
    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.

  • Brompot (unregistered) in reply to my name is missing
    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.

  • (cs)

    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?

  • (cs) in reply to ubersoldat
    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.

  • 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   ______________
  • SR (unregistered) in reply to qbe
    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.

  • girly programmer (unregistered) in reply to Moredate Madness
    I notice this gem was born on 08/29/08.

    So is that YMD or DMY?

    and the 29th month is...?

  • My name is missing too (unregistered) in reply to my name is missing

    But nuking it from orbit is the only way to be sure.

  • (cs) in reply to qbe
    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
    
  • 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.

  • (cs) in reply to girly programmer
    girly programmer:
    I notice this gem was born on 08/29/08.

    So is that YMD or DMY?

    and the 29th month is...?

    ...WTFuary!

  • 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? :)

  • Bob (unregistered)

    The design document probably specified that all computations be performed on the database.

  • vi (unregistered) in reply to qbe

    And the correct answer to this will prove the user IS a robot, right?

  • vi (unregistered) in reply to vi
    vi:
    And the correct answer to this will prove the user IS a robot, right?

    I mean, "953281 / 713 ______________" :)

  • Brady Kelly (unregistered) in reply to amischiefr
    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.

Leave a comment on “The Int Divide”

Log In or post as a guest

Replying to comment #:

« Return to Article