My sincerest apologies!

Perhaps the real WTF is blogs where you can't edit your posts to correct glaring errors.

Yes, = is the mathematical equality operator, but it is also used to "fix" variables to certain values, which is quite similar to assignment in C (though more similar to assignment in functional programming languages)

But it is not really used to fix or assign in mathematics, it is more used as an observation. Mathematics is not a programming language after all. It usually goes more like

if x=5 and y=10 then xy = 510 = 50. The mathematic is timeless and in this example, x will always be 5 but a program runs through steps and x may be changed at any time.

I think my old Casio calculator had it more correct. Assignment was represented by little arrows to represent putting the value into the variable.

Rich

• (cs) in reply to HardCoder
Anonymous:

This is by far not clever enough. Take this:

b = (b == b ? true : false) ;

Remember, C is about doing things you can't do in Basic.

That doesn't match the semantics of the original. What if b is NOT equal to b, what then? The code given leaves it unchanged; yours sets it to false. better would be 'b = (b == b ? true : b);'

• Marc (unregistered) in reply to Rich

> No, it used the assignment (=) and not the comparison (==)

No, it says "end if" afterwards. It's not C or C++ or C# or Java or PHP or Perl, but BASIC in which the comparison operator is actually = rather than ==.

• (cs) in reply to EvanED
EvanED:
b = (b == b ? true : b);
{ b = (b == b) || break }

I can't remember if you're allowed to use break inside expressions in C, nor if plain braces are break()ed to. So, safe version ("({...})" is a GCC extension, IIRC, allowing statements inside an expression):

b = (b == b) || ({goto OR_NOT}) }; OR_NOT: (void)NULL;

blah... this is so much nicer in perl. I've even done something similar a few times:

"ERROR: { die problem1() ? "error 1" : problem2() ? "error 2" : ... : last ERROR }
• (cs)
Jake Vinson:

P. C. apparently inherited code originally written by an evil genius from deep inside his volcano headquarters.

@{\$gst}{keys %{\$rec}} = values %{\$rec};  # muhahahaha

Oh, I've written uglier lines than that!

2.upto(Integer(sqrt(n)) + 1) { |i| p = p.delete_if { |j| i != j && j % i == 0 } }

word.gsub(/[^\w]/, '').each_byte { |b| accum *= @@code_map[b.chr] }

• Twm (unregistered)

long live the codesmorgasboard.

I like this one;

#define SIZE_2048 2048

It reminds me of a code review I once did. the code review policy at our company stated that "thou shall not use magic numbers in code. They are unreadable to new eyes and hinder maintenance"

So after pointing out a few of them

init_interupt(\$A355, \$B643)

I had to smile when getting the code back to review a second time:

const uint C_A355 = \$A355
const uint C_B643 = \$B643

init_interupt(C_A355, C_B643) <--- there, much more readable

• (cs)

1000 GOTO 1002
1001 GOTO 1010
1002 GOTO 1001

This is not three lefts, its three wrongs.

• Reinder (unregistered)
if b = b then
b = true
end if
In a dynamically-typed language where '=' is not assignment in an if statement, this could be a useful body of "bool isValidNumber( b)" (for any NaN n, we have !(n==n)).
#define SIZE_2048 2048
struct disk_request (
...
BYTE buffer[SIZE_2048];  /* data buffer 1024 bytes long */
};
This could be correct on a 4-bit system with a non-standard C compiler where chars are 4 bits :-)

• Zygo (unregistered) in reply to Megalomaniacs4u
Irrelevant:
Alex:
@{\$gst}{keys %{\$rec}} = values %{\$rec}; # muhahahaha

Is it bad that I understood this instantly?

I actually did benchmarks for methods of combining two hashes in perl, and this method seems to be significantly faster than any others I tried. I think it looks a lot nicer without all those optional braces, tho:

@\$gst{keys %\$rec} = values %\$rec;

And as for the comment... well, I'm gonna have to confess to using similar comments myself. Code can be evil-genious-y without being inappropriate for serious projects, IMO.

Are any other Perl coders reading this and saying "so that's how you copy one hash into another?"  I've never been able to grasp the syntax of list-assignments with anything beyond trivial lists of scalars on the left side.

• Zygo (unregistered) in reply to Twm
Anonymous:

long live the codesmorgasboard.

I like this one;

#define SIZE_2048 2048

It reminds me of a code review I once did. the code review policy at our company stated that "thou shall not use magic numbers in code. They are unreadable to new eyes and hinder maintenance"

So after pointing out a few of them

init_interupt(\$A355, \$B643)

I had to smile when getting the code back to review a second time:

const uint C_A355 = \$A355
const uint C_B643 = \$B643

init_interupt(C_A355, C_B643) <--- there, much more readable

The best are:

const uint C_A355 = \$A335
const uint C_B643 = \$B6A3
then spend a month wondering why it doesn't work...especially if these constants are used in rare situations.
• (cs) in reply to Zygo
Anonymous:

The best are:

const uint C_A355 = \$A335
const uint C_B643 = \$B6A3
then spend a month wondering why it doesn't work...especially if these constants are used in rare situations.

I just spent like 5 minutes trying to figure out what was going wrong with this one thing. Here, I'll reproduce (paraphrase) the symptoms:

% ls
....    wf1.c
% cat wfl.c
% cat w<TAB for autocomplete>f1.c
.... (no error)
% ls wfl.c
%

Stupid ssh program I was using uses a font that makes 1 ("one") and l ("lowercase L") nearly indistinguishable...

• (cs)
Jake Vinson:

And finally, Allison B. sent in this entry on Octobe#ERROR: DATE DOES NOT EXIST

/* note, system uses 360 days in a year, not 365 */

Unless I'm mistaken, 360 day years are used in some financial circles.

Ayup:

http://en.wikipedia.org/wiki/360_day_calendar

(Edit: Yeah and I'm like bazillionth person to point this out. Sorry. Just pointing out that some people had to learn about this WTF back in high school. =)

• (cs)
1000 GOTO 1002
1001 GOTO 1010
1002 GOTO 1001
Wait, that's brilliant! They actually managed to produce code that executes backwards, from the bottom up!
• (cs) in reply to Arancaytar
Arancaytar:
1000 GOTO 1002
1001 GOTO 1010
1002 GOTO 1001
Wait, that's brilliant! They actually managed to produce code that executes backwards, from the bottom up!

and to think people used to get paid to do this  :(

• Green (unregistered) in reply to kuroshin
kuroshin:
Jake Vinson:

Let's get things started with Michael, who shows us the easy way to calculate radii!

Looks like this is from Javascript.

There is no such thing as an int(eger) data type in Javascript. Also, Javascript doesn't know casting and especially not this C-style syntax. The above code will simply produce a syntax error.

• Drak (unregistered) in reply to TechNoFear
Arancaytar:
1000 GOTO 1002
1001 GOTO 1010
1002 GOTO 1001
Wait, that's brilliant! They actually managed to produce code that executes backwards, from the bottom up!

This is obviously a BASIC way of implementing a sort of NOP.. perhaps a (very short)  pause between 2 different notes of music or whatever to make a more lasery sound in a game (worked like a charm on my old p3105)

• Tub (unregistered) in reply to Drak
Anonymous:
Arancaytar:
1000 GOTO 1002
1001 GOTO 1010
1002 GOTO 1001
Wait, that's brilliant! They actually managed to produce code that executes backwards, from the bottom up!

This is obviously a BASIC way of implementing a sort of NOP.. perhaps a (very short)  pause between 2 different notes of music or whatever to make a more lasery sound in a game (worked like a charm on my old p3105)

no no no! That was

FOR i = 0 TO 10000
END FOR

• (cs) in reply to Zygo
Zygo:
Are any other Perl coders reading this and saying "so that's how you copy one hash into another?"  I've never been able to grasp the syntax of list-assignments with anything beyond trivial lists of scalars on the left side.
these're the same:

(\$foo, \$bar[2], \$bar[3], \$bar[4], \$baz)
(\$foo, @bar[2 .. 4], \$baz)

as are these:

(\$foo, \$bar{eek}, \$bar{ack}, \$bar{ook}, \$baz)
(\$foo, @bar{qw(eek ack ook)}, \$baz)

This is true whether they're being assigned to or otherwise. However, if you put a complete array or hash on the LHS of an assignment, it will take up as much as it can from the RHS, and everything asfter it on the LHS will end up as undef:

(\$foo, @bar, \$baz) = something(); # \$baz = undef, always

clear as mud?
• (cs) in reply to Muhahahaha

Anonymous:
I wrote the "# muhahahaha" line two companies ago, and like "Irrelevant" the first thing I thought when I saw it again was that it had unnecessary braces, and in my defense, Bob probably made me keep them.  I believe at the time it replaced a much larger and clunkier chunk of code, hence the evil laughter from my volcanic headquarters.  Naturally I know who P.C. is and I'll be dropping him a line.  Good times, good times :).

Awesome...I predict "muhahahah" is going to be a new TDWTF inside joke like Paula Bean and woodent tables. I already wrote muhahaha.h to include in all my projects. Cheers

• Rich (unregistered) in reply to EvanED

EvanED:
That doesn't match the semantics of the original. What if b is NOT equal to b, what then? The code given leaves it unchanged; yours sets it to false. better would be 'b = (b == b ? true : b);'

Now, that's true enough but why not go one step further to make it just that little bit more interesting?:<p>

b = ( b==b ? b==b : b );

<p>

Rich

• Rich (unregistered) in reply to Rich

wtf? Earlier I relied on carriage returns in the input box to create paragraphs and it ended up joining my name to the end of my comment (whitespace), this time I put in HTML and it htmlescaped it...

Rich

• Rich (unregistered) in reply to Rich
Anonymous:
wtf? Earlier I relied on carriage returns in the input box to create paragraphs and it ended up joining my name to the end of my comment (whitespace), this time I put in HTML and it htmlescaped it...

Rich

And then it just did it again. I suspect different mechanisms for reply and quote?

Rich

• Rich (unregistered) in reply to Rich

OK, I give up

Rich

• (cs) in reply to R.Flowers
R.Flowers:
Jake Vinson:

Three lefts are not, in fact, a right, as Chris C. shows.

1000 GOTO 1002
1001 GOTO 1010
1002 GOTO 1001

How old are some of these?

I'll step up and tell you that I cut my programming teeth on BASIC with line numbers. I'll also offer a guess as to how this ended up in the wild.

Depending on the machine and the BASIC variant, jumping over a line of code might be easier than 'commenting it out.' Some of those old built-in editors were onery, and it was much easier to use a GOTO to jump over a suspect line. (Line 1002 might have just been something like 1002 REM - DEBUGGING.) Then, after that line was checked, the programmer, again avoiding the editor, just changed line 1002 to jump to the original line. Why not 1010? Hey, this is a weak enough explanation anyway...

I'd bet that the compiler would effectively take these out, anyway.  This person may be the laziest programmer alive.  ;)

• (cs) in reply to anonymous
Anonymous:

Anonymous:
Note: If b=false then would come out of that equation equal to true.  The if... then is completley unneeded.  Now what the poor guy was meaning to do is a whole different matter.

For example, we don't know what the data type of b is: if b can be "null", then (except in a few strange Microsoft worlds), b = b will return false.

To even claim this much, I'm making assumptions about the nature of "=".  Like I said at the beginning, we need more information before we can start laughing at this one.

I'm laughing.  No matter what = is doing here, I see no reason to do it to one variable like this.  If it is a conditional operator, you would never check to make sure that the value in b is in fact the value in b, and if you are counting on strange proprietary compiler behavior it is still a terrible peice of code.  If the = is an assignment operator, nothing would still be accomplished.  And one last case, if = is redefined somehow for any other operation, it is still too misleading.

• (cs) in reply to Rich
Anonymous:

WTF? I've used C, C++, Java and C# and this does not look the slightest bit "C stylee" (sic) to me. It looks more like Basic.

Sorry, I already beat you to correcting myself.

Of course, the real WTF is that Basic uses the same symbol for assignment and equality comparison.

Equally as wtf is that other languages use the equality operator (=) for assignment then to test equality end up using things like "=="

Rich

Different strokes for different folks...I always liked := from Pascal for assignment.

• Tub (unregistered) in reply to seymore15074

seymore15074:
I'd bet that the compiler would effectively take these out, anyway.  This person may be the laziest programmer alive.  ;)

on those times where BASIC-instructions where preceeded by line numbers, the compilers couldn't do anything more fanzy than a literal translation of source code to machine code.

seymore15074:
Different strokes for different folks...I always liked := from Pascal for assignment.

It's ok to read, but I find it to be a pain to type, at least on the german keyboard layout I'm used to.

• (cs)

360 days in a year? Guess its not a unique idea.

• webdev101 (unregistered) in reply to anonymous
Anonymous wrote the following post at 10-09-2006 2:24 PM:
[image] Anonymous:
Note: If b=false then would come out of that equation equal to true.  The if... then is completley unneeded.  Now what the poor guy was meaning to do is a whole different matter.

For example, we don't know what the data type of b is: if b can be "null", then (except in a few strange Microsoft worlds), b = b will return false.

To even claim this much, I'm making assumptions about the nature of "=".  Like I said at the beginning, we need more information before we can start laughing at this one.

<joke>Is it possible that there was an operator override function for "=" and it assigns not equal of b to b? If that is the case this is even bigger WTF.</joke>

• (cs) in reply to Reinder
Anonymous:
#define SIZE_2048 2048
struct disk_request (
...
BYTE buffer[SIZE_2048];  /* data buffer 1024 bytes long */
};
This could be correct on a 4-bit system with a non-standard C compiler where chars are 4 bits :-)

Well, no, because it'd still be 2048 bytes, just 2048 4-bit bytes. 1024 octets, I'll grant you, and most people think octet and byte are synonymous.

(Actually, no variety of  C could go as far down in character size as 4 bits. I think 6 bits was the absolute minimum.)
• Igor (unregistered) in reply to Octo
Anonymous:
<code>BYTE buffer[SIZE_2048];  /* data buffer 1024 bytes long */</code>

We do live in a world of multi-byte character sets these days... the comment should have read "1024 characters" instead of bytes, but the code might well be valid.

Pardon me but last time I checked disk sector buffers were still measured in BYTES. Since the buffer of 1024 bytes is less common, I presume that the comment is stale and that the size of 2048 is there because of say sector size on a CD.

Another thing is that whoever wrote that hasn't used const int instead of #define.

• Pedro (unregistered) in reply to Gedoon

That is right.

This is because it was too difficult to do calculation with 365.. The winner is the lender i.e. usually banks.

• Cristian (unregistered)
Jake Vinson:

Janson discovered buildGroupLink, which is just another way of saying "the answer to life, the universe, and everything."

{
return "42";
}

Is this the routine of Deep Thought?... I'm disappointed.

• (cs) in reply to Cristian
Anonymous:
Jake Vinson:

Janson discovered buildGroupLink, which is just another way of saying "the answer to life, the universe, and everything."

{
return "42";
}

Is this the routine of Deep Thought?... I'm disappointed.

<font face="tahoma,arial,helvetica,sans-serif">I think Deep Thought has sleep() on the first line...

</font>
• Erwin Bolwidt (unregistered) in reply to Andy Ross
The "(int)0.5 + radius" has a precedence bug that makes it a noop, but it isn't as dumb as it looks.  Using (int)(0.5 + x) is a quick & easy way to get proper rounding behavior of positive (!) floating point values.  If the code is in C, note that there are portability issues with functions like round() and rint(), and the above code might actually be preferred in some environments.

It's also correct for negative numbers (with the parentheses), if you take the frequently-used convention of rounding 0.5 to the next bigger whole number. The java Math.round function is implemented in the same way as the WTF. (That may just reinforce some ppls preconceptions about Java, but wtf..)

• foonly (unregistered) in reply to Artemus Harper
Anonymous:

FYI, a possible implementation in java of Double.isNaN(double d):

public boolean isNaN(double d)

{

return d != d;

}

Just to show that there are cases of testing to see if something is equal to itself.

The question "Is Nan double-D?" can only be answered by a careful measurement of Nan's, er, size.

• fsdfsdfdsfsd (unregistered)

360 day a year?

Must be METRIC :)

• (cs) in reply to Jimbo

Well, I suppose the issue with if b=b could have been some procedural extention to SQL.

If that was the case and b was NULL, then b=b would not return true and b would not be set to true.

Still not elegant.  Better in this case:  if b IS NOT NULL....

This is probably a financial application tracking Bonds... they use 360 day calendars.

/* note, system uses 360 days in a year, not 365 */

Ricky H.'s find speaks for itself.

if b = b then b = true end if

If this is VB, he could just replace it with

b = b = b