Comment On One2Pt20462262185th

I believe that we may have had a first yesterday; the coder behind yesterday's post offered a perfectly reasonable explanation: one-time use with a tight deadline. Fair enough. Now I really want to see Isaac's coworker offer some sort of explanation for this ... seriously ... .coloredcode .cmt{ COLOR: #009900} .coloredcode .cmtg{ COLOR: #666} .coloredcode .st{ COLOR: #f00} .coloredcode .kwdt{ COLOR: #666} .coloredcode .kwd{ COLOR: #00f} .coloredcode .attr{ COLOR: #f00} .coloredcode .attrv{ COLOR: #00f} .coloredcode .ec{ COLOR: #00f} .coloredcode .tag{ COLOR: #800000} .coloredcode .dir{ BACKGROUND: #feff22;COLOR: #000} .coloredcode .sel{ COLOR: #800000} .coloredcode .val{ COLOR: #00f} .coloredcode .unit{ COLOR: #800000} .coloredcode .sqlcmt{ COLOR: #008080} .coloredcode .sqlkwd{ COLOR: #00f} .coloredcode .sqlkwd2{ COLOR: #f0f} .coloredcode .sqlkwd3{ COLOR: #999} .coloredcode .sqlkwd4{ COLOR: #800000} .coloredcode .num{ COLOR: #00f} .coloredcode .sqlst{ COLOR: #008000} [expand full text]
« PrevPage 1 | Page 2Next »

Re: One2Pt20462262185th

2005-01-07 12:48 • by
explination? explin yourself!

Re: One2Pt20462262185th

2005-01-07 12:52 • by Spaceman Spiff

That is the coolest const name EVER

Re: One2Pt20462262185th

2005-01-07 12:54 • by Bellinghman
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.

Re: One2Pt20462262185th

2005-01-07 12:59 • by
All that work, and there are STILL magic numbers in it...



 return i*2.54;

[:)]


Re: One2Pt20462262185th

2005-01-07 12:59 • by
Excelent use of comments //good commenting

Re: One2Pt20462262185th

2005-01-07 13:05 • by

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.


 

Re: One2Pt20462262185th

2005-01-07 13:12 • by

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?

Re: One2Pt20462262185th

2005-01-07 13:14 • by
[:|]  Wow!  I can see creating the conversions, but having to declare the constants for 1/12 is unacceptable.  [:D]

Re: One2Pt20462262185th

2005-01-07 13:16 • by
27478 in reply to 27474

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

Re: One2Pt20462262185th

2005-01-07 13:18 • by jesper

What's the licensing terms for that code? Cause I could sure use it.

Re: One2Pt20462262185th

2005-01-07 13:26 • by Goudinov
27480 in reply to 27479

What's next?


function ThisFunctionConvertsFeetToInches (Feet) {
      //here we go....
}

Re: One2Pt20462262185th

2005-01-07 13:27 • by Gil-Galad
27481 in reply to 27479
jesper:

What's the licensing terms for that code? Cause I could sure use it.



You would be granted the license for one year and five days.


const double OneYear5Days = 370.0/365.0    //1.01369863

Re: One2Pt20462262185th

2005-01-07 13:31 • by
Moin,

While I can see the reason behind the Pi and Deg2Rad/Rad2Dec (I
always confuse them myself) definitions, why on earth should one
want to have a constant for OneThird? I mean, on what planet is
it easier to write OneThird instead of 1./3.? Yet alone
One2Pt20462262185th. If you can remember that name, you could as
well write 1./2.20462262185. Or is that in case the value of 1./3.
should ever change?

And why oh why are these variables and functions at all? If the
author wanted to make it fast he should've used preprocessor macros.

--
Henryk Plötz
Grüße aus Berlin

Re: One2Pt20462262185th

2005-01-07 13:34 • by
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

Re: One2Pt20462262185th

2005-01-07 13:36 • by

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"

Re: One2Pt20462262185th

2005-01-07 13:49 • by
WTF?  This makes sense to me!  What do you do when the Lbs->Kgs conversion factor changes?  Huh, Mr. Smarty Pants?

RSS feed

2005-01-07 14:00 • by
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?



Re: RSS feed

2005-01-07 14:36 • by alexb
27492 in reply to 27488

:
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?


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)]

Re: One2Pt20462262185th

2005-01-07 14:37 • by
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.



Re: RSS feed

2005-01-07 14:48 • by
27494 in reply to 27492
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.

Re: One2Pt20462262185th

2005-01-07 15:04 • by JamesCurran
27495 in reply to 27485

Isaac's Father:
And "static_cast" -- never heard of it.


Those lines should look like:


const float  fDeg2Rad = static_cast<float>(Deg2Rad);


which is the modern C++ way of saying


const float  fDeg2Rad = (float)Deg2Rad;


except, apparently, when Alex posted it, the <float> was taken as embedded HTML and striped from the message.

Re: RSS feed

2005-01-07 15:06 • by alexb
27496 in reply to 27494

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


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.


 

Re: One2Pt20462262185th

2005-01-07 15:21 • by
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!

Re: One2Pt20462262185th

2005-01-07 15:27 • by
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:

const double CONVERT_INCH_MM = 1.0/25.4;


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:

const double One3Pt785411th = 1.0/3.78644278401;


which just screams for someone
to 'fix' it later on.

Re: One2Pt20462262185th

2005-01-07 16:03 • by alexb
27501 in reply to 27499

:

If you went:
<pre>
const double CONVERT_INCH_MM = 1.0/25.4;
</Pre>

then your intent is perfectly clear without the need for comments.


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


 

Re: One2Pt20462262185th

2005-01-07 16:54 • by Jokke
27502 in reply to 27480
Goudinov:

What's next?


function ThisFunctionConvertsFeetToInches (Feet) {
      //here we go....
}





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]

Re: One2Pt20462262185th

2005-01-07 17:25 • by memorex
27503 in reply to 27497

'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:



  • people not understanding what the compiler will generate 

  • people who can't read enough assembly to SEE what the compiler generates 

  • people who -assume- that X technique is faster because someone somewhere told them it was

  • people who don't understand that gaining a couple clock ticks enhancement is pointless when we're waiting -minutes- for a query to return...

Re: One2Pt20462262185th

2005-01-07 17:43 • by Jacob K
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]

Re: One2Pt20462262185th

2005-01-07 17:47 • by
What language was this written in? Javascript? LOL

Re: One2Pt20462262185th

2005-01-07 18:25 • by brandonh6k
27508 in reply to 27499

what exactly does 1/1760 signify?


1760 is the number of yards in a mile.

Re: One2Pt20462262185th

2005-01-07 18:52 • by JoeNotCharles
27509 in reply to 27487
:
WTF?  This makes sense to me!  What do you do when the Lbs->Kgs conversion factor changes?  Huh, Mr. Smarty Pants?


But the conversion factor *is* changing!

http://www.physics.capcollege.bc.ca/oldphys108/kilogram_standard.htm

Re: One2Pt20462262185th

2005-01-07 18:55 • by JoeNotCharles
27510 in reply to 27509
Hey - I'm logged in for once. Cool. But quoting's still broken! Gawd, how hard can it be to set this software up?

Re: One2Pt20462262185th

2005-01-07 19:25 • by
I have an explanation. Intellisense.

Re: One2Pt20462262185th

2005-01-07 19:43 • by
This has *got* to be a joke.

Re: One2Pt20462262185th

2005-01-08 10:18 • by
27514 in reply to 27474
:


Plus it is fast, since the functions are declared inline.



I hope this comment is sarcastic, because things like "const double &cm" as a parameter definition can be so bad for performance...






Re: One2Pt20462262185th

2005-01-08 10:42 • by
27515 in reply to 27497
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.

Re: One2Pt20462262185th

2005-01-08 12:31 • by
27516 in reply to 27515
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.

Re: One2Pt20462262185th

2005-01-08 18:04 • by foxyshadis
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.

Re: One2Pt20462262185th

2005-01-10 04:31 • by Katja
27526 in reply to 27474
:

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.


 





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]

Re: One2Pt20462262185th

2005-01-10 09:57 • by aapopfriets
27530 in reply to 27526
But then again, if you define constants like this:



const double   CentimeterPerInch = 2.54;



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:



const double   TwoPointFiftyFour = 2.54;



or, less flexible:



const double   CentimeterPerInchAndOneTenthOfTheAmountOfBottlesInACrateOfTwentyFourPlusOnePointFour = 2.54



I don't think either of both ways is 'better' or the 'best'. It really depends on the spec.

Re: One2Pt20462262185th

2005-01-10 10:34 • by
Will someone please back me up when I say that Katja's picture is reminiscent of Renee Zellweger?

Re: One2Pt20462262185th

2005-01-10 10:42 • by
27538 in reply to 27497
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.

Re: One2Pt20462262185th

2005-01-10 11:39 • by
I am reminded of some classics from a "A Field Guide to Your Unix Sysadmin":



  • alias kitty cat
  • alias process_table ps


Re: One2Pt20462262185th

2005-01-10 13:44 • by Katja
27553 in reply to 27536

:
Will someone please back me up when I say that Katja's picture is reminiscent of Renee Zellweger?


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

Re: One2Pt20462262185th

2005-01-10 14:51 • by
27560 in reply to 27553

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.

Re: One2Pt20462262185th

2005-01-10 15:00 • by
27563 in reply to 27560
"We're on the dewey decimal system over here."?



WTF!  I hope you're being sarcastic.



@ Katja, re: Amsterdam

2005-01-10 15:18 • by
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

Re: One2Pt20462262185th

2005-01-10 16:20 • by argyle
27574 in reply to 27560
:

Oh yeah, being an American I have no idea what 186CM or 61KG equates to.





Well, according to the post, you need only multiply 186 by One30Pt48th to find out.

Re: @ Katja, re: Amsterdam

2005-01-12 03:51 • by
27722 in reply to 27569
:
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




Now that's a WTF... I quoted this post yesterday, and I even checked whether the quote worked, but WTF? It's gone now.

Re: One2Pt20462262185th

2005-01-12 05:43 • by
27725 in reply to 27482
While I can see the reason behind the Pi and Deg2Rad/Rad2Dec (I

always confuse them myself) definitions, why on earth should one

want to have a constant for OneThird?




You never know when the value of one third will change in the future...

« PrevPage 1 | Page 2Next »

Add Comment