• Roman (unregistered)

    Whoa! This is some neat code. :)

  • (cs)

    Isn't it ironic that an article, beginning with a statement about "typing", has this typographical error? ... change about how we write ode:

  • (cs) in reply to ParkinT
    ParkinT:
    Isn't it ironic that an article, beginning with a statement about "typing", has this typographical error? ... change about how we write ode:

    You may just write code. When some of us do it, it's even an ode ;-)

  • Keith Hackney (unregistered)

    The Real WTF is that this site crashed for a couple of minutes just before this new article appeared. Could this be the repeated hammering of F5 by the fisters?

    captcha = dreadlocks

  • Thomas (unregistered) in reply to swapo
    swapo:
    ParkinT:
    Isn't it ironic that an article, beginning with a statement about "typing", has this typographical error? ... change about how we write ode:

    You may just write code. When some of us do it, it's even an ode ;-)

    "to their ay of doing things"

    Making an ode or an ay? ;-)

  • (cs) in reply to ParkinT
    ParkinT:
    Isn't it ironic that an article, beginning with a statement about "typing", has this typographical error? ... change about how we write ode:
    Or this one: try to make the language adapt to their ay of doing things.
  • Anonymous Coward (unregistered)

    Well, the biggest WTF is that the code is in Java for sure... And, he clearly uses the exception to get a stack trace... however, IIRC stack trace is initialized upon construction, not when the throwable is thrown.

  • Tachyomatic (unregistered)

    Since when did .net have the final keyword?

    craaazy indeed!

  • T$ (unregistered) in reply to swapo

    Yeah, as the author says, it's just his "ay" of doing it.

    CAPTCHA: burned, haha

  • (cs)

    An Ode! Aye Captain! Arrrr

  • Anonymous Coward (unregistered) in reply to Anonymous Coward
    Anonymous Coward:
    Well, the biggest WTF is that the code is in Java for sure... And, he clearly uses the exception to get a stack trace... however, IIRC stack trace is initialized upon construction, not when the throwable is thrown.

    If the error was truly fatal and there was no point in continuing the execution, he should have thrown an Error.

    To get the stack trace in logs, he could have used

    protected final void BUG (String msg) {
        logger.fatal (msg, new RuntimeException("Assertion failure"));
        System.exit (1);
    }
    
  • (cs)

    For what the code is supposed to do (in the eyes of the original coder) it is fairly concise. That's what a WTF is all about - well written code to do the exactly wrong thing!

  • (cs)

    Let us not overlook that he creates a completely empty Exception ---- and then logs it, as if it had some useful information......

  • rycamor (unregistered)

    An Ode to the Ay of Certain Developers:

    Forsooth! And how doth the keyboard clack As when, among twin perils of unnecessary loops and strange Inner Platforms, Bestride the angry waters of unfamiliar syntax and new paradigms Doth the Certain Developer lament: alas and alack! My brain hurteth so: ay ay ay This mountain, this Learning Curve, I durst not climb.

    But wherein his refuge? Of what dost thou speak?

    I speak of the inevitable temptation, to wit: As Alexander crossed the Hellespont, As Odysseus braved maelstrom, Verily as Hercules confronted the Hydra, So our hero confronts the Language Beast, And vanquishes the angry unknown, be it syntax or context, With an onslaught, truly a fusillade: the Wrapper of our Discontent, That the Language may, to his will be bent.

  • Lothar (unregistered) in reply to Anonymous Coward

    however, IIRC stack trace is initialized upon construction, not when the throwable is thrown.

    AFAIR exceptions on Java 1.0 and 1.1 have to be thrown to get the stacktrace filled in. If the code is older, this might be a correct attempt to get the assert-function working.

    Regards, Lothar

  • Mike Dimmick (unregistered)

    If you want a stack trace in .NET, call Environment.StackTrace.

  • David (unregistered)

    I once wrote:

    /**

    • Does what it says on the tin */ public static void crash(){ System.exit(1); }

    ... it worked every time...

  • (cs) in reply to rycamor
    An Ode to the Ay of Certain Developers

    Beautiful wipes tear from his eye

  • anne (unregistered) in reply to rycamor
    rycamor:
    An Ode to the Ay of Certain Developers:

    Oh boy it's a computer geek AND a classics geek! What an awesome combination. Kudos to you!

  • (cs) in reply to rycamor
    rycamor:
    An Ode to the Ay of Certain Developers:

    I just had to format that one and post it on our geek wall. Here's a screenshot of it in Word Print Preview (sorry, no tables involved).

    [image]

    Addendum (2007-06-11 14:33): I added in "the" and added in a break after the comma in "...unknown, be it". I then printed out the new copy and replaced it on the wall.

  • rycamor (unregistered) in reply to AbbydonKrafts

    I am duly honored.

    BTW, I made a small typo: there should be a "the" in front of "maelstrom".

  • Fred (unregistered)

    I fail to see the wtf, here. I used to write code exactly like this a few years ago, as it was the only know way to get a stack frame in Java.

    The real wtf seem to be the speed by which this site is going down the tube (even renaming from "what the fuck" to "worse than failure" made me thin WTF...)

  • (cs) in reply to rycamor
    rycamor:
    An Ode to the Ay of Certain Developers:

    Forsooth! And how doth the keyboard clack As when, among twin perils of unnecessary loops and strange Inner Platforms, Bestride the angry waters of unfamiliar syntax and new paradigms Doth the Certain Developer lament: alas and alack! My brain hurteth so: ay ay ay This mountain, this Learning Curve, I durst not climb.

    But wherein his refuge? Of what dost thou speak?

    I speak of the inevitable temptation, to wit: As Alexander crossed the Hellespont, As Odysseus braved maelstrom, Verily as Hercules confronted the Hydra, So our hero confronts the Language Beast, And vanquishes the angry unknown, be it syntax or context, With an onslaught, truly a fusillade: the Wrapper of our Discontent, That the Language may, to his will be bent.

    Your true talents are wasted on mere "code-banging"! Excellent work.
  • ThingGuy McGuyThing (unregistered) in reply to swapo
    swapo:
    An Ode! Aye Captain! Arrrr

    Worst. Haiku. Ever.

  • Calvin Spealman (unregistered)

    This is exactly the thing I try to guard against when teaching people to be "pythonic" when writing Python code, and what I am trying to get across in my last blog post Dynamic Hell in Python Names. Moving between languages inevitably drags along both bad and good ideas that all become bad in the new environment.

  • (cs) in reply to rycamor
    rycamor:
    An Ode to the Ay of Certain Developers:

    Forsooth! And how doth the keyboard clack As when, among twin perils of unnecessary loops and strange Inner Platforms, Bestride the angry waters of unfamiliar syntax and new paradigms Doth the Certain Developer lament: alas and alack! My brain hurteth so: ay ay ay This mountain, this Learning Curve, I durst not climb.

    But wherein his refuge? Of what dost thou speak?

    I speak of the inevitable temptation, to wit: As Alexander crossed the Hellespont, As Odysseus braved maelstrom, Verily as Hercules confronted the Hydra, So our hero confronts the Language Beast, And vanquishes the angry unknown, be it syntax or context, With an onslaught, truly a fusillade: the Wrapper of our Discontent, That the Language may, to his will be bent.

    You, sir, have earned the title of Poet Laureate for WorseThanFailure.com. I bow to your poetry skillz.

  • (cs) in reply to Roman

    That's almost the same as the error handling at a previous job:

    try
    {
       // do crap here
    } catch (...) {
       cout << "Abnormal program termination." << endl;
       exit(1);
    }
    
  • Frost (unregistered) in reply to David
    David:
    I once wrote:

    /**

    • Does what it says on the tin */ public static void crash(){ System.exit(1); }

    ... it worked every time...

    The REAL WTF is that you think the function name is an accurate description of what happens.

  • Onaka The Kaka (unregistered)

    I wouldn't really call this a WTF, it's just an example of someone who doesn't understand Exceptions.

  • woohoo (unregistered) in reply to Thomas
    Thomas:
    swapo:
    ParkinT:
    Isn't it ironic that an article, beginning with a statement about "typing", has this typographical error? ... change about how we write ode:

    You may just write code. When some of us do it, it's even an ode ;-)

    "to their ay of doing things"

    Making an ode or an ay? ;-)

    Which game might it have been that ruined the "c" and "w" keys on Alex' keyboard? ;o)

    BTW, it's Java, not C#, and another minor WTF lurks in the disregard of proper Java naming conventions, i.e. the notation of the function name (all caps...).

    Said developer is either an AOL user or a Csharpie all right... ;o))

  • (cs)
    a whole lot of “little things” change about how we write ode
    Little, yes... fundamental.

    You must remember this: A catch is just a catch; a try is just a try. The fundamental things apply As platforms go by.

  • sol (unregistered)

    WTF does Assert do anyway? Really.

    Does it stop program execution if true? Does it Assert that the value is indeed the value or does it just write the value to a debug window. VB programmers everywhere need to know.

    I mean it's not like debuggers are usefully anyway.... I mean really I could manually evaulate all the code in my head in context and find the problem.. right?

  • Christopher Clark (unregistered) in reply to sol
    sol:
    WTF does Assert do anyway? Really.

    Technically, since C doesn't have booleans, assert(false) makes monkeys fly out of your butt. Sideways.

    assert(0), on the other hand, prints a message to stderr (which this function doesn't do), and calls abort() to terminate without standard cleanup (which this code also doesn't do). Unless NDEBUG is defined at the moment <assert.h> is included, in which case nothing happens.

  • Elusive (unregistered)

    what good is assert? It's bloody usefull to have when working with non-programming staff, like say, artists.

    Telling an artist that "no, 36 is NOT a power of two, but 32 is" is just pointless, because they'll STILL make those textures in incorrect sizes. Put an assert on the build they use for testing thier art, or even on the conversion tools and they'll soon get the message.

    Making apps or tool-apps handle incorrect things like that by chopping of bits to the nearest ^2 just makes them lazy and they'll bitch and moan how the code screws thier work up. A controlled crash landing using a custom assert macro however, will make them fix it straight away, or atleast after they've run crying to your desk.

    The same thing goes for live game code...screw handling incorrect bone names gracefully. If the game has used a bone called "focus_point" for the last six months, I'm not bloody changing the code because of a typo or making the test build just focuson on the origin. Assert straight away, so they can fix thier own error...after coming to your desk demanding to know why you've broken thier art.

  • [ICR] (unregistered)

    Whats even more of a WTF is that in C# there is: Debug.Assert(expression); and in Java: assert expression; Or is it somehow different? Am I missing something?

  • Adrien "Krunch" Kunysz (unregistered) in reply to [ICR]

    The real WTF is that assert is used in that project too. TIMTOWTDI I guess.

  • (cs)

    Is the WTF supposed to be that he was so stubborn he refused to give up the assert method of dealing with errors? Because if so, he isn't the only one so stubborn. Java (as of 1.4 I believe) now supports asserts. Granted it doesn't perform a System.exit but instead throws an AssertionError, though than can be problematic when certain people write:

    try{
    ...
    }catch(Throwable e) {}
    

    And no, I didn't forget the ellipses in the catch block. I have seen that without anything in there (ok, maybe there was a comment or two).

  • Bigwig (unregistered)

    ROFL... One of the best WTFs ever!

  • (cs) in reply to Christopher Clark
    Christopher Clark:
    Technically, since C doesn't have booleans, assert(false) makes monkeys fly out of your butt. Sideways.

    Technically, C has booleans - they're called _Bool (also bool if you #include <stdbool.h>). And that same header includes macros for true and false. Section 7.16 of the current C standard.

  • DOA (unregistered) in reply to rycamor
    rycamor:
    An Ode to the Ay of Certain Developers:

    Forsooth! And how doth the keyboard clack As when, among twin perils of unnecessary loops and strange Inner Platforms, Bestride the angry waters of unfamiliar syntax and new paradigms Doth the Certain Developer lament: alas and alack! My brain hurteth so: ay ay ay This mountain, this Learning Curve, I durst not climb.

    But wherein his refuge? Of what dost thou speak?

    I speak of the inevitable temptation, to wit: As Alexander crossed the Hellespont, As Odysseus braved maelstrom, Verily as Hercules confronted the Hydra, So our hero confronts the Language Beast, And vanquishes the angry unknown, be it syntax or context, With an onslaught, truly a fusillade: the Wrapper of our Discontent, That the Language may, to his will be bent.

    I wish I has as much free time as you

  • Greg (unregistered) in reply to ThingGuy McGuyThing
    ThingGuy McGuyThing:
    swapo:
    An Ode! Aye Captain! Arrrr

    Worst. Haiku. Ever.

    Saw a great t-shirt this weekend:

    Haikus can be fun. Sometimes they do not make sense. Refridgerator.

  • (cs) in reply to Christopher Clark
    Christopher Clark:
    sol:
    WTF does Assert do anyway? Really.

    Technically, since C doesn't have booleans, assert(false) makes monkeys fly out of your butt. Sideways.

    int false = 1; assert(false);

    I see no problem.

    assert(0), on the other hand, prints a message to stderr (which this function doesn't do), and calls abort() to terminate without standard cleanup (which this code also doesn't do). Unless NDEBUG is defined at the moment <assert.h> is included, in which case nothing happens.

    actually, something happens - the token sequence ((void)0) is inserted into the code. Exactly that token sequence - it can't be ((void)(0)), ((void)1), or anything else that would be equivalent, it has to be exactly ((void)0).

  • sol (unregistered)

    I gues I am lucky or unfortunate because I never really got to do any real C programming or Java for that matter. So for just laughs we can say Assert is the flip side of On Error Resume Next even though it isn't actually in principal it something like that...

    typedef int BOOL;

    #define FALSE 0 #define TRUE 1 #define NULL 0 //OMG WTF 0 as in 0x0000

  • sol (unregistered)

    #define MAYBE -1

    yes it's now TriState lmao

  • (cs)
    a whole lot of “little things” change about how we write code
    Aw, what'dja correct it for? Now first-time readers are going to be going "WTF?" all the way down through the pun fun.
  • Scott (unregistered) in reply to Onaka The Kaka
    Onaka the Kaka:
    I wouldn't really call this a WTF, it's just an example of someone who doesn't understand Exceptions.
    Umm. I suspect you don't quite get the distinction between an assertion and an exception (as traditionally defined).

    An exception is used to detect and handle dynamic error conditions arising from the data or the environment - e.g. an over-length string, or running out of file space.

    An assertion is not supposed to be used for this: it's used to detect and abort if a condition occurs which can never happen if the logic of the program is correct - e.g. an array is passed as a parameter and its length appears to be negative. You can turn off assertions in a correctly written program, and the behaviour of the program will be completely unchanged - which is obviously not the case for exceptions. C exceptions are great: scatter them liberally to test the invariants and preconditions in your code, and a lot of bugs surface with very little effort. I generally try to make some sort of equivalent in languages which don't directly support assertions, and often bodging something up with an exception is the nearest you can get.

  • Christopher Clark (unregistered) in reply to Bellinghman
    Bellinghman:
    Christopher Clark:
    Technically, since C doesn't have booleans, assert(false) makes monkeys fly out of your butt. Sideways.

    Technically, C has booleans - they're called _Bool (also bool if you #include <stdbool.h>). And that same header includes macros for true and false. Section 7.16 of the current C standard.

    D'oh. My bad, been forced to use an out-of-date compiler for a while now, and apparently it's killing off sections of my brain.

  • Christopher Clark (unregistered) in reply to Random832
    Random832:
    Christopher Clark:
    Unless NDEBUG is defined at the moment <assert.h> is included, in which case nothing happens.

    actually, something happens - the token sequence ((void)0) is inserted into the code. Exactly that token sequence - it can't be ((void)(0)), ((void)1), or anything else that would be equivalent, it has to be exactly ((void)0).

    I was glossing. Yes, it sticks in something to make sure the compilation doesn't issue spurious warnings. At runtime, nothing happens.

  • Sharp (unregistered) in reply to Roman

    My eyes... the goggles do nothing!!!

Leave a comment on “It's Like Calling Assert”

Log In or post as a guest

Replying to comment #:

« Return to Article