• K2C (unregistered)

    why didn't he just use a database? everyone knows databases are more efficient then excel...

  • Joel (unregistered)

    The real WTF is definitely forgetting about the panendermic semiboloid. That's inconceivable. INCONVEIVABLE!

  • IV (unregistered)

    Simply returning the input - 273 would not give an out of range error. Obviously that would not be a correct solution. the programmer knew what (s)he was doing.

    BTW, why have no comment on the comic been photographed on a wooden table? I keep scrolling through, but apparently no one knows the proper way of creating an image for a website.

    Captcha: dignissim.

  • (cs) in reply to Joel
    Joel:
    The real WTF is definitely forgetting about the panendermic semiboloid. That's inconceivable. INCONVEIVABLE!

    You keep using that word. I do not think it means what you think it means.

  • Vollhorst (unregistered)

    Shoudln't worky anyway since he uses = instead of == for comparisons.

  • (cs)

    trwtf is that they didn't just replace the entire system with one or two lunar wainshafts and a differential girdle spring.

  • Dembinjo (unregistered) in reply to CRNewsom

    Nobody noticed

    if (Ktemp= 273 )

    what about == ?

  • SysKoll (unregistered)

    The use of a spreadsheet is a sure sign of a sick mind.

    The "programmer" obviously used the spreadsheet to auto-generate a bunch of lines, probably using some clever formula. This means that the idiot was clever enough to know Excel macros, but too dumb to understand the concept of a temperature difference.

    The guy should be banned from touching a compiler.

  • t (unregistered)

    It's worth pointing out, for those who didn't realize it, that finding the difference between two temperatures in Celsius yields the exact same result as taking the difference of the temperatures in Kelvin.

    So in those precious few occurrences, the function calls had no effect on the value of the expression.

  • Ken B (unregistered) in reply to K2C
    K2C:
    fist.. and why didn't he just use a database? everyone knows databases are more efficient then excel...
    Of course...
        select C from KtoC where K = %1
    Just remember to wrap it in a COM object and give it an "enterprise" interface.
  • (cs) in reply to Dembinjo
    Dembinjo:
    Nobody noticed

    if (Ktemp= 273 )

    what about == ?

    I guess all the temperature differentials were exactly zero. Not very useful I imagine.

  • (cs)

    but then the delta is the difference in Celsius! surely you need a K2C function to handle that! //see comment.xls

  • (cs)

    Clearly, he should have rerouted the tachyon beam through the forward deflector, remodulated the forward phaser bank, and ordered number one to take a number two.

  • (cs)

    Lots of issues here besides the = vs. == thing.

    -- the returns aren't followed by a semicolon. Won't compile. -- if the temperature is out of range, it simply printf()s a message (also without semicolon) without returning a value. Won't compile. -- extra } at the end. Won't compile.

    Oh, and "Ktemp int" vs. "int Ktemp". Won't compile.

  • shash (unregistered)

    Looking at that last else, it shouldn't even compile. Not all code paths return a value...

    Besides, there's a braces mismatch in the last line. The real WTF is someone who put non-compiling code into the source...

  • (cs)

    The other WTFery aside, you don't need formulas to do that easily in Excel. You can just type in the first number (in B1, for instance), type in the second number (B2), select the two cells, then click-and-drag the little dot in the bottom-right corner there as far as you want and it'll fill in the column with the sequence (273, 274, 275... 303)

  • (cs) in reply to gabba
    gabba:
    -- if the temperature is out of range, it simply printf()s a message (also without semicolon) without returning a value. Won't compile.
    Not true in C.
  • (cs) in reply to Vollhorst
    Vollhorst:
    Shoudln't worky anyway since he uses = instead of == for comparisons.

    Its also missing semi-colons. Maybe its a 'C' like language, or probably an obfuscation issue.

  • (cs) in reply to fennec
    fennec:
    The other WTFery aside, you don't need formulas to do that easily in Excel. You can just type in the first number (in B1, for instance), type in the second number (B2), select the two cells, then click-and-drag the little dot in the bottom-right corner there as far as you want and it'll fill in the column with the sequence (273, 274, 275... 303)

    Thanks for mentioning that. It's not rocket science.

  • (cs)

    The Real WTF is that he never found out what was actually causing the problem. A bit of a tease, this one.

  • (cs)

    he probably used excel to type in a number value in a cell and then drag the small dot in the bottom-right of the cell downwards and microsoft fills the cells incrementing the number. In cases it's not a number, it just repeats that data through the cell. that's why maybe he typed the numeral values in different cells and just dragged the whole thing down.

    neways.. this is one awesome WTF

    @DeLos: Since the Celsius-Kelvin are difference scales and not factor scales, the delta is same in both Celsius and Kelvin.

  • whicker (unregistered)

    maybe, just maybe, i would like to think that the excel table was meant to be an interpolation table to account for non-linear sensors.

    however, as interpolation like that is extremely non-trivial, I wouldn't doubt that the original programmer got hung up on it and just threw something together.

  • (cs)
    $ gcc k2c.c -c -o k2c.o
    k2c.c:1: error: expected ‘)’ before ‘int’
    k2c.c:36: error: expected identifier or ‘(’ before ‘}’ token
    
    <fix argument and extra curly brace>
    
    $ gcc k2c.c -c -o k2c.o
    k2c.c: In function ‘K2C’:
    k2c.c:4: error: expected ‘;’ before ‘}’ token
    k2c.c:5: error: expected ‘;’ before ‘}’ token
    ...
    k2c.c:33: error: expected ‘;’ before ‘}’ token
    k2c.c:34: error: expected ‘;’ before ‘}’ token
    k2c.c:35: warning: incompatible implicit declaration of built-in function ‘printf’
    k2c.c:35: error: expected ‘;’ before ‘}’ token
    
    <add semicolons>
    
    $ gcc -Wall k2c.c -c -o k2c.o
    k2c.c: In function ‘K2C’:
    k2c.c:4: warning: suggest parentheses around assignment used as truth value
    k2c.c:5: warning: suggest parentheses around assignment used as truth value
    k2c.c:6: warning: suggest parentheses around assignment used as truth value
    ...
    k2c.c:35: warning: implicit declaration of function ‘printf’
    k2c.c:35: warning: incompatible implicit declaration of built-in function ‘printf’
    
    <change '=' to '=='>
    
    $ gcc -Wall k2c.c -c -o k2c.o
    k2c.c: In function ‘K2C’:
    k2c.c:35: warning: implicit declaration of function ‘printf’
    k2c.c:35: warning: incompatible implicit declaration of built-in function ‘printf’
    k2c.c:36: warning: control reaches end of non-void function
    

    There are plenty of problems besides not returning a value. GCC only gives a warning, and even then, only if you ask for warnings.

  • (cs) in reply to CRNewsom
    CRNewsom:
    Joel:
    The real WTF is definitely forgetting about the panendermic semiboloid. That's inconceivable. INCONVEIVABLE!

    You keep using that word. I do not think it means what you think it means.

    It's not even spelled the way he thinks it's spelled--at least not when in ALL CAPS.

  • Paul (unregistered)

    Did anyone else notice the problem between the code:

    if(Ktemp=	273	){return	0	}
    else if(Ktemp=	274	){return	1	}
    else if(Ktemp=	275	){return	2	}
    else if(Ktemp=	276	){return	3	}
    

    and the comment that it could be replaced by:

    "return Ktemp-270;",

    Returns a completely different value 273-270=3, not zero!

  • Dmitri (unregistered) in reply to t
    t:
    So in those precious few occurrences, the function calls had no effect on the value of the expression.
    Unless the temperature happens to be outside of the 273...303 K ;).
  • Anirudh (unregistered)

    how would the code work if the code should be Ktemp==273

    while if he uses Ktemp=273, it'll just assign the rhs value to the lhs and the program won't work.

  • Whoops (unregistered) in reply to Anirudh
    Anirudh:
    how would the code work if the code should be Ktemp==273

    while if he uses Ktemp=273, it'll just assign the rhs value to the lhs and the program won't work.

    This reminds me of a very funny joke:

    /* world's last mistake in C */ if(code = CODE_RED) { launch_missles(); }

  • whicker (unregistered) in reply to Anirudh
    Anirudh:
    how would the code work if the code should be Ktemp==273

    while if he uses Ktemp=273, it'll just assign the rhs value to the lhs and the program won't work.

    yes, it will, if you invert the phase polarity.

  • Pyro (unregistered)

    The sudden influx of technobabble concentration causes fluctuation of the distortion field, and we may have to remodulate the confinement of the problematic plasma flow to prevent its further deterioration.

  • Kinglink (unregistered)

    They might not have hand typed the xls file. In excel there's a way to fill a row down and have it auto increment each row.

    Another possibility I've done/seen is to make a formula, implement it, once you have the correct data, copy the entire book, then paste special it as "just values" this way no one can muck up your data.

    Just because the final output doesn't have the formulas doesn't mean he didn't use some of the easier tools in Excel, otherwise he likely would have created these files in C++/other language.

  • (cs) in reply to jspenguin
    jspenguin:

    $ gcc -Wall k2c.c -c -o k2c.o k2c.c: In function ‘K2C’: k2c.c:35: warning: implicit declaration of function ‘printf’ k2c.c:35: warning: incompatible implicit declaration of built-in function ‘printf’ k2c.c:36: warning: control reaches end of non-void function

    There are plenty of problems besides not returning a value. GCC only gives a warning, and even then, only if you ask for warnings.

    Well, no shit, sherlock. It's a standalone function, not a complete program. There obviously won't be any #includes.

  • Jesper (unregistered) in reply to Paul
    Paul:
    Did anyone else notice the problem between the code:
    if(Ktemp=	273	){return	0	}
    else if(Ktemp=	274	){return	1	}
    else if(Ktemp=	275	){return	2	}
    else if(Ktemp=	276	){return	3	}
    

    and the comment that it could be replaced by:

    "return Ktemp-270;",

    Returns a completely different value 273-270=3, not zero!

    So... Did you notice that the original code always returns 0? Can you see why? (Hint: Look at some of the other posts above).

  • IV (unregistered)

    I can't believe I forgot to put this in my last post. The code could be made so much more efficient via use of the switch. Maybe that is the point in the article we have all been missing.

    captcha: quibus

  • Carra (unregistered)

    The real wtf is obviously using

    C = k - 273

    Should be

    C= k - 273.15

  • Paul (unregistered) in reply to Jesper

    Yeah, to quote another post here "No shit, sherlock!" Did you not see the other posts that said it might be an in-house C like language, or a mistype in copying the code.

  • Christian (unregistered) in reply to Whoops
    Whoops:
    This reminds me of a very funny joke:

    /* world's last mistake in C */ if(code = CODE_RED) { launch_missles(); }

    const int CODE_RED = 0; /* saved the world */
  • Chris E (unregistered) in reply to Christian

    Nope, missiles still got launched. World saving attempt FAILED.

  • Chris E (unregistered) in reply to Chris E

    (but you are lucky that he is only launching 'missles', whatever they are, not 'missiles')

  • Carra (unregistered) in reply to Christian
    Christian:
    Whoops:
    This reminds me of a very funny joke:

    /* world's last mistake in C */ if(code = CODE_RED) { launch_missles(); }

    const int CODE_RED = 0; /* saved the world */

    That will just put code to 0 and fire them anyway.

  • (cs) in reply to Christian

    The real WTF is that he realized that not only is that function a complete mess, but it's totally unnecessary and he should have removed it. Every codebase has crappy code, but if you just leave it lying around without doing anything about it you're only adding to the problem. The correct solution is:

    1. Delete that function.
    2. Change the few occurrences so that it just uses difference in Kelvin temps.
    3. Make sure the Johnson rod is functioning correctly.
  • Patrick (unregistered)

    Does that even compile? I thought the return statements had to have a semicolon...

  • Zygo (unregistered) in reply to Whoops
    Whoops:
    Anirudh:
    how would the code work if the code should be Ktemp==273

    while if he uses Ktemp=273, it'll just assign the rhs value to the lhs and the program won't work.

    This reminds me of a very funny joke:

    /* world's last mistake in C */ if(code = CODE_RED) { launch_missles(); }

    #define CODE_RED 0 /* Do. Not. Ever. Change. This. */
    #define CODE_ORANGE 1
    #define CODE_YELLOW 2
    #define CODE_GREEN 3
    #define CODE_BLUE 4
    #define CODE_BLACK 5
    #define CODE_FILE_NOT_FOUND -1
    

    World's safe...for now. ;-)

  • Zygo (unregistered) in reply to shash
    shash:
    Looking at that last else, it shouldn't even compile. Not all code paths return a value...

    Functions are not required to return a value in C (or, for that matter, C++). A C programmer would know that.

    Of course the value returned by such a function is undefined (usually whatever's lying around in the appropriate register):

    $ cat /tmp/t.c 
    #include <stdio.h>
    
    int foo() {
            puts("Hello, World!");
    }
    
    
    int main(int argc, char **argv) {
            printf("%d\n", foo());
    }
    $ make t
    cc     t.c   -o t
    $ ./t
    Hello, World!
    14
    $ echo $?
    3
    
  • Zygo (unregistered) in reply to Zygo
    Zygo:
    Whoops:
    Anirudh:
    how would the code work if the code should be Ktemp==273

    while if he uses Ktemp=273, it'll just assign the rhs value to the lhs and the program won't work.

    This reminds me of a very funny joke:

    /* world's last mistake in C */ if(code = CODE_RED) { launch_missles(); }

    #define CODE_RED 0 /* Do. Not. Ever. Change. This. */
    

    World's safe...for now. ;-)

    ...until some smartass maintainer "fixes" the "bug" in the 'if' statement, and checks in without testing.

  • notJoeKing (unregistered) in reply to Jesper
    Jesper:
    Paul:
    Did anyone else notice the problem between the code:
    if(Ktemp=	273	){return	0	}
    else if(Ktemp=	274	){return	1	}
    else if(Ktemp=	275	){return	2	}
    else if(Ktemp=	276	){return	3	}
    

    and the comment that it could be replaced by:

    "return Ktemp-270;",

    Returns a completely different value 273-270=3, not zero!

    So... Did you notice that the original code always returns 0? Can you see why? (Hint: Look at some of the other posts above).

    Regardless of the code always returning 0, the suggestion in the article that the entire method could be replaced by "return Ktemp-270;" is incorrect. It should be: "return Ktemp-273;" and that is what the original poster is pointing out.

  • Joshua Norman (unregistered) in reply to Zygo
    Zygo:
    Whoops:
    Anirudh:
    how would the code work if the code should be Ktemp==273

    while if he uses Ktemp=273, it'll just assign the rhs value to the lhs and the program won't work.

    This reminds me of a very funny joke:

    /* world's last mistake in C */ if(code = CODE_RED) { launch_missles(); }

    #define CODE_RED 0 /* Do. Not. Ever. Change. This. */
    #define CODE_ORANGE 1
    #define CODE_YELLOW 2
    #define CODE_GREEN 3
    #define CODE_BLUE 4
    #define CODE_BLACK 5
    #define CODE_FILE_NOT_FOUND -1
    

    World's safe...for now. ;-)

    That comment of yours might actually be counterproductive :O

    To quote Pratchett, "Of course someone would be that stupid. Some humans would do anything to see if it was possible to do it. If you put a large switch in some cave somewhere with a sign on it saying "End-of-the-World Switch. PLEASE DO NOT TOUCH," the paint wouldn't even have time to dry."

  • (cs) in reply to Outlaw Programmer

    [obligatory]

    Outlaw Programmer:
    The real WTF is that he realized that not only is that function a complete mess, but it's totally unnecessary and he should have removed it. Every codebase has crappy code, but if you just leave it lying around without doing anything about it you're only adding to the problem. The correct solution is:

    1. Delete that function.
    2. Change the few occurrences so that it just uses difference in Kelvin temps.
    3. Make sure the Johnson rod is functioning correctly.
    • ?????
    • Profit! [/obligatory]
  • Medinoc (unregistered)

    I call reasonable doubt on the "all typed by hand" of the Excel file. The programmer could very well have used the type-and-drag feature of Excel (type number, select cell, drag down, ????, profit!)...

  • Shinobu (unregistered) in reply to Chris E
    Chris E:
    Nope, missiles still got launched. World saving attempt FAILED.
    You fail at programming. The value of an assignment is the assigned value, in this case 0. if() interprets that as false and doesn't execute it's code block:
    Christian:
    Whoops:
    This reminds me of a very funny joke:

    /* world's last mistake in C */ if(code = CODE_RED) { launch_missles(); }

    const int CODE_RED = 0; /* saved the world */
    if(code = CODE_RED) { launch_missles(); }

    if(code = 0) { launch_missles(); }

    if(0) { launch_missles(); }

    ; //Notice how nothing happens

Leave a comment on “K2C”

Log In or post as a guest

Replying to comment #:

« Return to Article