• (cs) in reply to M Cassidy
M Cassidy:
The code was probably the result of reverse engineering, ie using Reflector or similar. And what else, would the reflection tool name the enumerations?
You're kidding, right?

In my experience, reverse engineering/refactoring tools tend to produce:

<cat walked over my keyboard>@smoosh%xxx1 <cat walked over my keyboard>@smoosh%xxx2 <cat walked over my keyboard>@smoosh%xxx3 <cat walked over my keyboard>@smoosh%xxx4

and so on. (I'm being kind: they're normally not that consistent.)

Show me a reflection tool that consistently renames integers as in the OP, and I will be deeply impressed. (And depressed at the same time. Who would feel the need for such a tool?)

Otherwise:

You're kidding, right?

• mudkip (unregistered) in reply to real_aardvark
real_aardvark:
Cloak:
The MAZZTer:
Josh:
But I can't help but vividly recall a homework assignment that involved some kind of calculations, and just about everyone's program had a constant named some variant of SQRT_3_OVER_2.

THEORETICALLY this is actually not a WTF, except that you can't tell if they mean sqrt(3 / 2) or sqrt(3) / 2 (I'll assume the latter).

Now if SQRT_3_OVER_2 is defined as 0.5773503 it's almost as valid as defining a PI. Almost. Because there IS a sqrt() function in any competent language and the computation only takes a few cycles, so why hard code it? The only reason you'd need to is if it was a bit more computationally hard, and ran several hundred times (or around there) a second in some time-critical code (ie a game rendering loop or something).

SQRT_3_OVER_2: sqrt(3)/2 = 0,86602540378443864676372317075294

SQRT_3_OVER_2: sqrt(3/2) = 0,61237243569579452454932101867647

Ooh, impressive. You're obviously not using one of the OMGWTF contest calculators, are you?

Nice catch.

For the record, in mathematical usage this kind of ambiguity would be a problem but for intonation when verbalized and shared familiarity with the problem domain.

• Harrow (unregistered) in reply to phil
phil:
Err.. no they didn't. They just used the English spelling, as opposed to the American English spelling.

(I live in England. We speak English. There is no such thing as "British English" - that would be like "European French". It is the other variants which should be named differently.)

I don't believe you are English. Everybody knows that English people spell everything funny, with lost of extra "u"'s and stuff. If you were English, you would have written:

"Yarr.. noe theuy didn'ut. Theuy joust oused ye Engliush speulling, has oppoused tou ye Ameurican Engliush speulling.

"(Oi liuve hin Englaund. Ouwe speeke Engliush. Theure his noe souch thiung has "Britiush Engliush" - thaut would bee loike "European Freunch". Hit his ye outher variaunts whiuch should bee nuamed differauntly.)"

-Harrouwe.

• (cs) in reply to SomeCoder
SomeCoder:
The MAZZTer:
Now if SQRT_3_OVER_2 is defined as 0.5773503 it's almost as valid as defining a PI. Almost. Because there IS a sqrt() function in any competent language and the computation only takes a few cycles, so why hard code it? The only reason you'd need to is if it was a bit more computationally hard, and ran several hundred times (or around there) a second in some time-critical code (ie a game rendering loop or something).

Actually, power functions (and of course we all know that square root is a power function) are incredibly taxing for most systems to perform. Granted, we don't know what the original code was really supposed to do, but if speed was a factor, then you would want to avoid all built in power functions as much as possible (as you alluded to).

I was using integer powers in a simple benchmark program. I'd loop for 10^1, then 10^2, then 10^3, until the loop took more than 1 second to complete. It gave a pretty reliable indicator of the speed of a given language. IIRC C overflowed the 32-bit loop counter (10^10), and some languages were as bad as 10^5.

It was originally: for(i=0;i<pow(10,j);i++) Optimized to: (with a truely stupid speed increase) for(i=pow(10,j);i>0;i--) But as it turned out, the pow function was slow enough to impact the results, even when only run once. Replaced it with a simple int^int version that just multiplied x times in a loop, which turned out to be faster, even at x^10. Eventually I figured that I could just multiply the max value by 10 each loop outside of the timer, eradicating pow altogether. I was young...

I also had a few problems getting a sensible result from VC++, because it was optimizing the loop out entirely, and just doing i=pow(10,j) (on the original, before hand optimizing it). "0s for 10^10, what?" No other compiler for any language I tried did that one.

But yeah, my point was that pow is slower than 10 integer multiplies in a row, and sqrt is as bad.

• (cs) in reply to Harrow
Harrow:
phil:
Err.. no they didn't. They just used the English spelling, as opposed to the American English spelling.

(I live in England. We speak English. There is no such thing as "British English" - that would be like "European French". It is the other variants which should be named differently.)

I don't believe you are English. Everybody knows that English people spell everything funny, with lost of extra "u"'s and stuff. If you were English, you would have written:

"Yarr.. noe theuy didn'ut. Theuy joust oused ye Engliush speulling, has oppoused tou ye Ameurican Engliush speulling.

"(Oi liuve hin Englaund. Ouwe speeke Engliush. Theure his noe souch thiung has "Britiush Engliush" - thaut would bee loike "European Freunch". Hit his ye outher variaunts whiuch should bee nuamed differauntly.)"

-Harrouwe.

You guys are aware that America is the only English speaking nation that DROPPED the u's right...?

Your friendly neighbours to the north kept them, same with the Aussies.

:P

• w00t (unregistered) in reply to Harrow
Harrow:
phil:
Err.. no they didn't. They just used the English spelling, as opposed to the American English spelling.

(I live in England. We speak English. There is no such thing as "British English" - that would be like "European French". It is the other variants which should be named differently.)

I don't believe you are English. Everybody knows that English people spell everything funny, with lost of extra "u"'s and stuff. If you were English, you would have written:

"Yarr.. noe theuy didn'ut. Theuy joust oused ye Engliush speulling, has oppoused tou ye Ameurican Engliush speulling.

"(Oi liuve hin Englaund. Ouwe speeke Engliush. Theure his noe souch thiung has "Britiush Engliush" - thaut would bee loike "European Freunch". Hit his ye outher variaunts whiuch should bee nuamed differauntly.)"

-Harrouwe.

Oh come on. It's not like Phil's from York, surely..

• Harrow (unregistered) in reply to Galbrezu
Galbrezu:
You guys are aware that America is the only English speaking nation that DROPPED the u's right...?

Your friendly neighbours to the north kept them, same with the Aussies.

Yes, well, I can see why the AUSSIES would want to keep the "U"...

-Harrow.

• Darien H (unregistered) in reply to real_aardvark
real_aardvark:
Show me a reflection tool that consistently renames integers as in the OP, and I will be deeply impressed. (And depressed at the same time. Who would feel the need for such a tool?)

Otherwise:

You're kidding, right?

I think you missed his point: Our theorized tool is NOT "renaming integers". The tool is guessing the name of a constant based on the constant's known value, which in this case happens to be an integer. That is because the information of what the constant was called for human usage has been discarded.

As for cats walking on keyboards, I've seen Java, by notable example, decompile quite nicely.

• (cs) in reply to sibtrag
sibtrag:
I would maintain that using a constant named SQRT_3_OVER_2 is indeed good practice rather than using 0.866024503 many places in the code. Using SQRT_3_OVER_2 does document the purpose of the number (albeit a low-level meaning) and has the side benefit of avoiding typographical errors such as inadvertently reversing digits.

"SQRT_3_OVER_2" doesn't document any purpose at all...no different than "#define FOUR 4". If you have a number like that it probably has a real puropse. Sure, it's better than hardcoding the literal constant itself -- but not by much.

• John (unregistered)

It's actually incorrect how he named those variables as well...

5422 is Five thousand four hundred twenty two. NOT Five thousand four hundred and twenty two

• (cs) in reply to Darien H
Darien H:
real_aardvark:
Show me a reflection tool that consistently renames integers as in the OP, and I will be deeply impressed. (And depressed at the same time. Who would feel the need for such a tool?)

Otherwise:

You're kidding, right?

I think you missed his point: Our theorized tool is NOT "renaming integers". The tool is guessing the name of a constant based on the constant's known value, which in this case happens to be an integer. That is because the information of what the constant was called for human usage has been discarded.

As for cats walking on keyboards, I've seen Java, by notable example, decompile quite nicely.

Nope, I'm not missing the point. I'm not theorising, either. Show me that tool.

And by "decompile" I assume you mean "decompose." Not just quite nicely, but quite quickly.

• Uh... (unregistered) in reply to Galbrezu
You guys are aware that America is the only English speaking nation that DROPPED the u's right...?

Uh... U's were not dropped from the language. They were added. When (what is now) the US was still under British rule, there were no extra U's in words like "hono[u]r". The U's were added later (middle of the 19th century if I remember correctly), which is why places like Canada and Australia use that spelling (the British Monarch is still their head of state).

• James Schend (unregistered) in reply to Harrow
Harrow:
Galbrezu:
You guys are aware that America is the only English speaking nation that DROPPED the u's right...?

Your friendly neighbours to the north kept them, same with the Aussies.

Yes, well, I can see why the AUSSIES would want to keep the "U"...

-Harrow.

You win the Internet. ROFL, seriously.

• (cs) in reply to Uh...
Uh...:
You guys are aware that America is the only English speaking nation that DROPPED the u's right...?

Uh... U's were not dropped from the language. They were added. When (what is now) the US was still under British rule, there were no extra U's in words like "hono[u]r". The U's were added later (middle of the 19th century if I remember correctly), which is why places like Canada and Australia use that spelling (the British Monarch is still their head of state).

“Added” is a nice euphemism. It’s documented that during the War of 1812, a Canadian commando force stole all the u’s from the US in a brilliant raid on the National Vowel Repository in Philadelphia. The ill-gotten u’s were redistributed around the British Empire where they stuck them wherever they could. Until the rich Gatlinburg u deposits were discovered in the mountains of Tennessee, Americans military leaders were unable to order flanking assaults or counter-attacks.

Letter imperialism is an ugly page in history. Look at all those Eastern European countries which still feel the effects of a desperate vowel shortage in their words, thanks to Napoleon’s collecting vowels as “war prizes” for the French language while on his way to Moscow.

--Rank

• Bender Robot from up yours (unregistered)
private static final int ONETHOUSANDANDTWENTYFOUR = 1024; private static final int TWOTHOUSANDANDFOURTYEIGHT = 2048;

I'd just like to point out while he was being cleeeevar, he messed up, should read

private static final int ONETHOUSANDANDTWENTYFOUR = 1000.24; private static final int TWOTHOUSANDANDFOURTYEIGHT = 2000.48;

-- and captcha didn't catch me

• el jaybird (unregistered) in reply to Harrow
Harrow:
Everybody knows that English people spell everything funny, with lost of extra "u"'s and stuff.

They also make funny faces when they speak, cf. http://www.youtube.com/watch?v=yafc_jSv2Wg&mode=related&search=

:)

• el jaybird (unregistered)

err... that was supposed to be a link to this Russell Peters sketch on Youtube.

• (cs)

http://www.angelfire.com/ok5/pearly/htmls/onion-vowels.html

• Andrew (unregistered) in reply to SomeCoder
SomeCoder:
Actually, power functions (and of course we all know that square root is a power function) are incredibly taxing for most systems to perform. Granted, we don't know what the original code was really supposed to do, but if speed was a factor, then you would want to avoid all built in power functions as much as possible (as you alluded to).

This code looks like Java though, so I'm going to assume that speed isn't that important (I'm not saying that Java is slow, just that the kind of optimization you would get from not using power functions would most likely be less important in Java than say C++).

I disagree that all power functions are incredibly taxing on most systems. This is a numerical analysis issue.

Fortran compilers optimized base raised to the pow (base**pow) well. For an integer pow variable, it created a loop: R = 1 DO I = 1,POW R = RBASE ENDDO A real pow variable needed logaritms: R = EXP(POWLOG(BASE)).

Furthermore, SQRT(N) can use the Newton-Raphson method solving for X in X2 - N = 0. This converges rapidly. Because X2 is a parabola, there are no alternate roots to converge, like X**3 and higher powers.

• stiggy (unregistered)

Oh. My. God.

• (cs) in reply to Uh...
Uh...:
Uh... U's were not *dropped* from the language. They were *added*. When (what is now) the US was still under British rule, there were no extra U's in words like "hono[u]r". The U's were added later (middle of the 19th century if I remember correctly), which is why places like Canada and Australia use that spelling (the British Monarch is still their head of state).

I'm not sure where you're getting this. While it's not entirely true that American spelling dropped the U's, it's a lot more close to the truth than claiming that the UK, etc. added them. Noah Webster is singlehandedly responsible for quite a bit of the spelling differences between UK and American English.

http://en.wikipedia.org/wiki/American_and_British_English_spelling_differences

• (cs) in reply to Bender Robot from up yours
Bender Robot from up yours:
private static final int ONETHOUSANDANDTWENTYFOUR = 1024; private static final int TWOTHOUSANDANDFOURTYEIGHT = 2048;

I'd just like to point out while he was being cleeeevar, he messed up, should read

private static final int ONETHOUSANDANDTWENTYFOUR = 1000.24; private static final int TWOTHOUSANDANDFOURTYEIGHT = 2000.48;

-- and captcha didn't catch me

ONETHOUSANDANDTWENTYFOUR is not 1000.24.

Actually, the unnecessary "AND" doesn't create any ambiguity in the above example. However, the "AND" should be left out. It creates ambiguity when you say "three hundred and twelve thousandsth." That expression is not .312 but rather 300.012 because the "and" acts as a decimal point.

And by the way, is it okay to declare an INT as a number with two decimals places?

• dkf (unregistered) in reply to Flash
Flash:
Actually, the unnecessary "AND" doesn't create any ambiguity in the above example. However, the "AND" should be left out. It creates ambiguity when you say "three hundred and twelve thousandsth." That expression is not .312 but rather 300.012 because the "and" acts as a decimal point.
The use of "and" seems to be something that varies culturally. I was taught to use it, but it seems you weren't. On the other hand, I'd also say 350.012 as "three hundred and fifty, point oh one two". That's ambiguity free, and avoids the word "thousandsths" which has an ending that would make me like a spluttering snake. Decorum is important!
• tw (unregistered) in reply to db
db:
Any competent optimizing compiler would evaluate sqrt(3)/2 or sqrt(3/2) into constants.

Well, aside from the already noted fact that you probably actually want sqrt(3.0)/2.0, that's not the solution you want in any floating point program in which you really care about accuracy because the compiler runtime (ie the sqrt performed at compile-time to produce the constant) may not calculate it to the same precision as the program runtime (ie the sqrt performed when the compiled program executes).

This can easily happen on a normal compiler due to optimizing factors, and is almost guaranteed to happen in cross-compiling, since the host FP system won't be the same as the target FP system.

And it's rather inconvenient if you end up with a resultant program where

`sqrt(3.0)/2.0!=sqrt(3.0)/2.0`

• (cs) in reply to Cloak
Cloak:
Or even better use the Klingonian base 13 numbering system
Cloak:
Or even better use the Klingonian base 13 numbering system
Or better yet, use the Refresh button before reposting.
• Stefan W. (unregistered) in reply to O Thieu Choi
O Thieu Choi:
Insufficiently evil, if you ask me. A properly insane coder would have used Roman numerals:

private constant static int MMXLVIII = 2048;

That's a big improvement! Let's push that idea more forward!

The romanians were used to round numbers like X, L, M, so did the arabians 10, 100, 1000 and so do we hackabes: 0x200 0x400.

Let's use the romanian M as if it where a binary k, alias 1024. For clarity we prefix it with a b (binary):

private constant static int bL = 128; private constant static int bLL= 256; private constant static int bD = 512; private constant static int bM = 1024; private constant static int bMM= 2048;

isn't that pretty?

Of course we could observe the needless roman way.

private constant static int 2P7 = 128; private constant static int 2P8 = 256; private constant static int 2P9 = 512; private constant static int 2P10= 1024; private constant static int 2P11= 2048;

Hm. 7, 8, 9 is not very geeky. 8 is 2P3, so 2P8 could be written as 2P2P3. 7 is 2P2 + 2P1 + 2P0 128 could be reduced to 2P_2P2p2P1p2P0.

• B (unregistered) in reply to el jaybird
el jaybird:
Josh:
But I can't help but vividly recall a homework assignment that involved some kind of calculations, and just about everyone's program had a constant named some variant of SQRT_3_OVER_2.

Well, that might not be so terrible if the code was calculating a function that involved (root 3 over 2) a lot. I've forgotten all my university math (sigh) but I know that was a number that showed up a lot, along with pi and e.

Yep. It is sin(pi/3) (or cos(pi/6)) and frequently appears in elementary trigonometry.

• Sumudu (unregistered) in reply to real_aardvark
real_aardvark:
Cloak:
The MAZZTer:
Josh:
But I can't help but vividly recall a homework assignment that involved some kind of calculations, and just about everyone's program had a constant named some variant of SQRT_3_OVER_2.

THEORETICALLY this is actually not a WTF, except that you can't tell if they mean sqrt(3 / 2) or sqrt(3) / 2 (I'll assume the latter).

Now if SQRT_3_OVER_2 is defined as 0.5773503 it's almost as valid as defining a PI. Almost. Because there IS a sqrt() function in any competent language and the computation only takes a few cycles, so why hard code it? The only reason you'd need to is if it was a bit more computationally hard, and ran several hundred times (or around there) a second in some time-critical code (ie a game rendering loop or something).

SQRT_3_OVER_2: sqrt(3)/2 = 0,86602540378443864676372317075294

SQRT_3_OVER_2: sqrt(3/2) = 0,61237243569579452454932101867647

Ooh, impressive. You're obviously not using one of the OMGWTF contest calculators, are you?

Actually, he probably is. How else would he have come to the conclusion that the square root of 3/2 (definitely greater than 1) is equal to 0.612... (definitely less than 1). The mind boggles (at least he got sqrt(3)/2 correct).

sqrt(3/2) = 1.22474487139158904909864203735..., which is twice what Cloak reported. He was obviously thinking of SQRT_3_OVER_2_OVER_2...

• (cs) in reply to Stefan W.
Stefan W.:
O Thieu Choi:
Insufficiently evil, if you ask me. A properly insane coder would have used Roman numerals:

private constant static int MMXLVIII = 2048;

That's a big improvement! Let's push that idea more forward!

The romanians were used to round numbers like X, L, M, so did the arabians 10, 100, 1000 and so do we hackabes: 0x200 0x400.

Let's use the romanian M as if it where a binary k, alias 1024. For clarity we prefix it with a b (binary):

private constant static int bL = 128; private constant static int bLL= 256; private constant static int bD = 512; private constant static int bM = 1024; private constant static int bMM= 2048;

isn't that pretty?

Of course we could observe the needless roman way.

private constant static int 2P7 = 128; private constant static int 2P8 = 256; private constant static int 2P9 = 512; private constant static int 2P10= 1024; private constant static int 2P11= 2048;

Hm. 7, 8, 9 is not very geeky. 8 is 2P3, so 2P8 could be written as 2P2P3. 7 is 2P2 + 2P1 + 2P0 128 could be reduced to 2P_2P2p2P1p2P0.

Shouldn't that then be private constant static int bC = 128; and not private constant static int bL = 128;

C is the roman number for hundreds where as L is 50

• i want a burger (unregistered) in reply to Bender Robot from up yours
Bender Robot from up yours:
private static final int ONETHOUSANDANDTWENTYFOUR = 1024; private static final int TWOTHOUSANDANDFOURTYEIGHT = 2048;

I'd just like to point out while he was being cleeeevar, he messed up, should read

private static final int ONETHOUSANDANDTWENTYFOUR = 1000.24; private static final int TWOTHOUSANDANDFOURTYEIGHT = 2000.48;

-- and captcha didn't catch me

private static final int ONETHOUSANDANDTWENTYFOUR = 8 private static final int TWOTHOUSANDANDFOURTYEIGHT = 16

Obviously the intent here was "1000 & 24" etc.

• Ann Nonymous (unregistered) in reply to tsmith

Another popular version:

```private static final int ERROR_INVALID_FILENAME = (1 << 0);
private static final int ERROR_INVALID_USERNAME = (ERROR_INVALID_FILENAME << 1);
...
```
• Stefan W. (unregistered) in reply to Xandax
Xandax:
Shouldn't that then be private constant static int bC = 128; and not private constant static int bL = 128;

C is the roman number for hundreds where as L is 50

absolutely! My fault. Mea culpy!

• bobdobbs (unregistered) in reply to Harrow

Not do mention the Americans dropping the 'r' in Arse !

• (cs) in reply to Xandax
Xandax:
Stefan W.:
O Thieu Choi:
Insufficiently evil, if you ask me. A properly insane coder would have used Roman numerals:

private constant static int MMXLVIII = 2048;

That's a big improvement! Let's push that idea more forward!

The romanians were used to round numbers like X, L, M, so did the arabians 10, 100, 1000 and so do we hackabes: 0x200 0x400.

Let's use the romanian M as if it where a binary k, alias 1024. For clarity we prefix it with a b (binary):

private constant static int bL = 128; private constant static int bLL= 256; private constant static int bD = 512; private constant static int bM = 1024; private constant static int bMM= 2048;

isn't that pretty?

Of course we could observe the needless roman way.

private constant static int 2P7 = 128; private constant static int 2P8 = 256; private constant static int 2P9 = 512; private constant static int 2P10= 1024; private constant static int 2P11= 2048;

Shouldn't that then be private constant static int bC = 128; and not private constant static int bL = 128;

C is the roman number for hundreds where as L is 50

This is all very, very, sad. Don't you guys have a nice fluffy kitten to play with?

First of all, the "Romanian empire" died in a hail of bullets with Nicolae Ceaucescu. I believe you are thinking of the "Romulan empire." God knows what their numeric system was: degenerate Klingon, perhaps?

I do so like "For clarity we prefix it with a b (binary)." Very clear. Hungarian notation on Romanian obfuscation. Here comes the next Balkan war ...

And, "private constant static int 2P7 = 128?"

I don't know where this comes from, needless and Roman as it might be, but AFAIK it won't compile in Java. Or in any other sensible language. (Did I just accuse Java of being sensible?) What, exactly, is the point?

All of which is beaten by "C is the roman number for hundreds where as L is 50."

It's difficult to know which is the more cretinous: pointing out the bleeding obvious in a context that requires no explanation, or attempting to analyse a meaningless post and picking nits in it.

Oh, hang on a minute ... What am I doing here?

Well, that's WTF for you. Incidentally, O Thieu Choi's post was both wise and witty. As usual, everything else has rapidly disappeared around the S-bend.

• (cs)

hello cargo cult!

• (cs) in reply to real_aardvark
real_aardvark:

Off topic: Alex might want to examine http://www.wtfmagazine.co.uk/ for potential copyright violation.

No evidence of any copyright violation there; it's potential TRADEMARK infringement. However even if thedailywtf was registered as a trademark, he now uses worsethanfailure in full, so I don't think there's a case.

• (cs) in reply to Cloak
Cloak:
Or even better use the Klingonian base 13 numbering system

Wha? Klingons use base 10, same as us. This was supposedly brought about to better understand scientific work of other planets; they originally used base 3 (not 13).

What's "Klingonian" anyway?

• (cs) in reply to bobdobbs
bobdobbs:
Not do mention the Americans dropping the 'r' in Arse !

"Ase"? Gives polymerase a whole new meaning ... (As in "We are dyslexic of Borg, prepare to have your ass laminated.)

• (cs) in reply to Daniel Beardsmore
Daniel Beardsmore:
What's "Klingonian" anyway?
A neologism. It's like when the English speak Englishian.
• (cs) in reply to tw
tw:
db:
Any competent optimizing compiler would evaluate sqrt(3)/2 or sqrt(3/2) into constants.

Well, aside from the already noted fact that you probably actually want sqrt(3.0)/2.0, that's not the solution you want in any floating point program in which you really care about accuracy because the compiler runtime (ie the sqrt performed at compile-time to produce the constant) may not calculate it to the same precision as the program runtime (ie the sqrt performed when the compiled program executes).

This can easily happen on a normal compiler due to optimizing factors, and is almost guaranteed to happen in cross-compiling, since the host FP system won't be the same as the target FP system.

And it's rather inconvenient if you end up with a resultant program where

`sqrt(3.0)/2.0!=sqrt(3.0)/2.0`
assert(sqrt(3.0)/2.0==sqrt(3.0)/2.0) will actually fail on some architectures and optimizations (assuming constant folding is off).

• (cs) in reply to m0ffx
m0ffx:
real_aardvark:

Off topic: Alex might want to examine http://www.wtfmagazine.co.uk/ for potential copyright violation.

No evidence of any copyright violation there; it's potential TRADEMARK infringement. However even if thedailywtf was registered as a trademark, he now uses worsethanfailure in full, so I don't think there's a case.

Yeah, I know. But nobody gets excited over trademark infringement (except pointless lawyers with nothing better to do), and, besides, the front cover is curiously appealing.

The magazine itself is, as per usual with UK "tech" glossies featuring desirable women in bondage clothes on the front, predictably worthless.

• Alcari (unregistered)
private static final int ONETHOUSANDANDTWENTYFOUR = 1024; private static final int TWOTHOUSANDANDFOURTYEIGHT = 2048;
I believe the correct figure would be OVERNINETHOUSAND!
• ChiefCrazyTalk (unregistered) in reply to phil
phil:
Err.. no they didn't. They just used the English spelling, as opposed to the American English spelling.

(I live in England. We speak English. There is no such thing as "British English" - that would be like "European French". It is the other variants which should be named differently.)

Actually there is a European French, which is distinct from the French spoken in Canada.

Regarding the original post, this is just a classic example of someone not "getting it" - they were told to use constants for numerals, so they did it, without really understanding why.

I really don't mind The Captchas on this site much - at least I can read them, unlike some sites!

• Mike (an WTF-Popup contributer - yea!) (unregistered) in reply to Cloak

You may want to check your math... I am to lazy to calculate this now - but its just wrong.

• Mike (an WTF-Popup contributer - yea!) (unregistered) in reply to Mike (an WTF-Popup contributer - yea!)

so now with quotes...

Cloake:
SQRT_3_OVER_2: sqrt(3)/2 = 0,86602540378443864676372317075294

SQRT_3_OVER_2: sqrt(3/2) = 0,61237243569579452454932101867647

Mike (an WTF-Popup contributer - yea!):
You may want to check your math... I am to lazy to calculate this now - but its just wrong.
• (cs) in reply to tsmith
tsmith:
Errors were encoded into a single integer rather than using a Boolean for each error that occurred. A nice way to overcomplicate things, but fine.

It's actually a common coding idiom in systems programming.

Surely not as common as simple scalars:

```ERROR_INVALID_FILENAME = 1,
...
```

How often is support for multiple simultaneous error conditions required?

• Nutmeg Programmer (unregistered)

With respect to SQRT_3_OVER_2, a better name might be SIN60.

However, my own rule of thumb about taking pains to speed program execution is that if it takes me longer to type figure it out and type it out than it will take for execution in the lifetime of the program, I don't bother. That would include just about all homework assignments. And I trust my compiler to resolve constants.

• (cs) in reply to real_aardvark
real_aardvark:
M Cassidy:
The code was probably the result of reverse engineering, ie using Reflector or similar. And what else, would the reflection tool name the enumerations?
You're kidding, right?

In my experience, reverse engineering/refactoring tools tend to produce:

<cat walked over my keyboard>@smoosh%xxx1 <cat walked over my keyboard>@smoosh%xxx2 <cat walked over my keyboard>@smoosh%xxx3 <cat walked over my keyboard>@smoosh%xxx4

and so on. (I'm being kind: they're normally not that consistent.)

Show me a reflection tool that consistently renames integers as in the OP, and I will be deeply impressed. (And depressed at the same time. Who would feel the need for such a tool?)

Otherwise:

You're kidding, right?

Reflector tries it best by naming local variables to the parameters from the first method they use.

Like if I have a method

public void PrintNumber(int number);

And I decompile some code:

public void DoStuff() { int number = 5; PrintNumber(number); }

Which works most of the time but sometimes it gives a pretty funny result.

tw:
Well, aside from the already noted fact that you probably actually want sqrt(3.0)/2.0

While in C++ (e.g.) there is a small chance that sqrt is overloaded as something like "int sqrt(int)", at least the 2.0 is redundant. If sqrt(3.0), for some strange reason, returns an integer, then all is lost anyhow.

SomeCoder:
Actually, power functions (and of course we all know that square root is a power function)

Yes, but calculating sqrt(x) as exp(log(x) / 2) is inefficient* and since sqrt is used very often, it is almost always special-cased to use a more efficient algorithm, e.g. the one mentioned by Andrew.

*) for x > 0, obviously

ebs2002:
I was always of the impression that any decent math library calculates the square-root of an integer uses a table lookup method

Using enormous tables that clog up your RAM and hard disk? What was the square root of 179257833209697 again? Seriously, for some small range of integers that might possibly make sense.

O Thieu Choi:
Insufficiently evil, if you ask me. A properly insane coder would have used Roman numerals:

private constant static int MMXLVIII = 2048;

I am so doing this for all numeric values in my next project...