• T1TAN (unregistered)
    Alex Papadimoulis:

    He had a very deep belief that exception handling was evil and that all methods should instead return a boolean value indicating success or failure.



    Errr..this is actually true, exception handling is evil, slow down the execution drastically. I tend to avoid try-catch blocks whenever I can and use my own logic with ifs and return values.

  • (cs) in reply to T1TAN
    Anonymous:
    Alex Papadimoulis:

    He had a very deep belief that exception handling was evil and that all methods should instead return a boolean value indicating success or failure.



    Errr..this is actually true, exception handling is evil, slow down the execution drastically. I tend to avoid try-catch blocks whenever I can and use my own logic with ifs and return values.


    I look forward to seeing your code on this site.

  • (cs) in reply to T1TAN
    Anonymous:
    Alex Papadimoulis:

    He had a very deep belief that exception handling was evil and that all methods should instead return a boolean value indicating success or failure.



    Errr..this is actually true, exception handling is evil, slow down the execution drastically. I tend to avoid try-catch blocks whenever I can and use my own logic with ifs and return values.

    This makes you a blight on our profession.

  • (cs) in reply to dubwai
    dubwai:
    Anonymous:
    Alex Papadimoulis:

    He had a very deep belief that exception handling was evil and that all methods should instead return a boolean value indicating success or failure.



    Errr..this is actually true, exception handling is evil, slow down the execution drastically. I tend to avoid try-catch blocks whenever I can and use my own logic with ifs and return values.

    This makes you a blight on our profession.

    please, you must submit some code.  I just have to see this.

  • (cs) in reply to ammoQ

    What is this "spreadsheet" you speak of?

  • (cs) in reply to tSQL
    tSQL:
    dubwai:
    Anonymous:
    Alex Papadimoulis:

    He had a very deep belief that exception handling was evil and that all methods should instead return a boolean value indicating success or failure.



    Errr..this is actually true, exception handling is evil, slow down the execution drastically. I tend to avoid try-catch blocks whenever I can and use my own logic with ifs and return values.

    This makes you a blight on our profession.

    please, you must submit some code.  I just have to see this.

    Me, or exceptionless-boy?

  • (cs) in reply to dubwai
    dubwai:
    tSQL:
    dubwai:
    Anonymous:
    Alex Papadimoulis:

    He had a very deep belief that exception handling was evil and that all methods should instead return a boolean value indicating success or failure.



    Errr..this is actually true, exception handling is evil, slow down the execution drastically. I tend to avoid try-catch blocks whenever I can and use my own logic with ifs and return values.

    This makes you a blight on our profession.

    please, you must submit some code.  I just have to see this.

    Me, or exceptionless-boy?

    that would be 'exceptionless-boy'. 

  • (cs) in reply to tSQL
    dubwai:
    This makes you a blight on our profession.

    tSQL:
    please, you must submit some code.  I just have to see this.

    dubwai:
    Me, or exceptionless-boy?

    tSQL:
    that would be 'exceptionless-boy'. 

    Don't worry; I'm sure someone will be posting it right here sometime soon.
  • (cs) in reply to Mike R
    Mike R:

    Methinks Jed needed to lay off the cough syrup a bit.

     

    He needs to lay off a lot more than just cough syrup! [:|]

  • T1TAN (unregistered) in reply to tSQL
    tSQL:
    please, you must submit some code.  I just have to see this.


    Err, what, you've never seen a piece of code that looks like this:

    if ( pSomePointer == NULL )
        return FALSE;

    ??

    Or would you all rather prefer

    try
    {
        pSomePointer->DoSomething();
    }
    catch
    {
        return FALSE;
    }

    ?? This makes me say WTF??

    Besides, go to my site and download KT and try to crash it if you can. And good luck.. :-\
  • (cs) in reply to T1TAN

    Anonymous:
    tSQL:
    please, you must submit some code.  I just have to see this.


    Err, what, you've never seen a piece of code that looks like this:

    if ( pSomePointer == NULL )
        return FALSE;

    ??

    Great, so your code doesn't differentiate between error states and normal return codes.  I'm sure that's useful.

    Anonymous:

    Or would you all rather prefer

    try
    {
        pSomePointer->DoSomething();
    }
    catch
    {
        return FALSE;
    }

    ?? This makes me say WTF?

    If this is how you think exceptions are supposed to be used, it's no wonder you are so confused.

    Anonymous:

    Besides, go to my site and download KT and try to crash it if you can. And good luck.. :-\

    What site?

  • (cs) in reply to T1TAN
    Anonymous:

    Err, what, you've never seen a piece of code that looks like this:

    if ( pSomePointer == NULL )
        return FALSE;

    ??

    Or would you all rather prefer

    try
    {
        pSomePointer->DoSomething();
    }
    catch
    {
        return FALSE;
    }

    ?? This makes me say WTF??


    You don't seem to have understood the point. Your code is pretty pointless either way, but what we would like to see is more like this:

    if ( pSomePointer == null )
        throw new IllegalArgumentException("Paramterer XY must not be null.");

    However, it depends on what the method does. If all it does is check the parameters for validity and return true or false, then that's OK, although in that case you'd probably want more information about which parameter was invalid in what way. On the other hand, if the method is supposed to DO something with the parameters and can't do that right if the parameter is null, then a return code is bad style, because people tend to call the methode and expect it to work without checking the return value. For a more in-depth explanation, look here.


  • T1TAN (unregistered) in reply to dubwai
    dubwai:

    If this is how you think exceptions are supposed to be used, it's no wonder you are so confused.

    Anonymous:

    Besides, go to my site and download KT and try to crash it if you can. And good luck.. :-\

    What site?



    That was just a stupid example for the love of everything. My site is http://sprdsoft.cmar-net.org , program is Kewl Tool..

    Look guys, I'm just saying that it's easier to check for errors with some custom error checking system rather than using try-catch block which DO slow down the execution. However, I still use standard exception handling when I need to.

    This is my article on codeproject.com and this is the coding style I use nearly always, using both my exception handling logic and built in..

    http://www.codeproject.com/internet/siv_version.asp

    And why the hell do you attack me without asking any further details about my statement??
  • (cs) in reply to T1TAN

    TITAN:

    And why the hell do you attack me without asking any further details about my statement??

    You must be new here.  All we do is attack attack ATTACK!

  • (cs) in reply to T1TAN

    Anonymous:


    Look guys, I'm just saying that it's easier to check for errors with some custom error checking system rather than using try-catch block which DO slow down the execution. However, I still use standard exception handling when I need to.

    Depends on what you think is easier:  putting a switch statement after every method call to test for every possible error code imaginable (and still miss some) or put in a try - catch in a few strategic locations and catch every error.

    I'm not sure about C++ but in Java, try - catch blocks do not slow down execution in an appreciable way.  It's only when they are thrown that they have any cost.  In some languages like Python, the cost of exceptions is built into every method call whether you use a try catch or not.

    I work with code written by people who apparently thought exceptions were just a pain in the ass.  So when something goes wrong, it doesn't error out, it inserts bad data into the DB and executes in other indeterminite ways.  This costs a lot, and not nano-seconds.  tens and even hundreds of thousands of dollars can be lost.

  • T1TAN (unregistered) in reply to dubwai
    dubwai:

    Depends on what you think is easier:  putting a switch statement after every method call to test for every possible error code imaginable (and still miss some) or put in a try - catch in a few strategic locations and catch every error.



    attack! LOL :D

    Anyways, I agree, it all depends on the situation, but for example, the project I'm on at my job is completely jammed with try-catch blocks (in C#), our web app is so damn slow because of it, since postback occurs every once in a while and a billion of exceptions get thrown out of space.. Sadly, I was one year too late to stop that 'tradition'..

    My co-workers tend to write code like this:

    try
    {
        m_someVar = ViewState["something"].ToString();
    }
    catch
    {
        m_someVar = "whatever";
    }

    which is quite dumb if you ask me, I prefer

    if ( ViewState["something"] != null )
        m_someVar = ViewState["something"].ToString();
    else
        m_someVar = "whatever";

    so I ask you, if you run this code for ten thousand times, which one will be faster?? :)
  • (cs) in reply to T1TAN

    Anonymous:


    My co-workers tend to write code like this:

    try
    {
        m_someVar = ViewState["something"].ToString();
    }
    catch
    {
        m_someVar = "whatever";
    }

    which is quite dumb if you ask me, I prefer

    if ( ViewState["something"] != null )
        m_someVar = ViewState["something"].ToString();
    else
        m_someVar = "whatever";

    so I ask you, if you run this code for ten thousand times, which one will be faster?? :)

    This is a complete misuse of exceptions IMO.  And not only is it slower, it's completely silly.  There are cases where there's no better alternative and some Python types argue it's an acceptable pattern.  There's a thread all about this subject called 'Array of Hope'.

  • (cs) in reply to T1TAN
    Anonymous:

    if ( ViewState["something"] != null )
        m_someVar = ViewState["something"].ToString();
    else
        m_someVar = "whatever";

    so I ask you, if you run this code for ten thousand times, which one will be faster?? :)


    Hmmm... I'd prefer
    string vs(string strKey, string strDefault) {
        return ViewState[strKey] == null ? strDefault : ViewState[strKey].ToString();
    }

    m_someVar = vs("something", "whatever"); // ah, my aching fingers
  • (cs) in reply to T1TAN

    Anonymous:

    Besides, go to my site and download KT and try to crash it if you can. And good luck.. :-\

    <FONT face="Courier New" size=2>bwah ha ha.  it's actually easier to make a non-crashing program than you think.  for example, i just told my
    turing machine to read characters until the end of the tape.</FONT>

    <FONT face="Courier New" size=2>h4x0rv("LOL i p4553d it teh INF tape!??!?") ;</FONT>

    <FONT face="Courier New" size=2>i ran it a mobius tape, and although it is stuck in an infinite loop, the turing machine is not allocating any resources so it's crash free.</FONT>

    Anonymous:

    That was just a stupid example for the love of everything. My site is http://sprdsoft.cmar-net.org , program is Kewl Tool..

    <FONT face="Courier New" size=2>totally radical, dude!  keanu reeves in "my own private system monitor"</FONT>

     

  • (cs) in reply to T1TAN
    Anonymous:
    dubwai:

    If this is how you think exceptions are supposed to be used, it's no wonder you are so confused.

    Anonymous:

    Besides, go to my site and download KT and try to crash it if you can. And good luck.. :-\

    What site?



    That was just a stupid example for the love of everything. My site is http://sprdsoft.cmar-net.org , program is Kewl Tool..

    Look guys, I'm just saying that it's easier to check for errors with some custom error checking system rather than using try-catch block which DO slow down the execution. However, I still use standard exception handling when I need to.

    This is my article on codeproject.com and this is the coding style I use nearly always, using both my exception handling logic and built in..

    http://www.codeproject.com/internet/siv_version.asp

    And why the hell do you attack me without asking any further details about my statement??


    "Kewl tool" huh? People using "kewl" is a WTF in itself.
  • (cs) in reply to T1TAN

    Anonymous:

    attack! LOL :D

    <FONT face="Courier New" size=2>my suspicions are confirmed.</FONT>

    Anonymous:

    My co-workers tend to write code like this:
    <snip>
    so I ask you, if you run this code for ten thousand times, which one will be faster?? :)

    <FONT face="Courier New" size=2>while i sympathize with your situation, what you're reasoning is the equivalent of strapping hedgehogs to your forearms prior to entering the thunderdome.</FONT>

  • (cs) in reply to T1TAN

    so I ask you, if you run this code for ten thousand times, which one will be faster?? :)

    That's irrelevant. The first is a horrible abuse of exceptions. But it has NOTHING to do with exceptions vs. return codes. You seem to have been traumatized by exceptions misused for control flow and come to the totally wrong conclusion that they should not be used at all. The great thing about exceptions is that, when used correctly, they make the code so much more readable because you can handle the exceptions for large blocks of code with several possibly exception-throwing statements in one place at the end of the code block rather than mixing it with the code. Better yet, you can handle the exceptions several levels upwards in the method call stack.

    As a rule of thumb, exceptions should NOT be used for a case that is expected, for something that happens in a particular place and needs a particular reaction specific to that. Exceptions are good for more general things like "if anything goes wrong while reading or parsing the input file, show error message XYZ and return to main screen".

  • programmer from india (unregistered) in reply to Jake Heidt

    what do you mean he should be exported to india? we dont need stupid programmers in india...stupid american programmers should stay in stupid america.

  • SlideGuitar (unregistered) in reply to Apu

    Apu, we don't expect him to work there! We expect him to be a beggar.

  • SlideGuitar (unregistered) in reply to dubwai

    "I'm not sure about C++ but in Java, try - catch blocks do not slow down execution in an appreciable way.  It's only when they are thrown that they have any cost." I am sure about C++; when you can still turn exception handling, you will see performance decreases from turning it on (cf. Scott Meyers, Lippman). But almost anyone says he needs the performance boost he gets from avoiding exceptions is probably lying.

  • T1TAN (unregistered) in reply to emptyset
    emptyset:

    <font face="Courier New" size="2">bwah ha ha.  it's actually easier to make a non-crashing program than you think.  for example, i just told my
    turing machine to read characters until the end of the tape.</font>

    <font face="Courier New" size="2">h4x0rv("LOL i p4553d it teh INF tape!??!?") ;</font>

    <font face="Courier New" size="2">i ran it a mobius tape, and although it is stuck in an infinite loop, the turing machine is not allocating any resources so it's crash free.
    </font>

    <font face="Courier New" size="2">


    <font size="3">what's your point?? did ANYONE get this??</font></font>

    besides, if it's easier to make a non-crashing program, maybe you should tell that to microsoft heh..

    emptyset:

    <font face="Courier New" size="2">totally radical, dude!  keanu reeves in "my own private system monitor"</font>


    ??

  • T1TAN (unregistered) in reply to brazzy
    brazzy:

    The great thing about exceptions is that, when used correctly, they make the code so much more readable because you can handle the exceptions for large blocks of code with several possibly exception-throwing statements in one place at the end of the code block rather than mixing it with the code. Better yet, you can handle the exceptions several levels upwards in the method call stack.

    As a rule of thumb, exceptions should NOT be used for a case that is expected, for something that happens in a particular place and needs a particular reaction specific to that. Exceptions are good for more general things like "if anything goes wrong while reading or parsing the input file, show error message XYZ and return to main screen".



    Agreed, I never claimed anything of this to be false, but I still believe that exception handling is over-used, well, at least where I live :-) Sorry for the misunderstanding IF all of you thought that I think exception handling is evil incarnation and should never be used, because that's not what I meant to say..
  • (cs) in reply to SlideGuitar

    Anonymous:
    But almost anyone says he needs the performance boost he gets from avoiding exceptions is probably lying.

    Or a satanist.

  • (cs) in reply to T1TAN

    Anonymous:
    <FONT face="Courier New" size=2>
    <FONT size=3>what's your point?? did ANYONE get this??</FONT></FONT>

    <FONT face="Courier New" size=2><FONT size=3>besides, if it's easier to make a non-crashing program, maybe you should tell that to microsoft heh..</FONT></FONT>

    ??

    <FONT face="Courier New" size=2>0. it's become clear you should keep your knowledge of programming under a fig leaf.  otherwise, you'll have to be cast into the accumulator, squashed by 0x01, the loneliest integer.</FONT>

    <FONT face="Courier New" size=2>1. is this 1995?  are you listening to green day?  do you read slashdot?  have you installed slackware?  do you like the font "Comic Sans"?</FONT>

    <FONT face="Courier New" size=2>2. do us all a favor and get back to shooting at the walls of heartbreak, bang bang.</FONT>

  • T1TAN (unregistered) in reply to emptyset
    emptyset:

    <font face="Courier New" size="2">0. it's become clear you should keep your knowledge of programming under a fig leaf.</font>



    Same as you, my dear friend, should hide your brains, for they obviously match those of George W. Bush, a conclusion I am foced to make due to the fact that you haven't laid down a single proof of your argument and just kept insulting with things irrelevant for this discussion. Good luck with the real life.
  • Poster+4toPost (unregistered) in reply to Gene Wirchenko

    Aw c'mon, it's obvious he was burnt out and bored! I found it pretty silly myself, a good laugh [H]

  • Michael (unregistered) in reply to Jake Heidt

    What's wrong with India?

  • (cs) in reply to T1TAN

    Anonymous:
    Same as you, my dear friend, should hide your brains, for they obviously match those of George W. Bush, a conclusion I am foced to make due to the fact that you haven't laid down a single proof of your argument and just kept insulting with things irrelevant for this discussion. Good luck with the real life.

    <FONT face="Courier New" size=2>what argument?  the hell are you talking about?  </FONT>

  • Markus Venter (unregistered)

    if not (JED read Delphi online help on good programming practices) then

      JED can't code

    else

      JED still can't code!

    JED - GO SELL LIFE INSURANCE!  Your bull.... will fool someone!

  • brill (unregistered) in reply to Jed
    Anonymous:

    upcomming jed methods...

    MostlyTrue
    AreMostlyEqual

    and for those who still get confused by the concept of negating a value

    NotTrue
    NotEqual
    MainlyFalse




    Jed, Dude!
    You forgot:
    - MightBeTrue
    - GuessIfItsTrue
  • (cs) in reply to T1TAN
    Anonymous:

    [snip turing machine]

    <font face="Courier New" size="2"> <font size="3">what's your point?? did ANYONE get this??


    </font></font>

    <font face="Courier New" size="2"><font size="3">I did.  I suggest you read a book about computation and automata?  Sipser's Introduction to the Theory of Computation is a good read.
    I reckon NP-completeness will also not ring a bell?
    </font></font>

    besides, if it's easier to make a non-crashing program, maybe you should tell that to microsoft heh..


    How much of a Unix guy I am I must honestly say that Windows XP is hardly giving me problems at all.  In over 2 years I have not encountered a single blue screen.  The only software that has been breaking on me was third party software.
    Microsoft bashing, how lovely it might seem to people, is getting old if it is not based on facts.
  • (cs) in reply to tSQL
    tSQL:
    GOTO code is not cool, ...


    Sorry, but this is a generalisation.

    Goto does have its functions (ever tried writing compilers/parsers where skipping to a label in the same function makes a lot of sense?), but the way how it is handled is what determines if it is evil or well-used.

    The same can be said for 80% or so of the C++ code out there in the wild.  A lot of people that have no clue whatsoever how to properly use I/O streams or templates.

    Don't blame the language or its functionality for the programmer's malpractice.

    The good programmers, at least in my opinion, are the ones that adapt to the situation and not the ones that believe everything is cast in stone and should remain like that forever.
  • qiguai (unregistered) in reply to joost
    joost:
    ammoQ:
    SomeObject string2someObject(String s) {
      SomeObject so = new SomeObject();
    StringBreaker sts = new StringBreaker(s);
    so.someField = sts.getString(3);
    so.anotherField = sts.getInteger(4);
    ...
    return so;
    }
    But that's still 155 lines of code.


    I'm too lazy to spell it all out right now, but using a couple of lists and some introspection, you can do:

    import java.lang.reflect;

    const int FT_INT = 1, FT_STR = 2;
    String[] fieldNames = { 'someField', 'anotherField' };
    int[] fieldTypes = { FT_STR, FT_INT };
    int[] fieldOffsets = { 3, 4 };

    SomeObject string2SomeObject(String s) {
      SomeObject so = new SomeObject();
      StringBreaker sts = new StringBreaker(s);
      Field f = so.getField(fieldNames[i]);
      switch(fieldTypes[i]): {
        case FT_INT:
          Field f = so.getField(fieldNames[i]);
          f.setInt(sts.getInteger(fieldOffsets[i]));
          break;
        ....
      }
      return so;
    }

    This is probably what the other guy meant with 'use a schema'. If you don't like the parallel arrays (error-prone), curse Java for not having Tuples and create a light-weight class that has one string and two ints as public fields, and make sure you give it a short name:

    FieldInfo[] fieldInfo = {
      new FieldInfo('someField', FT_INT, 3),
      new FieldInfo('anotherField', FT_STR, 4)
    }

    This reduces 155 lines of code to ~20 lines of code 155 lines of data. They taught me it's better to have smart data structures and stupid code than to have stupid data structures and smart code.


    Yes- and this could be generalized to a small framework so that doing this for various objects didn't require a class for each one. I'd be inclined to pull the offset/field name data out into a separate file, in an actual implementation.  Data driven programming is often a big win- it's unfortunate that few mainstream languages offer good facilities for data driven code. It's nice that Java has added reflection, but I still find it quite painful for things like this. A good macro system, and/or convenient closures (inner classes fail the convenience part) and higher order functions would make things a lot easier. Limited expressiveness seems to have been one of Java's original design goals though, and reading the code on this site makes me understand that approach.

    The longer I program, the more I rely on "comfort level" as a guide(I guess this is similar to what XP people mean by "Code Smells"). Long  functions make me uncomfortable. So does mechanical repetition of the same construct. When my level of discomfort reaches a certain point, I stop and look for a more comfortable approach- which generally means some sort of abstraction  (after all, the only problem that can't be solved by another layer of abstraction is too many layers of abstraction).
  • (cs) in reply to christoofar

    christoofar:
    Typically, the design pattern a lot of procedural programmers get themselves into when working in an OO language is a lightweight set of classes with one giant God object that does most of the work... and boy is it a pain to fix. :-(

     

    I am soooo busted [:'(]

    I do try to prevent myself from falling into this trap, but sometimes I have the equivalent of a little bitty script thing I need to write, and if I end up doing it in C# it's just not cool what I end up doing.

    /duck

  • (cs)

    Happy Jed day everyone!

    Jed, you are an artist.

  • Michael Edenfield (unregistered) in reply to Oliver Klozoff
    Oliver Klozoff:

    From memories that are now many many years old, I can recall the following built-in functions in Pascal. Determine their worth for yourself.

    {...}
    Succ(x) - Returns x + 1
    Pred(x) - Returns x - 1



    This is a slightly inaccurate definition of those two functions.  They return the previous and next values for any ordinal type; e.g., Succ('a') is 'b'.  They also work for enumerations and sets, if I remember my Delphi correctly.  This is important because Pascal is very strongly typed, so you can't just add 1 to a char as you can in C.

    There are also Inc(x) and Dec(x) methods that add and subtract in-place, which works on all ordinal types as well as pointers.

    --Kutulu

  • nobody (unregistered) in reply to RyGuy
    RyGuy:

    My favorite line:


     // set up a simple 'boolean fall-through grid', there should be 2^2 [4] possible outcomes
      // because there are two states being compared (true and false) for each of the
      // two expressions (expression1 and expression2), I've numbered them for easy counting.

    4 possible outcomes?!??!  Good thing he numbered them.  I would have lost track had he not!

    He was probably explaining it to himself.

  • (cs)
    Alex Papadimoulis:

    A little while back, David Knaack wrote in to tell me about August 29th, a day revered by him and his colleagues. August 29th is, after all Jed Day: the anniversary of Jed's 'de-hiring' date. David explains why they consider this such a celebratory event ...


    <FONT face=Tahoma>AAAAAHHHH!!! now I'll forever be tormented every 29th of August...

    I should not have ventured further by knowing what is Jed day...



    </FONT>

  • kraghavk (unregistered) in reply to Jake Heidt
    Anonymous:
    WTF is with these asshats programmers and their IsTrue, IsEqual, what moron would USE these, let alone WRITE them.

    People like JED should be exported to india.


    I'm sure you are a ******** who's never even dealt with an indian before...

    moderator' note: censored
  • S. (unregistered)

    This thread, I guess, shows why if someone makes a joke on a forum full of programmers like Slashdot, there's always someone who takes you seriously.

    About the only WTF here is "Why was he slacking off making jokes". It's obvious from the comments, the code, and everything else that these were deliberately written to be funny, not to be serious implementations of anything necessary. Why was he fired? Probably because he spent too much time on this kind of thing and not enough time on actual programming.

    And what's with the criticism of his opinions on exceptions? Are gotos - which is what thrown exceptions are a form of and as such is a cause for debate - suddenly non-controvertial? I don't know many programmers that don't at least have misgivings about the technology, even if they, personally, like them. If he was in an environment in which exceptions are the convention and kept refusing to throw them, then that's one thing, but if this is the case, why not mention that?

    He looks to me like a talented, if opinionated, programmer, who choose to incorporate his fun in his work rather than browse the web all day.

  • (cs) in reply to S.

    Anonymous:
    He looks to me like a talented, if opinionated, programmer, who choose to incorporate his fun in his work rather than browse the web all day.

    And finally here's Jed himself...

     

    Anonymous:
    And what's with the criticism of his opinions on exceptions? Are gotos - which is what thrown exceptions are a form of and as such is a cause for debate - suddenly non-controvertial?

    Yeah, a form... in this vein what about loops? Did you ever ask yourself why do we ever need loops (for, while etc)? Completely unnecessary, aren't they? For example:

    for(int i=0; i<10; i++) {
       bla bla bla
    }

    is about the same as :

    int i=0;
    loop_begin:
    if (i>=10) goto loop_end;
    bla bla bla
    i++;
    goto loop_begin;
    loop_end:

    <sarcasm>It makes it really clear what you are trying to do isn't it?</sarcasm>

  • (cs) in reply to brazzy

    brazzy:
    Anonymous:

    Err, what, you've never seen a piece of code that looks like this:

    if ( pSomePointer == NULL )
        return FALSE;

    ??

    Or would you all rather prefer

    try
    {
        pSomePointer->DoSomething();
    }
    catch
    {
        return FALSE;
    }

    ?? This makes me say WTF??


    You don't seem to have understood the point. Your code is pretty pointless either way, but what we would like to see is more like this:

    if ( pSomePointer == null )
        throw new IllegalArgumentException("Paramterer XY must not be null.");

    However, it depends on what the method does. If all it does is check the parameters for validity and return true or false, then that's OK, although in that case you'd probably want more information about which parameter was invalid in what way. On the other hand, if the method is supposed to DO something with the parameters and can't do that right if the parameter is null, then a return code is bad style, because people tend to call the methode and expect it to work without checking the return value. For a more in-depth explanation, look here.


    I call bullshit here. Not just on you, brazzy, but all the other would be idiots who have posted similar "avoiding exceptions is always bad" type bollocks.

    The example you replied to may have to run a thousand times on a gui application in a single hypothetical thread. The try/catch example is going to slow the program down to a crawl and seriously effect the user experience/client satisfaction. Your solution is going to be eveny slower, and what, pop up a thousand error messages? You take the first, more efficient code, and then throw a useless bloody exception to be caught and dealt with somewhere else. See, it all comes down to the context. Do you want users of your UI to have to click "Okay" on a thousand "Error: Paramterer XY must not be null" dialogs?

    There are times when we need to do a lot of work very quickly with a lot of possibilities. We don't know for sure what is set, and we don't care. We want to do what we can on as many as possible quickly.

    Remember when you're having your little prick compare fest, that an exception is a tool that was created for a purpose and while it is extremely useful,  it is not the only way to deal with the unexpected, nor is it always the best way.

    Remember also that mine will always be bigger.

    BTW, regarding the OP, this guy is great! Obviously some CS grads reading his code had too much sense of humour squeezed out of them in the sausage machine. I'd give him a job for sure, might need a bit of micro management, but he can't be as bad as most CS grads, they actually believe it's a science. I reckon he could write an OS to rival Vista!

    Long live JED!

  • (cs) in reply to Mung Kee

    // need to set the result if it hasn't been set yet, we'll randomly decide true or false
    // because there should be no bias.

    Clever thinking. Scattering this value is useless as long as the code
    actually works as intended (ie the value is then set correctly), but causes havoc
    (Schrodinger's Cat havoc) when there is a minor bug. So what we have is a "bug-enhancer".

    Hm... now it works? Now it doesn't?

  • celeriac (unregistered) in reply to joost
    joost:

    FieldInfo[] fieldInfo = {

    new FieldInfo('someField', FT_INT, 3),

    new FieldInfo('anotherField', FT_STR, 4)

    }

    For more flexibility you can build a string scanning API. For example you can make a nice set of string scanning classes with a flexible API like the following:

    StringScanner theScanner = new StringScanner();
    ObjectInitializer object = new ReflectiveBeanPropInitializer(SomeClass.CLASS);
    BeanPropertyAssignment someFieldAssignment = new BeanPropertyIntegerAssignment('someField');
    object.addField(someFieldAssignment);
    IntegerConversion ic = new IntegerConversion();
    ic.setConversionBehavior(ScanConversion.FIXED_WIDTH);
    ic.setConversionLength(3);
    ic.setTarget(someFieldAssignment);
    StringConversion sc = new StringConversion();
    sc.setConversionBehavior(ScanConversion.FIXED_WIDTH);
    sc.setConversionLength(4);
    BeanPropertyAssignment anotherFieldAssignment = new eanPropertyStringAssignment('anotherField');
    sc.setTarget(anotherFieldAssignment);
    object.addField(anotherFieldAssignment);
    

    Then parsing the entire string is just a simple matter of

    try {
        SomeClass obj = (SomeClass)theScanner.scan(s);
    } catch (Exception e) {
         throw new IOException('String format problem');
    }
    

    The really neat thing is that if you do it this way the whole StringScanner construct is itself just a static data structure. You can tell it to store itself in an XML configuration file and load it on the fly when you need to parse your string; ; the stringScanner initialization code you see above will be handled transparently by an XML object persistence library.. So it's just a few lines of code to do all the scanning and the string format is flexibly configurable.

    (captcha is 'sscanf')

  • CK (unregistered) in reply to Maurits
    Maurits:
    Alex Papadimoulis:
    there should be 2^2 [4] possible outcomes
    Glad he included the "4".  Here I was thinking that 2^2 == 0.
    If ^ is XOR, then 2^2 == 0

Leave a comment on “Happy (Belated) Jed Day!”

Log In or post as a guest

Replying to comment #:

« Return to Article