• anonym (unregistered)
    1. 0
    2. 1
    3. ?
    4. profit / first!
  • (cs)

    Shame the Distributed Applications Group wasn't called the Distributed Operations Group.

    Your combined operation would be WAGDOG.

  • (cs)

    I've actually written code kinda like this... but it never made it past testing, was just quick ugly testing code while I was debugging something else. I heavily // TODO: flagged it and removed it before getting much further.

  • BK (unregistered)

    For some people, exceptions are just another form of GOTO

  • (cs)

    Divide this comment by zero.

  • (cs) in reply to BK
    BK:
    For some people, exceptions are just another form of GOTO

    I maintain code written by someone who also used them as a break statement.

  • Anonymous (unregistered)

    Ahh, "elite consultants" - where would TDWTF be without them?

  • RayRay (unregistered) in reply to hikari
    hikari:
    BK:
    For some people, exceptions are just another form of GOTO

    I maintain code written by someone who also used them as a break statement.

    I thought you were going to stop talking about me behind my back.

  • Steve (unregistered)

    You sir, are my hero!

    I'm not talking to anyone in particular but I thought I'd get it out there since it seems to be expression of the month at the moment and someone's going to say it sooner or later.

    Whilst I'm here, "the googles, they do nothing" and "the REAL WTF is <insert non-WTF here>". Oh, and "frist" (not).

  • thg (unregistered)

    Stuck programming in a language that does not offer Exception Handling? .. Use the good-old "divide by zero" trick.

    Next week: generating Bus Errors to implement inter-process communication.

  • Tryde (unregistered) in reply to hikari
    hikari:
    BK:
    For some people, exceptions are just another form of GOTO

    I maintain code written by someone who also used them as a break statement.

    I worked with an (obfuscated) library in java which used new Exception() along with try/catch blocks in order to exit loops, switches...

    Debugging was great.... :(

  • (cs)

    Do you guys have any idea how discouraging it is to search for an image on the internet, copy its URL, post a message and add the proper BBCode tag to display the image, and then come back a few minutes later to discover that it has been deleted? You're abusing your readership when you do that.

    So, you corrected your misspelled word. What's wrong with annotating my post with "Fixed! - Alex" or something similar? After all, I don't mind clicking on your ads now and again so you can rake in a few coins.

  • (cs) in reply to Steve
    Steve:
    You sir, are my hero! (..) Whilst I'm here, "the googles, they do nothing" and "the REAL WTF is <insert non-WTF here>". Oh, and "frist" (not).
    Brillant!
  • (cs)

    Intentionally creating an error isn't a crazy wtf if you use the error handling code to catch it and do the correct thing...That's basically the entire point of a Try->Catch block.

    Still, assuming there isn't any great efficiency gain, it's better to do it using standard conditionals.

  • Thomas (unregistered)

    Was using Raiserror or a better filter really that cumbersome? It certainly would have provided a better error. I guess I'm missing what claimed savings the consultants seem to think they got by using this silly solution.

  • fluffy777 (unregistered)

    The real WTF is that it's inefficient too.

    let's examine this expression more closely:

    (Active = 1 OR 1/(Active+@ActDivisor) IS NULL)

    so... if Active is 1 then the expression is true, otherwise it's 0 and the expression is "1/(Active + @ActDivisor) IS NULL", so... isn't that just "1/@ActDivisor IS NULL", 'cause Active is 0 ... or... um... what?

  • (cs)

    (1/0)th!

  • (cs) in reply to thg
    thg:
    Stuck programming in a language that does not offer Exception Handling? .. Use the good-old "divide by zero" trick.

    Next week: generating Bus Errors to implement inter-process communication.

    You're late. It's been done. For real. In 1976.

    'leet old skool fun with covert channels

  • MainCoder (unregistered)

    This was just the error reporting. The real question is why this procedure was called all over with both in parameters set to zero.

  • (cs) in reply to fluffy777
    fluffy777:
    The real WTF is that it's inefficient too.

    let's examine this expression more closely:

    (Active = 1 OR 1/(Active+@ActDivisor) IS NULL)

    so... if Active is 1 then the expression is true, otherwise it's 0 and the expression is "1/(Active + @ActDivisor) IS NULL", so... isn't that just "1/@ActDivisor IS NULL", 'cause Active is 0 ... or... um... what?

    So here are the steps: 1) if(Active = 1 or 1/(Active+@ActDivisor) IS NULL) 2) if(Active = 1 or 1/@ActDivisor IS NULL) 3) if(Active = 1 or ActDivisor = 0)

    2 conditional jumps!

  • (cs) in reply to RayRay
    RayRay:
    I thought you were going to stop talking about me behind my back.

    Only when the code stops making me curl up in the corner and cry.

  • (cs) in reply to thg
    thg:
    Stuck programming in a language that does not offer Exception Handling? .. Use the good-old "divide by zero" trick.

    Except this is PL/SQL. Those consultants weren't stuck, they were on crack.

  • (cs)
    try {
        if (iHaveSomethingUsefulToSay) {
           int x = 1 / 0;
        }
        return;
    } catch (Exception e1) {
      try {
          if (itsNotFrist) {
             int y = 2 / 0;
          }
      } catch (Exception e2) {
        try {
            if (iPromiseNotToPostTheCaptcha) {
               int z = 3 / 0;
            }
        } catch (Exception e3) {
          postComment("Yada yada yada");
        }
      }
    }
    
  • Lunkwill (unregistered)

    TRWTF is how the code fails miserably on Active==FILE_NOT_FOUND

  • monkeyPushButton (unregistered) in reply to Steve
    Steve:
    You sir, are my hero!

    I'm not talking to anyone in particular but I thought I'd get it out there since it seems to be expression of the month at the moment and someone's going to say it sooner or later.

    Whilst I'm here, "the googles, they do nothing" and "the REAL WTF is <insert non-WTF here>". Oh, and "frist" (not).

    No, no. YOU sir, are my hero!

  • Zerbs (unregistered) in reply to JamesQMurphy
    JamesQMurphy:
    thg:
    Stuck programming in a language that does not offer Exception Handling? .. Use the good-old "divide by zero" trick.

    Except this is PL/SQL. Those consultants weren't stuck, they were on crack.

    Actually this is T-SQL from MS Sql Server. T-SQL does have try / catch functinality in 2005 and 2008

  • Josh Lefler (unregistered)

    Reminds me of a trick I used long ago when I coded in VB6. It was often useful to know if one was in the IDE or running as a real executable, so I had a handy IsDebug() method.

    Function IsDebug() On Error GoTo bad: Debug.print( 1 / 0) IsDebug = False Exit Function bad: IsDebug = true End Function (Coded from memory and haven't done VB work in years)

    Basically, Debug.print calls aren't compiled into the executable, so an error will only get thrown in the IDE.

    I am so glad I moved on to Linux and left all things Microsoft behind years ago...

  • ebenblues (unregistered) in reply to anonym
    anonym:
    1. 0 2. 1 3. FileNotFound <-- 4. profit / first!
    Solved at last!!
  • (cs) in reply to Josh Lefler
    Josh Lefler:
    Reminds me of a trick I used long ago when I coded in VB6. It was often useful to know if one was in the IDE or running as a real executable, so I had a handy IsDebug() method.

    Function IsDebug() On Error GoTo bad: Debug.print( 1 / 0) IsDebug = False Exit Function bad: IsDebug = true End Function (Coded from memory and haven't done VB work in years)

    Basically, Debug.print calls aren't compiled into the executable, so an error will only get thrown in the IDE.

    I am so glad I moved on to Linux and left all things Microsoft behind years ago...

    Uhhh, why? How does your function turn into "Microsoft = Bad"? Just because you couldn't search the SDK docs and write the following?

    Declare Auto Function IsDebuggerPresent Lib "Kernel32.dll" () as Integer

    (Note: Not sure if that's the correct code, I don't use VB6. IsDebuggerPresent is the Windows SDK exposed method of determining if someone has attached a debugger, though.)

    Still, I like the code. Ingenious, for someone who doesn't know how to use documentation. How would you do this in Linux?

  • (cs) in reply to Erzengel
    Erzengel:
    Josh Lefler:
    Reminds me of a trick I used long ago when I coded in VB6. It was often useful to know if one was in the IDE or running as a real executable, so I had a handy IsDebug() method.

    Function IsDebug() On Error GoTo bad: Debug.print( 1 / 0) IsDebug = False Exit Function bad: IsDebug = true End Function (Coded from memory and haven't done VB work in years)

    Basically, Debug.print calls aren't compiled into the executable, so an error will only get thrown in the IDE.

    I am so glad I moved on to Linux and left all things Microsoft behind years ago...

    Uhhh, why? How does your function turn into "Microsoft = Bad"? Just because you couldn't search the SDK docs and write the following?

    Declare Auto Function IsDebuggerPresent Lib "Kernel32.dll" () as Integer

    (Note: Not sure if that's the correct code, I don't use VB6. IsDebuggerPresent is the Windows SDK exposed method of determining if someone has attached a debugger, though.)

    Still, I like the code. Ingenious, for someone who doesn't know how to use documentation. How would you do this in Linux?

    Read the man page....oh wait

  • (cs) in reply to Zerbs
    Zerbs:
    JamesQMurphy:
    thg:
    Stuck programming in a language that does not offer Exception Handling? .. Use the good-old "divide by zero" trick.

    Except this is PL/SQL. Those consultants weren't stuck, they were on crack.

    Actually this is T-SQL from MS Sql Server. T-SQL does have try / catch functinality in 2005 and 2008

    You're right. PL/SQL doesn't have ISNULL (it has NVL). Just slap me silly and call me Paula.

  • Jay (unregistered) in reply to BK
    BK:
    For some people, exceptions are just another form of GOTO

    Ah, but by using an exception to transfer control rather than a GOTO, you conform to the "no GOTOs" rule, and thus what you have written must be a good structured program!

    Next lesson: The experts agree that embedded constants in a program are bad because their purpose can be unclear, like "adjustedAmount=amount*2.942;" may leave the reader wondering where the number "2.942" comes from. This problem is easily solved by replacing all constants with a symbolic name. In this example, "final static float AMOUNT_FACTOR=2.942;" and then use the name rather than the hard-coded constant to eliminate the problem!

    For advanced students, we will move on to avoiding the pitfalls of global data accessed from a million unrelated functions by declaring the variable private, then create public get and set functions for it and use THOSE from your million unrelated functions. Your data is private, so it meets the "no public data" rule and what you have written must be a properly encapsulated class!

    (Note: This is a joke. Please don't take this advice seriously.)

  • Bosshog (unregistered)

    The goggles, they divide by nothing!

  • Comments Welcome (unregistered)

    Everone missed the real WTF.

    Escaping the ' in the comments.

  • Marc B (unregistered) in reply to Steve
    Steve:
    You sir, are my hero!

    I'm not talking to anyone in particular but I thought I'd get it out there since it seems to be expression of the month at the moment and someone's going to say it sooner or later.

    Whilst I'm here, "the googles, they do nothing" and "the REAL WTF is <insert non-WTF here>". Oh, and "frist" (not).

    I'm hoping next month's expression will be "shovel-ready", as in "that code was a real pile of shovel-ready dogsh*t". Why should the politicians have all the fun?

  • Anonymous (unregistered) in reply to Bosshog
    Bosshog:
    The goggles, they divide by nothing!

    You sir, are an idiot commenter.

    Captcha: ingenium (a genius who continually submits nothing but comments about goggles?)

  • (cs) in reply to Anonymous
    Anonymous:
    Bosshog:
    The goggles, they divide by nothing!

    You sir, are an idiot commenter.

    Captcha: ingenium (a genius who continually submits nothing but comments about goggles?)

    No one gives a Pope's Hat about the captcha you got. Most of us probably wish it was a bannable offense (and yes, I know some smartass is going to say complaining about it is just as bad. No, you don't have to fulfill this prophecy.)

  • (cs) in reply to Jay
    Jay:
    For advanced students, we will move on to avoiding the pitfalls of global data accessed from a million unrelated functions by declaring the variable private, then create public get and set functions for it and use THOSE from your million unrelated functions. Your data is private, so it meets the "no public data" rule and what you have written must be a properly encapsulated class!

    (Note: This is a joke. Please don't take this advice seriously.)

    Actually keeping member variables private and using get/set methods is a pretty damn good idea. Imagine you have a very frequently used class and suddenly due to new requirements you need something special to happen when it's value is changed. What do you prefer to do, make one change to the set method or change each one of your million unrelated functions?

  • (cs) in reply to Kermos
    Kermos:
    Jay:
    For advanced students, we will move on to avoiding the pitfalls of global data accessed from a million unrelated functions by declaring the variable private, then create public get and set functions for it and use THOSE from your million unrelated functions. Your data is private, so it meets the "no public data" rule and what you have written must be a properly encapsulated class!

    (Note: This is a joke. Please don't take this advice seriously.)

    Actually keeping member variables private and using get/set methods is a pretty damn good idea. Imagine you have a very frequently used class and suddenly due to new requirements you need something special to happen when it's value is changed. What do you prefer to do, make one change to the set method or change each one of your million unrelated functions?

    Depends on how far removed the unrelated functions are from the class. If they're in the same executable, and I'm using Microsoft's compiler, I can just replace the data with a __declspec(property). For example,

    class SomeClass
    {
        public:
        int MyData;
    };
    

    becomes

    class SomeClass
    {
        private:
        int _MyData;
        public:
        __declspec(property(get=GetMyData, put=SetMyData)) int MyData;
        int GetMyData()
        {
            return _MyData;
        }
        void SetMyData(int value)
        {
            //TODO: validation, propagation, whatever
            _MyData = value;
        }
    };
    

    That would require no more changes to the surrounding functions. Same deal when working in C#, just with language support instead of compiler specific functionality.

    HOWEVER, all bets are off if this is a library that is imported or loaded into another executable.

    Also, I don't know if GCC has anything similar.

  • (cs) in reply to Erzengel
    Erzengel:
    Depends on how far removed the unrelated functions are from the class. If they're in the same executable, and I'm using Microsoft's compiler, I can just replace the data with a __declspec(property). For example,
    class SomeClass
    {
        public:
        int MyData;
    };
    
    becomes
    class SomeClass
    {
        private:
        int _MyData;
        public:
        __declspec(property(get=GetMyData, put=SetMyData)) int MyData;
        int GetMyData()
        {
            return _MyData;
        }
        void SetMyData(int value)
        {
            //TODO: validation, propagation, whatever
            _MyData = value;
        }
    };
    

    That would require no more changes to the surrounding functions. Same deal when working in C#, just with language support instead of compiler specific functionality.

    HOWEVER, all bets are off if this is a library that is imported or loaded into another executable.

    Also, I don't know if GCC has anything similar.

    That declspec property thing is neat, I like it. Don't think GCC does, a quick look at it's attribute list doesn't reveal anything like it. In my case though my code needs to compile both under GCC and MS' Compiler so I can't use anything that is compiler specific anyway.

    The Eclipse IDE does have support for automatically generating getters / setters, though it still needs a bit of tweaking to really become useful. It currently doesn't support enough customization to make what it generates fit the surrounding coding style and it also doesn't give me the option of making getters return a const reference. By the time I hand-edit what it has generated it generally is still easier to write the methods myself.

    It's a new feature though so hopefully Version 6 will see improvements there. :)

  • (cs) in reply to BK
    BK:
    For some people, exceptions are just another form of GOTO
    Now THAT is funny!!
  • (cs) in reply to snoofle
    snoofle:
    try {
        if (iHaveSomethingUsefulToSay) {
           int x = 1 / 0;
        }
        return;
    } catch (Exception e1) {
      try {
          if (itsNotFrist) {
             int y = 2 / 0;
          }
      } catch (Exception e2) {
        try {
            if (iPromiseNotToPostTheCaptcha) {
               int z = 3 / 0;
            }
        } catch (Exception e3) {
          postComment("Yada yada yada");
        }
      }
    }
    
    But THIS is funnier!!
  • Daniel (unregistered) in reply to Erzengel

    If you're using C++, just overload the = operator!

  • Meistert (unregistered) in reply to Steve
    Steve:
    You sir, are my hero!

    I'm not talking to anyone in particular but I thought I'd get it out there since it seems to be expression of the month at the moment and someone's going to say it sooner or later.

    Whilst I'm here, "the googles, they do nothing" and "the REAL WTF is <insert non-WTF here>". Oh, and "frist" (not).

    Brillant

  • Americium (unregistered) in reply to Zerbs
    Zerbs:
    JamesQMurphy:
    thg:
    Stuck programming in a language that does not offer Exception Handling? .. Use the good-old "divide by zero" trick.

    Except this is PL/SQL. Those consultants weren't stuck, they were on crack.

    Actually this is T-SQL from MS SQL Server. T-SQL does have try / catch functionality in 2005 and 2008

    Oracle PL/SQL supports exceptions. It is a derivative of Ada, which has its own try..catch idiom. Ada has a block structured begin..exception..end instead.

    Ada will raise an exception, rather than throw it. Python borrows this term, but still uses try..catch.

    begin raise Some_Error exception when Some_Error then -- Do something when others then -- Handle any other exception end;

  • (cs) in reply to Josh Lefler
    Josh Lefler:
    I am so glad I moved on to Linux and left all things Microsoft behind years ago...

    Its not a microsoft problem, its an idiot problem.

  • Jim (unregistered) in reply to Jay
    Jay:
    BK:
    For some people, exceptions are just another form of GOTO

    Ah, but by using an exception to transfer control rather than a GOTO, you conform to the "no GOTOs" rule, and thus what you have written must be a good structured program!

    Next lesson: The experts agree that embedded constants in a program are bad because their purpose can be unclear, like "adjustedAmount=amount*2.942;" may leave the reader wondering where the number "2.942" comes from. This problem is easily solved by replacing all constants with a symbolic name. In this example, "final static float AMOUNT_FACTOR=2.942;" and then use the name rather than the hard-coded constant to eliminate the problem!

    For advanced students, we will move on to avoiding the pitfalls of global data accessed from a million unrelated functions by declaring the variable private, then create public get and set functions for it and use THOSE from your million unrelated functions. Your data is private, so it meets the "no public data" rule and what you have written must be a properly encapsulated class!

    (Note: This is a joke. Please don't take this advice seriously.)

    Better still: #define TWO_POINT_NINE_FOUR_TWO 2.942

  • The Prophet Omar (unregistered) in reply to kastein
    kastein:
    Anonymous:
    Bosshog:
    The goggles, they divide by nothing!

    You sir, are an idiot commenter.

    Captcha: ingenium (a genius who continually submits nothing but comments about goggles?)

    No one gives a Pope's Hat about the captcha you got. Most of us probably wish it was a bannable offense (and yes, I know some smartass is going to say complaining about it is just as bad. No, you don't have to fulfill this prophecy.)

    Complaining about it is twice as worserer....in accordance with the Prophecy

  • Bob (unregistered) in reply to kastein
    kastein:
    No one gives a Pope's Hat about the captcha you got.
    If I had a pope's hat handy, I'ld give it to him.
    kastein:
    No, you don't have to fulfill this prophecy.)
    Technically true, but every time someone mentions a captcha there's a certainty that someone will complain about it, and you did feel obliged to fulfill that prophecy, apparantly under the sincere believ that this time your complaint will make the world a better place.

    Once you succeed in that, you should probably pop over to the middle east and tell those guys to just get over their differences. And they wouldn't even want a pope's hat.

    (Incidentally, my captcha was 'laoreet' but I don't have anything funny to say about it. Sorry.)

  • Americium (unregistered) in reply to Americium
    Americium:
    ... Ada will raise an exception, rather than throw it. Python borrows this term, but uses try..catch.

    correction: Python uses try..except. It bastardizes all the exception-handling syntax!

    try: raise Some_Error except Some_Error: do_something() except Exception,e : pass Handle any other exception

Leave a comment on “Dividing by Zero for Fun and Profit”

Log In or post as a guest

Replying to comment #:

« Return to Article