- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
explination? explin yourself!
Admin
<FONT style="BACKGROUND-COLOR: #efefef">That is the coolest const name EVER</FONT>
Admin
What confuses me is the really, really confusing names for the constants. Where they've had to have comments associated.
And then, there are the pointless comments next to the conversion functions. Why? Those functions actually have sensible names, so why bother appending a gazillion digit constant to the end of the line? After all, you either trust the writer, or you go check what the conversion value really is.
Admin
All that work, and there are STILL magic numbers in it...
Admin
Excelent use of comments<font color="#008000"> </font><font color="#008000">//good commenting</font>
Admin
Where is the WTF in this? It looks like a perfectly good library for performing unit conversions and geometric calcs. Plus it is fast, since the functions are declared inline. I like the way the constants are named. Personally, I would have defined a couple more:
const double Twenty5Point4 = 25.4
const double TwoPoint54 = 2.54
const double Ten = 10.0
etc.
Admin
beause this is from a library, and because all the functions are inlined, the guy was clearly worried about perf. however, somebody has to maintain this, and the sheer volume that could be cut down with a couple of much simpler functions would be worth the perf hit.
but those const declarations are a total WTF; maybe he hoped the compiler would calculate those and not the run time?
Admin
[:|] Wow! I can see creating the conversions, but having to declare the constants for 1/12 is unacceptable. [:D]
Admin
This represents my #1 pet peeve when reading other people's code. I just can't stand developers that simply "don't get" the purpose of constants.
- Sergio Pereira
Admin
<FONT style="BACKGROUND-COLOR: #efefef">What's the licensing terms for that code? Cause I could sure use it.</FONT>
Admin
What's next?
<FONT color=#0000ff>function</FONT> ThisFunctionConvertsFeetToInches (Feet) {
<FONT color=#008000> //here we go....</FONT>
}
Admin
You would be granted the license for one year and five days.
const double OneYear5Days = 370.0/365.0 //1.01369863
Admin
Admin
I'm not Isaac's coworker (although my son is named Isaac, an interesting coincidence) but here's an attempt at a justification ...
I once worked on a tiny embedded system that had no floating-point hardware and a compiler with absolutely no optimization, but the system had real-time performance requirements.
Division is often much slower than multiplication, even with floating-point hardware. In such a situation, it makes sense to calculate the reciprocal once so that conversions at run-time are all multiplications. (As other folks have commented, the constant names are still questionable.)
Of course, in my case the compiler didn't grok inlining either, so I would have had to use macros instead of typed functions. And "static_cast" -- never heard of it. (A friend of mine says "Embedded Systems: Yesterday's Technology Tomorrow".)
-- Scott
Admin
i love how everyone either is posting the same thing or somehow totally misses the wtf and posts the wtf thinking they've found it
and/or defends names like "OnePtThreeFourTimesFiveSixSevenEight"
Admin
WTF? This makes sense to me! What do you do when the Lbs->Kgs conversion factor changes? Huh, Mr. Smarty Pants?
Admin
Not a comment on this entry, per se. But the last couple of days the RSS XML has been contaminated with what looks like a bunch of style-sheet crap. Am I the only person seeing this?
Admin
Your RSS reader should either ignore them, or use them in a meaningful way. They're all within properly structured [style] tags, so any self-respecting reader should be able to use them as styling classes that are defined within the same entry. It's a very elegant and standardized way to handle formatting.
I mean, seriously, "contaminated", "crap", and "stylesheets" in the same sentence? [^o)]
Admin
You should note that math.h includes a bunch of weird constant names like M_PI, M_PI_2, M_2_PI, M_SQRT1_2. Not as eggregiously bad as naming a constant after the number that's in it since the ones in math.h at least involve things normally known by their name rather than their numeric value like pi, e and sqrt(2), but you can sort of see where they got the idea.
Admin
I'm not complaining about you using stylesheets, I'm just baffled as to why your RSS feed doesn't strip them out.
I think at least part of the problem is that there is no standard in RSS about whether or how much to strip html mark-up in the description field. Your RSS doesn't have header that defines the stylesheet, without with your style tags are pretty useless. So why isn't it stripping the style tags and their contents? And my RSS aggregator generates a web page that has its own style sheet, its own markup, its own div and style tags, so it is quite properly stripping yours, but for some reason not what's in between them. Strangely enough it leaves the <span></span> tags alone.
Admin
Those lines should look like:
<FONT face="Courier New">const float fDeg2Rad = static_cast<float>(Deg2Rad);</FONT>
which is the modern C++ way of saying
<FONT face="Courier New">const float fDeg2Rad = (float)Deg2Rad;</FONT>
except, apparently, when Alex posted it, the <float> was taken as embedded HTML and striped from the message.
Admin
Your aggregator is mishandling the proper XHTML that is contained in the entry. It shouldn't just strip out tags, it should strip out contents of tags as well. If it's trying to enforce its own styles, it should care to, at least, respect the standard way of handling CSS.
You shouldn't blame the RSS provider (or any content provider, for that matter) if they're offering you a fully standardized enhanced experience. If your aggregator is misbehaving, you should either re-configure/re-write it, or switch to a better one -- there's a plethora of them out there.
Admin
I think this person may not realize that even a crappy compiler will optimize out any math between literals. It doesn't change the run time speed of a program to just write 1.0/1760 instead of One1760th.
I've seen even experienced programmers sometimes unable to grasp this concept. I've heard some excuses like "I don't trust the compiler," but seriously this is not complex optimization, it's just the simplest inline math. If you don't trust your compiler to do that you're better off programming in assembly.
Also I'm interested to know why he/she is using doubles everywhere, the only thing you need measurement accuracy like that is on a space shuttle or maybe a missiles launch program, wait, oh my god!
Admin
The whole reason for using constants is to remove the use of arbitrary magic numbers in your code. By including the magic number in the constant name, you're sort of defeating the purpose. It also completely hides the purpose of the constant: what exactly does 1/1760 signify? (I'm actually not sure without whipping out a calculator or checking a reference).
If you went:
then your intent is perfectly clear without the need for comments.
Besides, if you wrote a constant like One3Pt785411th wrong you'd either have to change the constant name everywhere (defeats the purpose of having a constant) or have something just as bad like:
which just screams for someone to 'fix' it later on.
Admin
"Convert" is an verb. If you ask me, variable names that don't include verbs are more useful and direct because you don't use verbs in regular English as a primary means to describe something. In my experience, sticking to nouns and adjectives is the best way to come up with a variable name.
I think CENTIMETERS_PER_INCH, INCHES_PER_CENTIMETER (or any variant of those) would be a very decent set of constant names for this purpose.
Admin
You can laugh all you want, but I used to have a teacher that gave his variables similar names, like for a boolean: blnReturnsTrueIfThisActionOccurs . His exams were really horrible and that was just for JavaScript[:D]
Admin
'I've seen even experienced programmers sometimes unable to grasp this concept. I've heard some excuses like "I don't trust the compiler,"'
Which brings me to pet peeves of mine:
Admin
The WTF that I see is the naming conventions for each const.
Well, that and the bright lime green that I was greeted by when I browsed to http://www.thedailywtf.com. Kind of hurt my eyes; made me say "wtf?" quietly to myself as soon as I saw it[:O]
Admin
What language was this written in? Javascript? LOL
Admin
1760 is the number of yards in a mile.
Admin
But the conversion factor is changing!
http://www.physics.capcollege.bc.ca/oldphys108/kilogram_standard.htm
Admin
Hey - I'm logged in for once. Cool. But quoting's still broken! Gawd, how hard can it be to set this software up?
Admin
I have an explanation. Intellisense.
Admin
This has got to be a joke.
Admin
Admin
Actually, I write quite a bit of floating point code, and I have noticed that a lot of CPU-intensive math algorithms will run quite a bit faster in C/C++ if everything is done in double-precision. At first, I was mystified by this counterintuitive result, but after looking at the disassembly of the compiler-generated code, I realized why: if you use type 'float', C/C++ converts them to double precision every time they are used in a calculation, then converts them back to float to store them in a variable.
Bottom line: now the only time I use float is if I have to allocate a huge array of floating point numbers and want to save some memory.
Admin
You're either using a very odd flavor of compiler or targeting a processor with a different FPU architecture than most. The only time C++ should preform type promotion is if one of the values in the calculation is already a double. Most of the time this is a constant, which default to double precision. For example:
float fHours = fDays / 24.;
will promote fDays to a double, divide by 24, discard the extra precision and shove it into fHours.
float fHours = fDays / 24.f;
will use only float precision math.
Admin
Modern x86 architectures treat float and double exactly the same, because it's internally 64/80 bit operations. The only difference would be in memory bandwidth - a good compiler would just load the float and let the FPU backfill it.
Not all compilers are good and not all architectures are x86, however. Particularly embedded systems/ultra-low-power have terrible performance if you pick the one that isn't its native internal size, 32 or 64. (In which case you'd want to use a fixed-point integer math library anyway.) But that's one of the trade-offs of going to a raw RISC.
Admin
WTF??? You're defining those constants completely wrong!!!
const double Twenty5Point4 = 20/5.4;
const double TwoPoint54 = 1/2.54;
const double Ten = 10.0; // Well, you got this one right, I think...
You also forgot the semi-colons so are you a VB programmer? [:P]
Admin
But then again, if you define constants like this:
What if you decide to use it for a different purpose, instead of doing imperial <-> metric conversions? Say, you decide that there's as many beers in a crate as ten times the amount of centimeters per inch, minus 1.4? That would mean you'd have to change the constant's name everywhere! A more universal way to name this constant would be:
or, less flexible:
I don't think either of both ways is 'better' or the 'best'. It really depends on the spec.
Admin
Will someone please back me up when I say that Katja's picture is reminiscent of Renee Zellweger?
Admin
One does have to be a little careful when writing expressions that should be optimized by the compiler. Integer operations are more likely to reveal the difference between "var * CONST1 / CONST2" and "var * (CONST1 / CONST2)" than floating-point, but the order of operations can be significant to both. Because of that, the compiler generally should not rewrite the former as the latter.
Admin
I am reminded of some classics from a "A Field Guide to Your Unix Sysadmin":
alias kitty cat
alias process_table ps
Admin
Would someone please remind anonimous that comparing a young girl with a FAT ACTRESS is a real WTF too...[:@] I am 186 CM tall and my weight is 61 KG. Definitely not fat...
Admin
Katja: I did not mean the comparison as an insult. BTW, Renee only gained weight for her role in the Bridget Jones films, and possibly for the movie Cold Mountain (a very good movie IMO). In her other films she was not as "plump". I sort of think she's a good actress...if I can admit that. I'm sorry you took the comment as an insult, I meant it more as a compliment.
Oh yeah, being an American I have no idea what 186CM or 61KG equates to. We're on the dewey decimal system over here.
Admin
"We're on the dewey decimal system over here."?
WTF! I hope you're being sarcastic.
Admin
Renee...I mean, Katja...what's it like over there in Amsterdam? That's in Holland/Norway/Netherlands/Sweden right? Pardon my complete ignorance of geography. Are there a lot of programmers over there? Is it cold? What kind of things do you do for fun over there? You know how in Spain they chase bulls? Do you have anything similar? Like horseshoe tossing. Is that the national passtime there? I bet that's fun. One day I would like to visit. And toss horseshoes. I'll have to buy some more winter clothes though. I really want to see those windmills too. Didn't Sandy Duncan film The Sound of Music over there? (Or maybe that was Fiddler on the Roof.) Anyways, let me know what it's like. We are so ignorant of other cultures here in the U.S. It's not our fault though, it's our education system. It kinda sucks. Oh well, chat with you later. -Mike
Admin
Well, according to the post, you need only multiply 186 by One30Pt48th to find out.
Admin
Now that's a WTF... I quoted this post yesterday, and I even checked whether the quote worked, but WTF? It's gone now.
Admin
You never know when the value of one third will change in the future...