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

    Surprisingly, the United States'. http://en.wikipedia.org/wiki/Calendar_date#mm.2Fdd.2Fyy_or_mm.2Fdd.2Fyyyy_.28month.2C_day.2C_year.29

    That's the great thing about standards, there are so many to choose from.

  • Brady Kelly (unregistered) 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...?

    girly programmer:
    indeed.
  • (cs)

    Well, at last this approach is well scallable, it could be setup as a integer division cluster!

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

    So is that YMD or DMY?

    Hmm... could be YDM or MDY. Can't tell.

  • (cs) 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 retarded Month - Day - Year?

    FTFY. No need to thank me.

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

    No, its more like catching the fly and putting it in a box that you then post to your accountant with instructions for him to swat the fly and send it back to you.

  • HeyYall (unregistered)

    I almost took a job where only IT guy was leaving.

    In about 3 days he was trying to train me to do a quite lengthy process that was only documented in his head and on random documents. He was leaving the U.S. for the U.K. for his new job. No one else knew how to run the system.

    The job consisted of a Java with SAS and a webserver. The Java part was written by a 3rd company in FL and got slower and slower as more data was entered (via users by a MS access application and various spreadsheets). And there was no backup server. :)

  • Julia (unregistered)

    Not a WTF at all. The next expensive upgrade to sell, with dramatic performance enhancements, is only ten minutes' work away...

  • KM (unregistered)

    I have to admit, I have written my own divide/remainder functions before, but that's because the default operators in most languages don't follow the correct mathematical convention for negative numerators.

  • Roy (unregistered)

    Small wtf: [quote] Yes, Aaron made a call to SQL Server, and filled a DataSet just divide two integers! I guess Math.Floor(Num / Denom) was too easy. [quote]

    We all know that an int divide doesnt need to be floored right? Because an int divide dismisses the numbers after the seperator (9/4 = 2.25 but in int divide that is 2 (note: not rounded 7.9999 would become 7).

    So the floor would be redundand. All he needed was Num / Denom. And at first some check to see if denom wasnt 0.

  • Steve (unregistered)

    Another case of "Man who owns only a hammer" syndrome? I know someone who uses Excel to write press releases.

  • (cs) in reply to Steve
    Steve:
    I know someone who uses Excel to write press releases.

    Wait what?

  • Zapp Brannigan (unregistered) in reply to HeyYall
    HeyYall:
    I *almost* took a job where only IT guy was leaving.

    In about 3 days he was trying to train me to do a quite lengthy process that was only documented in his head and on random documents. He was leaving the U.S. for the U.K. for his new job. No one else knew how to run the system.

    The job consisted of a Java with SAS and a webserver. The Java part was written by a 3rd company in FL and got slower and slower as more data was entered (via users by a MS access application and various spreadsheets). And there was no backup server. :)

    What happens when you have a lone IT guy is very similar to what happens to species development in isolated populations. i.e. you wind up with some weird mutations. No mayonnaise in Ireland (No man is an island)
  • (cs) in reply to Steve
    Steve:
    Another case of "Man who owns only a hammer" syndrome? I know someone who uses Excel to write press releases.

    That doesn't supprise me. In the company where I work excel is used for everything from data storage to bug reports (even though we have proper database and bug reporting solutions in place - they just don't get used).

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

    Yes this is true. The author of this article's WTF code is a terminator of common sense and basic logic.

  • ChrisE (unregistered)

    Come on, we all know America is too retarded to come up with a date format that orders each component by significance. That would be, you know, sensible and everything.

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

    That reminds me - Happy 3rd of Quizzleqoth everybody!
  • Trevor D'Arcy-Evans (unregistered)

    "When all you have is a hammer, everything looks like a nail".

    I worked with someone who was adamant that:

    1. all calculations should be done as SPs on the database
    2. all data should be stored in the database

    I pointed out that:

    1. SPs intertwine logic and data
    2. a database is only useful if you're sharing the data (we weren't)

    At that point, his eyes glazed over...

  • Bosshog (unregistered) in reply to Alan
    Alan:
    my name is missing:
    Using SQL to divide two integers is like using an atomic bomb to swat a fly.

    No, its more like catching the fly and putting it in a box that you then post to your accountant with instructions for him to swat the fly using an atomic bomb and send it back to you.

    FTFY.

    Pesky accountant, never does as he's told.

  • revenant (unregistered)

    This is just lame. Everyone knows that division is a slow operation. He had to create a table on that server, with 3 columns: numerator, denominator, result, to cache the results of frequently used divisions. And if there is no entry for given parameters, only then it should actually divide (and store the result in the table). There could be a stored proc for all this logic.

  • Zapp Brannigan (unregistered) in reply to revenant
    revenant:
    This is just lame. Everyone knows that division is a slow operation. He had to create a table on that server, with 3 columns: numerator, denominator, result, to cache the results of frequently used divisions. And if there is no entry for given parameters, only then it should actually divide (and store the result in the table). There could be a stored proc for all this logic.
    Since it's integer division, a look up table with all possible combinations of numerator and denominator is a valid approach. I usually create a loop and subtract when I want to divide. I loop and add for multiplication. But I'm a disgruntled curmudgeon, to each his own.
  • RandomUser423651 (unregistered) in reply to Smash King

    The USA date format of Month/Day/Year appears to have evolved (devolved?) from the common US written form: Month Day, Year. (E.g. June 10, 2009.)

    Of course, it is not entirely uncommon (at least in US English) for the comma to indicate that items have been transposed. Thus, "Doe, John Alva" would represent "John Alva Doe" and "Boring Book Title, The" would represent "The Boring Book Title". In this way, the date may have originally been formatted as "2009 June 10", but was reordered so as not to begin with digits.

  • justsomedude (unregistered) in reply to RandomUser423651

    The real WTF is he didn't put the ds.tables(0) into a With...End With block. Geeze, doesn't he know anything about speed optimization?

  • RandomUser423651 (unregistered) in reply to RandomUser423651

    And then, of course, as the masses became literate and were taught how to write dates but not why they were in that order, it just sort of stuck.

  • hikari being too lazy to login. (unregistered) in reply to D C Ross
    D C Ross:
    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.

    .NET doesn't do NaN, it would just throw an exception. DivideByZeroException, in fact.

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

    I have, at work. My predecessor also had an interesting approach to programming. This is what happens when you hire an economist (now financial lawyer) to write code for you.

  • (cs) in reply to hikari being too lazy to login.
    hikari being too lazy to login.:
    D C Ross:
    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.

    .NET doesn't do NaN, it would just throw an exception. DivideByZeroException, in fact.

    I just tried this out in VB.NET (The original code looks like VB.NET to me), the following code gave me "Uhoh, a System.OverflowException was thrown!"

            Dim x As Integer = 123
            Dim y As Integer = 0
            Dim result As Integer = 0
    
            Try
                result = CInt(x / y)
                Console.WriteLine("It worked, the answer is: " & result.ToString())
            Catch ex As Exception
                Console.WriteLine("Uhoh, a " & ex.GetType().ToString() & " was thrown!")
            End Try
    
            Console.ReadKey(True)
    

    Whereas this code gave me "It worked, the answer is: Infinity":

            Dim x As Integer = 123
            Dim y As Integer = 0
            Dim result As Double = 0
    
            Try
                result = x / y
                Console.WriteLine("It worked, the answer is: " & result.ToString())
            Catch ex As Exception
                Console.WriteLine("Uhoh, a " & ex.GetType().ToString() & " was thrown!")
            End Try
    
            Console.ReadKey(True)
    
  • Somebody's NaN (unregistered) in reply to hikari being too lazy to login.
    hikari being too lazy to login.:
    D C Ross:
    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.

    .NET doesn't do NaN, it would just throw an exception. DivideByZeroException, in fact.

    .NET does indeed speak NaN

    http://msdn.microsoft.com/en-us/library/system.double.nan(VS.71).aspx

  • me (unregistered) 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...?

    Chucktober!

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

    Nah, there's too much difference in power there. A rubber mallet would be a better fit.

  • Jay (unregistered) 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...?

    Sugust!

  • Dan (unregistered) 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?

    That's amazing! I've got the same combination on my luggage!

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

    So is that YMD or DMY?

    DMY? I know what that means, young lady!

  • Are Three (unregistered) in reply to Dinnerbone

    Well, at least it got the answer right on the second piece of code. Even though I don't think that you can continue to compute with the 'Infinity' it gave as a result.

    Actually x/0 returns "Complex Infinity" (a quantity with infinite magnitude, but undetermined complex phase) http://www43.wolframalpha.com/input/?i=123%2F0

    where as log(x/0) returns "Infinity" http://www43.wolframalpha.com/input/?i=log%28123%2F0%29

    What would vb.net return if you tried to take the log of 'result' in the above example? ...

    better yet, try 1/result which should return 0.

  • i can explain everything (unregistered)

    there's a perfectly valid reason for doing this you've all missed. if the application was a database based application that could use multiple providers, each of which performed integer division in a different fashion, and you wanted to ensure that whatever database you used, the integer division within the app was done in the same way as the database, this would be the way forward.

    of course, you'd be better off going home.

  • (cs) in reply to Are Three
    Are Three:
    What would vb.net return if you tried to take the log of 'result' in the above example? ...
            Dim x As Integer = 123
            Dim y As Integer = 0
            Dim result As Double = 0
    
        Try
            result = Math.Log(x / y)
            Console.WriteLine("It worked, the answer is: " & result.ToString())
        Catch ex As Exception
            Console.WriteLine("Uhoh, a " & ex.GetType().ToString() & " was thrown!")
        End Try
    
        Console.ReadKey(True)
    

    == "It worked, the answer is: Infinity"

    Are Three:
    better yet, try 1/result which should return 0.
            Dim x As Integer = 123
            Dim y As Integer = 0
            Dim result As Double = 0
    
        Try
            result = x / y
            result = 1 / result
            Console.WriteLine("It worked, the answer is: " & result.ToString())
        Catch ex As Exception
            Console.WriteLine("Uhoh, a " & ex.GetType().ToString() & " was thrown!")
        End Try
    
        Console.ReadKey(True)
    

    == It worked, the answer is: 0

  • Marc B (unregistered) 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.

    Yes, that's great, but I'm guessing that Google is not using SQL Server to perform it's equations. I want SQL Server quality answers, not just some answers produced by a puny on-chip floating point processor.

  • justsomedude (unregistered) in reply to Are Three
    Are Three:
    Well, at least it got the answer right on the second piece of code. Even though I don't think that you can continue to compute with the 'Infinity' it gave as a result.

    Actually x/0 returns "Complex Infinity" (a quantity with infinite magnitude, but undetermined complex phase) http://www43.wolframalpha.com/input/?i=123%2F0

    where as log(x/0) returns "Infinity" http://www43.wolframalpha.com/input/?i=log%28123%2F0%29

    What would vb.net return if you tried to take the log of 'result' in the above example? ...

    better yet, try 1/result which should return 0.

    Good god, I'm blown away. Is this really the way .NET handles div by zero operations?

    My background is physics/math so yes I do understand why/when these answers can be considered valid or can be useful, but I sure as hell don't want my app to contine happily along without throwing an exception...on the x/0 operation...if the code happens to try dividing by zero!

    If I was coding in mathematica or maple I'd expect the advanced behavor, but not with a 'traditional' development platform!

    Holy crap! That just seems like a problem waiting to happen...

  • (cs) in reply to D C Ross
    D C Ross:
    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.

    The 0/0 indeterminate is funny, because business specifications usually want it to resolve to something that's still a metric. In the case of percentages, I run into "if zero met the test out of zero cases possible, then we want that to read 100% compliance."

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

    That's amazing! I've got the same combination on my luggage!

    Wouldn't it be something if ubersoldat was storing his debit card in Dan's luggage?

  • caper (unregistered)

    When will we see some more of that guy's work. Tomorrow ?

  • Sean Connery (unregistered) 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...?

    Febtober!

  • (cs) in reply to Dinnerbone
    Dinnerbone:
    Steve:
    I know someone who uses Excel to write press releases.

    Wait what?

    They make the facts and figures he quotes more valid.

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

    So is that YMD or DMY?

    Sheesh. I feel foolish now... I was having trouble figuring out the WTF when I read the article. I'm so glad I read the comments now so that I could be better edumucated.

  • Are Three (unregistered) in reply to Dinnerbone

    Thanks, Dinnerbone ...

    What about on the first try

     result = x / y
    
     result = Math.Log(result)
    

    I am curious (I should just install vb.net here) that result can carry around Infinity as an answer.

    So what is the proper way to do this? CInt throws an exception, so I suppose that would be the right function to use (if you didn't want a complex answer).

    I agree that even though the results are correct, and this is just mental fun and games right now since the original code checked for a 0 in the denominator, that I would want some sort of exception, usually. Wouldn't you?

  • heretic (unregistered) in reply to Moredate Madness

    Umm, what calendar do you? Mine only goes to 12.

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

    So is that YMD or DMY?

    Umm, what calendar do you? Mine only goes to 12.

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

    So is that YMD or DMY?

    Umm, what calendar do you? Mine only goes to 12.

    Argh, that should be:

    heretic:
    Umm, what calendar do you use? Mine only goes to 12.
  • Superfly (unregistered) in reply to Yeah Baby

    Hehehehehehe, heh!

    The story was funny, but this point really made me crack up :-)

  • annymouse (unregistered) in reply to Trevor D'Arcy-Evans
    Trevor D'Arcy-Evans:
    "When all you have is a hammer, everything looks like a nail".

    I worked with someone who was adamant that:

    1. all calculations should be done as SPs on the database
    2. all data should be stored in the database

    I pointed out that:

    1. SPs intertwine logic and data
    2. a database is only useful if you're sharing the data (we weren't)

    At that point, his eyes glazed over...

    Nice troll attempt

Leave a comment on “The Int Divide”

Log In or post as a guest

Replying to comment #:

« Return to Article