• Zatanix (unregistered) in reply to Maurits

    LOL! Cool function!

  • (cs) in reply to Zatanix

    Its true, the kid who wrote this graduated in the same class as me, we both got our BS. Its totally insane how many people get a BS in CS at my school who have no idea how to write code in java, or c, or both. This kid was one of those people.

    For one of our classes our junior year we were asked to write a program that would, given a String polynomial parse that, and stick the values into a double array. The class was titled "Empirical methods in computer science". A week after the deadline of this project, the professor made a nice little excel table detailing the class performance. If i remember correctly, 55% of the people passed in code that DIDNT COMPILE. 25% had code that compiled but they didn’t pass 1/2 the test cases. only about 5 people wrote programs that actually worked. I was the only one to use regular expressions.

    On the other hand, if these are the people who are going to be competing for jobs with me... i should have no problem finding work.

  • Ben (unregistered) in reply to petvirus

    There is no bool, if you look closely you can see its not the bool that is true, it is you who is false :s

  • Anonymouse (unregistered)

    A few years agon, I worked with this PhD who was all up-in-arms about qsort and how it had some worst-case behavior so he wrote his own insertion sort, but that's another story.

    I came across this wonder in a Whole Pile of his code:

    <FONT face="Courier New" size=1>#define TRUE (1==1)</FONT>

    <FONT face="Courier New" size=1>#define FALSE (!TRUE)</FONT>

    <FONT face="Courier New" size=1>#define FlagOn(b,f)   (((b)&(f))!=0?TRUE:FALSE)</FONT>

    This fellow left the company after a while and went back to teaching Software Engineering at a local institution...

  • (cs) in reply to Anonymouse

    This reminds me of one I caught in a code review a few months ago...no joke...

    if(someObject.someBooleanProperty.ToString() == "true")

  • (cs) in reply to Anonymouse
    Anonymous:

    A few years agon, I worked with this PhD who was all up-in-arms about qsort and how it had some worst-case behavior so he wrote his own insertion sort, but that's another story.

    <snip></snip>

    <font face="Courier New" size="1">#define FlagOn(b,f)   (((b)&(f))!=0?TRUE:FALSE)</font>


    I have seen similar code in xBASE.  For some reason, many people can not get their heads around boolean.  The xBASE equivalent is:
    if iif(x>y,.t.,.f.)

    The iif() function evaluates the first (boolean) expression.  If true, it returns the second expression, otherwise the third.  (.t. is true and .f. is false.)  The example is much better stated:

    if x>y

    Sincerely,

    Gene Wirchenko

  • (cs) in reply to petvirus
    petvirus:
    Its true, the kid who wrote this graduated in the same class as me, we both got our BS. Its totally insane how many people get a BS in CS at my school who have no idea how to write code in java, or c, or both. This kid was one of those people. For one of our classes our junior year we were asked to write a program that would, given a String polynomial parse that, and stick the values into a double array. The class was titled "Empirical methods in computer science". A week after the deadline of this project, the professor made a nice little excel table detailing the class performance. If i remember correctly, 55% of the people passed in code that DIDNT COMPILE. 25% had code that compiled but they didn’t pass 1/2 the test cases. only about 5 people wrote programs that actually worked. I was the only one to use regular expressions. On the other hand, if these are the people who are going to be competing for jobs with me... i should have no problem finding work.


    In what reality do you live where job acquisition is based on merit?  ;)
  • MeLLeR (unregistered)

    It looks perfect! I'm going to rewrite all my applications :)



    (just kidding of course :P)

  • (cs) in reply to Eric
    Eric:

    This reminds me of one I caught in a code review a few months ago...no joke...

    if(someObject.someBooleanProperty.ToString() == "true")



    What language is this written in?  And is it comparing references or values?  The reason I ask is, in Java, even if someBooleanProperty was true, this would result in false, because references are compared.  Could potentially be more of a WTF than it initally appeared.
  • DeMoN (unregistered)

    hmmm ... and whats about a True Detector?

    could be something like :

    <FONT style="BACKGROUND-COLOR: #ffffff"><FONT color=#0000ff><FONT size=+0>public boolean</FONT> checkTrue(<FONT size=+0>Boolean</FONT> bool)
    {
       return !</FONT></FONT><FONT style="BACKGROUND-COLOR: #ffffff"><FONT color=#0000ff>checkFalse(bool);
    }</FONT></FONT>

    or even better ...

    <FONT color=#0000ff><FONT size=+0>public boolean</FONT> checkTrue(<FONT size=+0>Boolean</FONT> bool)
    {
       return </FONT><FONT color=#0000ff>checkFalse(checkFalse(bool));
    }</FONT>

    hmmmm ... is this correct???  hmmm ... have to think about it ... *hrhrhr*

  • Jack (unregistered) in reply to dhromed

    I would do something along the lines of:

    <font size="3">if (foo == ""          //if foo is empty,
        || foo == 0        //zero,
        || foo == null     //null,
        || foo == false) { //or false
      [do stuff]
    }

    if it were really that difficult to figure out.
    </font>

  • (cs) in reply to Matt

    No one asked for a solution.......chop!

  • soundman32 (unregistered) in reply to johnl
    johnl:

    this is bad , but not as bad as the

     #define INTEGER_VALUE_ONE 1

    one that there was a while back.



    We have

    #define MINUS_ONE -1

    in our flagship product :-)
  • (cs)

    When I was a TA for a programming course at my university, we had to deal with another variation of this frequently in the first couple of projects.

    The course uses the SML language, which enforces strict type safety rules. Many students found these rules... unnerving, and would over-engineer large swaths of code in an attempt to "step around" the type-safety issues.

    It got so bad that we had to start docking points on projects every time we saw code like this:

    let result = if a then true else false

    Note that because of the type-safety rules of the language, a is always guaranteed to be type bool...

  • (cs) in reply to soundman32
    Anonymous:
    johnl:

    this is bad , but not as bad as the

     #define INTEGER_VALUE_ONE 1

    one that there was a while back.



    We have

    #define MINUS_ONE -1

    in our flagship product :-)


    System.Decimal.MinusOne

  • patson (unregistered) in reply to soundman32

    You work for Microsoft, then, I take it?

  • G Bickham (unregistered)

    "Let him who is without sin cast the first stone ..."

    I don't see anything wrong with this (if it works) ... Sure, this developer could have easily done a google search to find a better approach.But would that have made him/her a better developer.  What I see from this code is someone who was thinking outside of the box.  Which is a good sign that this person will eventually mature into solid developer.

    I think the bad developers are those who COPY code without even taking the time to understand why it works ...  

    If we all just think back to when we were writing our first apps then we would better appreciate code like this.  I wonder how many of those apps are still in production and are still being used?

  • Anonymouse2 (unregistered) in reply to G Bickham
    Anonymous:
    "Let him who is without sin cast the first stone ..."

    I don't see anything wrong with this (if it works) ... Sure, this developer could have easily done a google search to find a better approach.But would that have made him/her a better developer.  What I see from this code is someone who was thinking outside of the box.  Which is a good sign that this person will eventually mature into solid developer.

    I think the bad developers are those who COPY code without even taking the time to understand why it works ...  

    If we all just think back to when we were writing our first apps then we would better appreciate code like this.  I wonder how many of those apps are still in production and are still being used?

    I take it you are the original developer.

    Seriously, the guy knew about the Boolean.booleanValue() method and yet rewrote it, including the usage of several calls to it. That is simply inexcusable and by no means a sign of a 'good thinker'. A 'good thinker' would be a guy who looked at his tools and used them.

    Further, anyone who praises code for 'thinking outside the box' probably shouldn't be allowed near a computer.
  • Hello_There (unregistered)

    This function is debug residue. They just forgot to delete it. My guess is it had something to do with an array, which in itself was built for debugging (probably an array that was a member function of another).  We all leave debug residue from time to time, but usually the compiler is in your face about it. However, with it being in production i would assume it was in a sea of code to be overlooked to make it into production. This isn't much of a WTF to me. i've seen func(){return;} plenty of times in others code (but then again it is in beta stage, not in production).

    <font color="Red">
    </font>

  • Suomynona (unregistered) in reply to DeMoN
    Anonymous:

    hmmmm ... is this correct???  hmmm ... have to think about it ... *hrhrhr*



    How about the following solution?


    public boolean checkTrue(Boolean bool)
    {
        return checkFalse(new Boolean(checkFalse(bool)));
    }
    <font size="+0"></font>
    public boolean checkFalse(Boolean bool)
    {
        try
        {
            return !checkTrue(bool);
        }
        catch (StackOverflowError e)
        {
           return new Boolean(Boolean.FALSE.toString()).booleanValue();
        }
    }

  • whatsinaname (unregistered) in reply to Mung Kee

    I think this comment is almost as "Out-of-the-place" (couldn't be any more decent!) as the code itself.
    What does it mean ?

  • (cs)

    Saw the following at my place..... (c++)

    string FromBool(const bool x) {
        if (true == x) {
           return "true";
        } else if (false == x) {
           return "false";
        } else {
           throw InvalidDataException();
        }
    }

    Well, it's certainly belt and braces.....

  • (cs) in reply to leibnitz27
    leibnitz27:
    Saw the following at my place..... (c++)

    string FromBool(const bool x) {
    ...
           return "true";

    ...
           return "false";
    }

    Well, it's certainly belt and braces.....


    Wot, no localization options? :)
        if (lang == "es")
        {
             return x ? "es verdad" : "no es verdad";
        }
  • Jesper (unregistered) in reply to johnl

    I was in a project once, writing C code, where the client insisted on having a #define for EVERY constant in the program. You weren't allowed to use literal numbers or strings anywhere.

    So on April 1st my colleagues and I announced that we had made a header file to make life easier, and that we had already searched and replaced all the source code of the whole project to use the new header file.

    I couldn't believe they fell for it and almost paniced when they saw the header file:

    #define ONE 1
    #define TWO 2
    #define THREE 3
    ...
    #define ONEHUNDREDANDTWENTYFOUR 124
    ...
    (up to 1000)

  • superz (unregistered)

    That is ridiculous

  • (cs) in reply to Andrew
    Anonymous:

    Anonymous:
    I think Java encourages bad programming practices. I'm finding it harder and harder to hire qualified folks who were raised on it.

     

    No, its not that.  CS programs have dumbed down.  Eight years ago, I asked a professor, "When is this going to get hard," in reference to CS202 and CS203.  The answer was that they had started making it intentionally easier so less people would drop out.  The attrition rate from CS201 to CS203 was about 80%.  Because its either Java or VB in most CS programs now, you're seeing a lot of people who would have been weeded out get degrees instead.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    <FONT face="Courier New" size=2>back in my college days, i used to meet a lot of gentlefolk who were out to get their cs degrees so they could afford to live in california and persue acting as a career.</FONT>

    <FONT face="Courier New" size=2>"cs is just to pay the bills - it's not what i really want to do.  i want to act!"</FONT>

  • anonymous coward (unregistered) in reply to Jesper

    > I was in a project once, writing C code, where the client insisted on having a
    > #define for EVERY constant in the program. You weren't allowed to use literal
    > numbers or strings anywhere.

    > So on April 1st my colleagues and I announced that we had made a header file to
    > make life easier, and that we had already searched and replaced all the source
    > code of the whole project to use the new header file.

    > I couldn't believe they fell for it and almost paniced when they saw the header file:

    > #define ONE 1
    > #define TWO 2
    > #define THREE 3
    > ...
    > #define ONEHUNDREDANDTWENTYFOUR 124
    > ...
    > (up to 1000)


    Funny. To be fair, I think what the person intended with the rule "no numbers" was to avoid magical number in the middle of the code. Then having a
    #define MAX_USERS 163 /* some reason why it's 163 */
    if (n > MAX_USERS) panic();
    is somewhat better than a strange out of the blue
    if (n > 163) panic();
    especially if 163 is all over the place.

    I take it you did not actually type the 1000 lines; how did you generate this joke file? I have an idea (hash of number and names (1-one, 2-two, ...., 70-seventy, 80-eghty, 90-ninety) I think after 100 it's just a matter of reusing the names available)... but maybe you came up with something clever.

  • MMe (unregistered) in reply to Maurits

    naaaaaa me don't belive possible this oink?

  • (cs) in reply to anonymous coward
    Anonymous:

    is somewhat better than a strange out of the blue
    if (n > 163) panic();
    especially if 163 is all over the place.

    I take it you did not actually type the 1000 lines; how did you generate this joke file?


    Re: 163... of course

    if (n > ONEHUNDREDSIXTYTHREE) panic();
    is so much more alarming :)

    Re: generating joke file
    There is, of course, a Perl module for this
    http://search.cpan.org/author/LHOWARD/Number-Spell-0.04/Spell.pm


  • ac (unregistered) in reply to Maurits

    well, if you name your var ONESIXTYTHREE it's stupid. now if you give it a meaningful name, then it's better; see the 163 vs. ONESIXTYTHREE vs. MAX_USERS: wich one carries the most useful information?

  • ac (unregistered) in reply to Maurits

    > There is, of course, a Perl module for this
    > http://search.cpan.org/author/LHOWARD/Number-Spell-0.04/Spell.pm

    what was I thinking, there's a Perl module for everything! Thanks for the info, I'll have a look at how it's done, I'm sure it's an interesting read.

  • (cs) in reply to Mung Kee
    Mung Kee:
    Eric:

    This reminds me of one I caught in a code review a few months ago...no joke...

    if(someObject.someBooleanProperty.ToString() == "true")



    What language is this written in?  And is it comparing references or values?  The reason I ask is, in Java, even if someBooleanProperty was true, this would result in false, because references are compared.  Could potentially be more of a WTF than it initally appeared.

    It's C#.  Not comparing references, but actually, that would return false because I forgot to capitalize the T in True.

  • (cs) in reply to ac

    Anonymous:
    well, if you name your var ONESIXTYTHREE it's stupid. now if you give it a meaningful name, then it's better; see the 163 vs. ONESIXTYTHREE vs. MAX_USERS: wich one carries the most useful information?

    I see the joke detector has been disabled.

     

Leave a comment on “A False Detector”

Log In or post as a guest

Replying to comment #:

« Return to Article