Comment On K2C

Anton N is not a programmer by trade. Whenever he comes across “questionable” code in his job as an engineer, he always gives the programmer the benefit of the doubt: it might just have to be that complicated to work; maybe he did it to work around some system limitation; or perhaps it’s some optimized routine. It’s only fair. Certainly, he wouldn't want some programmer critiquing his decision to use the modial interaction of magneto-reluctance (rather than a more efficient method, such as capacitive directance) for supplying inverse reactive current in a unilateral phase detractor. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Re: K2C

2008-02-27 10:04 • by K2C (unregistered)
why didn't he just use a database? everyone knows databases are more efficient then excel...

Re: K2C

2008-02-27 10:05 • by Joel (unregistered)
The real WTF is definitely forgetting about the panendermic semiboloid. That's inconceivable. INCONVEIVABLE!

Re: K2C

2008-02-27 10:12 • by 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.

Re: K2C

2008-02-27 10:12 • by CRNewsom
179429 in reply to 179422
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.

Re: K2C

2008-02-27 10:13 • by Vollhorst (unregistered)
Shoudln't worky anyway since he uses = instead of == for comparisons.

Re: K2C

2008-02-27 10:14 • by SeekerDarksteel
trwtf is that they didn't just replace the entire system with one or two lunar wainshafts and a differential girdle spring.

Re: K2C

2008-02-27 10:14 • by Dembinjo (unregistered)
179433 in reply to 179429
Nobody noticed

if (Ktemp= 273 )

what about == ?

Re: K2C

2008-02-27 10:17 • by 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.

Re: K2C

2008-02-27 10:17 • by 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.

Re: K2C

2008-02-27 10:17 • by Ken B (unregistered)
179438 in reply to 179421
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.

Re: K2C

2008-02-27 10:17 • by dextron
179439 in reply to 179433
Dembinjo:
Nobody noticed

if (Ktemp= 273 )

what about == ?



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

Re: K2C

2008-02-27 10:18 • by DeLos
but then the delta is the difference in Celsius!
surely you need a K2C function to handle that!
//see comment.xls

Re: K2C

2008-02-27 10:23 • by operagost
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.

Re: K2C

2008-02-27 10:24 • by gabba
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.

Re: K2C

2008-02-27 10:26 • by 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...

Re: K2C

2008-02-27 10:26 • by 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)

Re: K2C

2008-02-27 10:28 • by lgrave
179449 in reply to 179445
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.

Re: K2C

2008-02-27 10:31 • by Rick
179452 in reply to 179430
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.

Re: K2C

2008-02-27 10:33 • by zip
179455 in reply to 179447
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.

Re: K2C

2008-02-27 10:35 • by Zylon
The Real WTF is that he never found out what was actually causing the problem. A bit of a tease, this one.

Re: K2C

2008-02-27 10:36 • by rohanprabhu
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.

Re: K2C

2008-02-27 10:40 • by 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.

Re: K2C

2008-02-27 10:40 • by jspenguin

$ 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.

Re: K2C

2008-02-27 10:43 • by mrprogguy
179465 in reply to 179429
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.

Re: K2C

2008-02-27 10:43 • by 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!

Re: K2C

2008-02-27 10:43 • by Dmitri (unregistered)
179467 in reply to 179437
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 ;).

Re: K2C

2008-02-27 10:45 • by 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.

Re: K2C

2008-02-27 10:49 • by Whoops (unregistered)
179473 in reply to 179469
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();
}

Re: K2C

2008-02-27 10:49 • by whicker (unregistered)
179474 in reply to 179469
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.

Re: K2C

2008-02-27 10:52 • by 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.

Re: K2C

2008-02-27 10:52 • by 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.

Re: K2C

2008-02-27 10:54 • by shadowman
179477 in reply to 179464
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.

Re: K2C

2008-02-27 10:58 • by Jesper (unregistered)
179481 in reply to 179466
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).

Re: K2C

2008-02-27 11:00 • by 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

Re: K2C

2008-02-27 11:01 • by Carra (unregistered)
The real wtf is obviously using

C = k - 273

Should be

C= k - 273.15

Re: K2C

2008-02-27 11:02 • by Paul (unregistered)
179485 in reply to 179481
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.

Re: K2C

2008-02-27 11:02 • by Christian (unregistered)
179486 in reply to 179473
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 */

Re: K2C

2008-02-27 11:10 • by Chris E (unregistered)
179489 in reply to 179486
Nope, missiles still got launched. World saving attempt FAILED.

Re: K2C

2008-02-27 11:12 • by Chris E (unregistered)
179490 in reply to 179489
(but you are lucky that he is only launching 'missles', whatever they are, not 'missiles')

Re: K2C

2008-02-27 11:12 • by Carra (unregistered)
179491 in reply to 179486
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.

Re: K2C

2008-02-27 11:13 • by Outlaw Programmer
179493 in reply to 179486
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.

Re: K2C

2008-02-27 11:13 • by Patrick (unregistered)
Does that even compile? I thought the return statements had to have a semicolon...

Re: K2C

2008-02-27 11:18 • by Zygo (unregistered)
179502 in reply to 179473
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. ;-)

Re: K2C

2008-02-27 11:19 • by Zygo (unregistered)
179503 in reply to 179446
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

Re: K2C

2008-02-27 11:20 • by Zygo (unregistered)
179504 in reply to 179502
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.

Re: K2C

2008-02-27 11:21 • by notJoeKing (unregistered)
179505 in reply to 179481
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.

Re: K2C

2008-02-27 11:26 • by Joshua Norman (unregistered)
179506 in reply to 179502
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."

Re: K2C

2008-02-27 11:32 • by elias
179509 in reply to 179493
[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.

4) ?????
5) Profit!
[/obligatory]

Re: K2C

2008-02-27 11:33 • by 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!)...

Re: K2C

2008-02-27 11:33 • by Shinobu (unregistered)
179511 in reply to 179489
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
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Add Comment