• (cs) in reply to Mung Kee

    <font size="2">So they were implementing an accounting system (instead of buying one off the shelf or using an ASP) and in PHP?! And it took over a year?! And still didn't work?!

    WFT?! doesn't come close to describing my feelings...
    </font>

  • (cs) in reply to kipthegreat
    kipthegreat:
    Rank Amateur:

    Mung Kee:
    kipthegreat:

    <font size="2">function return_false()
    {
      return !return_true();
    }

    function return_true()
    {
      return !return_false();
    }</font>


    kipthegreat:

    Shouldn't dont_return be implemented like this:

    <font face="Courier New" size="2">function dont_return()
    {
    while (1 == 1);
    }</font>

    [late-night infomercial]
    Have you ever had the need for an infinite loop but couldn't find a developer who could really crash your runtime the way you want it crashed?  Well, you're in luck!  Kipthegreat is a "specialist" who can provide you with one, in any flavor of your choosing.  Just send $59.99 and a 3.5 floppy in a SASE to:
    Kip the Great
    c/o TheDailyWTF.com
    1000 W. Alameda Blvd.
    Burbank CA 91522

    Does Kipthegreat give seminars? I need to sign up.



    Absolutely.  The weekend of December 2-4, 8am-6pm (lunch not provided) at the Miami-Dade County YMCA!  Sign up now!


    On day 2 of the seminar I'll go over move advanced ifinite looping, utilizing the for-switch design pattern.  Can you spot the impossible cases in this code?  I bet your manager who pays you per KLOC can't.

    <font size="1">for (int i = 0; i < 10; i++)
    {
      switch (i)
      {
        case 0:
          i *= 1;
        case 1:
          i--;
          break;
        case 2:
          i = 7;
          break;
        default:
          i++;
          break;
      }
    }</font>

    MMM was ready to answer then I noticed the very nice use of fallthrough to actually use the default case.

    If I'm not mistaken, this code should switch forever between 0 and -1

  • (cs) in reply to John Smallberries
    John Smallberries:
    <font size="2">So they were implementing an accounting system (instead of buying one off the shelf or using an ASP) and in PHP?! And it took over a year?! And still didn't work?!

    WFT?! doesn't come close to describing my feelings...
    </font>



    No kidding, GL systems must be one of the most widely available to buy off the shelf.
  • (cs) in reply to masklinn
    masklinn:
    If I'm not mistaken, this code should switch forever between 0 and -1


    I'm afraid you're mistaken.  If I add a printf statement:

    <font size="1">for (int i = 0; i < 10; i++)
    {
    </font><font size="1">  printf("%d\n", i);</font><font size="1"> 
      switch (i)

      {
        case 0:
          i *= 1;
        case 1:
          i--;
          break;
        case 2:
          i = 7;
          break;
        default:
          i++;
          break;
      }
    }</font>

    then this will print
    0
    1
    1
    1
    1
    1
    ...
  • (cs) in reply to Konstantinos

    Anonymous:
    Sonic McTails:
    Wow, it's like the orginial programmer didn't know the concept of 'return' ... I'd love to see the code that calls it.

    I dissagree. It seems to me that he did know the concept of 'return' too well.
    I have an other theory about why this happened:

    1) We have to present something to the Boss
    2) The Boss doesnt know how to code/review.
    3) The Boss recognises comments and blank lines so we cannot use them to make our code bigger
    4) We get paid by the nr of lines in the code

    5) We appear on TDWTF
    6) Enjoy the glory

  • mikeb (unregistered) in reply to Boojum
    How about sizeof(empty_class) in C++ where class empty_class{}; then? Trying to explain the empty class optimization gets interesting.

    Stroustrup explains it here:

    http://www.research.att.com/~bs/bs_faq2.html#sizeof-empty

  • (cs) in reply to Satanicpuppy
    Satanicpuppy:
    In Java, this would be a perfectly normal set of methods to return data from a private object.


    No. Note that the methods all have parameters. They simply do nothing at all.
  • (cs) in reply to emptyset
    emptyset:

    <font face="Courier New" size="2">behold mortals!  maintable code!</font>



    Not spellainable, though.

  • (cs) in reply to Alexis de Torquemada
    Alexis de Torquemada:
    emptyset:

    <font face="Courier New" size="2">behold mortals!  maintable code!</font>



    Not spellainable, though.



    I'm sure that "main table code" has a deeper meaning that us mere mortals cannot fathom. Don't behave as if you've never dropped a space by accident.
  • (cs) in reply to Gene Wirchenko
    Gene Wirchenko:
    That is not as rare as you might think.  Have you ever seen
    <font size="2">     return(0);</font>
    ?  I have had people "explain" to me that the parens are needed when the return function is called.



    If they really want to call the "return" function, tell them to write a call wrapper in Assembler.

  • (cs) in reply to Maurits
    Maurits:
    Now explain why sizeof(void) == 1


    In C++, it's actually undefined.

  • (cs) in reply to Thomas
    Anonymous:
    Mauritz said:
    "Now explain why sizeof(void) == 1"

    Cause it ain't.

    To be serious, sizeof cannot be applied to an expression/type with a type that is incomplete. void is an incomplete type that cannot be completed. Since this is the case the compiler can do whatever it want really. sizeof(void) == 1 is one possiblity, compile error another. Runtime error is also allowed, but likely if the compiler is to be regarded as a serious product.

    I hate it when people bring fact into the discussion...


    A conforming C99 compiler (at least) is required to produce a diagnostic and the standard does not specify undefined behavior either explicitely or implicitely.

    IANALL (I am not a language lawyer.)

  • (cs) in reply to Thomas
    Anonymous:
    Thus the behaviour is undefined so a compiler can do anything really.


    No, it's not. "sizeof" not accepting incomplete types is an explicit constraint, which means that

    a) Violation must produce a diagnostic.
    b) Undefined behavior does not follow.

    (This post is C99-verified.)

  • (cs) in reply to Alexis de Torquemada
    Alexis de Torquemada:
    Maurits:
    Now explain why sizeof(void) == 1


    In C++, it's actually undefined.



    Same in C. It's actually just this question (well, a very similar one) that gave rise to the expression "nasal demons" - someone pointed out on a newsgroup that upon encountering sizeof() applied to an incomplete type, a C compiler is (implicitly) allowed by the standard to do absoluetely anything, including making demons fly out of your nose.
  • (cs) in reply to James Ingram
    Anonymous:


    Actually, Black Holes are the total presence of a bunch of really, really compacted matter which warps space with its gravity so much that light cannot escape.  They are there, they are very solid, and you really don't want to meet one in a dark alley after midnight (or at any time of day, come to think of it).


    By definition you will never meet a black hole at anytime other than midnight.   Though by the time you realize that the black hole is turning your local noon into midnight much faster than normal, it is too late to escape.
  • (cs) in reply to Maurits
    Maurits:
    masklinn:
    If I'm not mistaken, this code should switch forever between 0 and -1


    I'm afraid you're mistaken.  If I add a printf statement:

    <font size="1">for (int i = 0; i < 10; i++)
    {
    </font><font size="1">  printf("%d\n", i);</font><font size="1"> 
      switch (i)

      {
        case 0:
          i *= 1;
        case 1:
          i--;
          break;
        case 2:
          i = 7;
          break;
        default:
          i++;
          break;
      }
    }</font>

    then this will print
    0
    1
    1
    1
    1
    1
    ...


    Have you actually run this code?  For the code to run the way you say, you need a break for case 0.  As it is, here is a by-hand trace:

    loop control: i=0, termination?  not yet, so enter loop
    printf(): prints 0
    switch case 0: i=0 (0*1 equals 0)
    fall through to case 1: i decremented to -1
    loop control: i incremented to 0, termination? not yet, so loop continues
    Rinse, lather, repeat from printf() on..

    Sincerely,

    Gene Wirchenko

  • (cs) in reply to Gene Wirchenko
    Gene Wirchenko:

    Have you actually run this code?  For the code to run the way you say, you need a break for case 0.  As it is, here is a by-hand trace:

    loop control: i=0, termination?  not yet, so enter loop
    printf(): prints 0
    switch case 0: i=0 (0*1 equals 0)
    fall through to case 1: i decremented to -1
    loop control: i incremented to 0, termination? not yet, so loop continues
    Rinse, lather, repeat from printf() on..


    Oops... I missed the lack of a break; statement after case 0.  You're absolutely right.

    If I add another printf() statement after the switch, the output will indeed be

    0
    -1
    0
    -1
    0
    -1
    ...

  • (cs) in reply to Maurits
    Maurits:
    Gene Wirchenko:

    Have you actually run this code?  For the code to run the way you say, you need a break for case 0.  As it is, here is a by-hand trace:

    loop control: i=0, termination?  not yet, so enter loop
    printf(): prints 0
    switch case 0: i=0 (0*1 equals 0)
    fall through to case 1: i decremented to -1
    loop control: i incremented to 0, termination? not yet, so loop continues
    Rinse, lather, repeat from printf() on..


    Oops... I missed the lack of a break; statement after case 0.  You're absolutely right.

    If I add another printf() statement after the switch, the output will indeed be

    0
    -1
    0
    -1
    0
    -1
    ...



    Do you feel bad about implying someone else was a dumbass when, in fact, you were the dumbass?

    Sincerely,

    Richard Nixon
  • (cs) in reply to Richard Nixon
    Richard Nixon:
    Do you feel bad about implying someone else was a dumbass when, in fact, you were the dumbass?


    Not particularly... missing the lack of a break; statement is a common error...
  • (cs) in reply to Maurits
    Maurits:
    Richard Nixon:
    Do you feel bad about implying someone else was a dumbass when, in fact, you were the dumbass?


    Not particularly... missing the lack of a break; statement is a common error...


    And not particularly, since you only suggested the person was mistaken.  That is no implication of something worse, just a polite statement.  Mine was the same, especially since I was not 100% sure, only ninety-something.

    break in switch is one of the things that I very much dislike about C.

    Sincerely,

    Gene Wirchenko

  • Keith Smith (unregistered)

    Blizzard's World of Warcraft code has this function in it:

    function TEXT(string text)
    {
      <FONT size=+0>return</FONT> text;
    }

     

  • bcat (unregistered) in reply to ferrengi

    It's written in PHP.

Leave a comment on “Doing What You Say, Saying What You Do”

Log In or post as a guest

Replying to comment #:

« Return to Article