One2Pt20462262185th

« Return to Article
  • 2005-01-07 12:48
    <span id="_ctl0_MainContent__ctl0_PostForm_ReplyBody" class="txt4">explination? explin yourself!<br>
    </span>
  • Spaceman Spiff 2005-01-07 12:52
    <P><FONT style="BACKGROUND-COLOR: #efefef">That is the coolest const name EVER</FONT></P>
  • Bellinghman 2005-01-07 12:54
    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.
  • 2005-01-07 12:59
    All that work, and there are STILL magic numbers in it...<br>
    <br>
    <span id="_ctl0_MainContent__ctl0_PostForm_ReplyBody" class="txt4"><pre class="coloredcode"> <span class="kwd">return</span> i*2.54;<br><br>[:)]<br></pre></span><br>
  • 2005-01-07 12:59
    Excelent use of comments<font color="#008000"> </font><font color="#008000">//good commenting</font><br>
  • 2005-01-07 13:05
    <P>Where is the WTF in this?&nbsp; It looks like a perfectly good library for performing unit conversions and geometric calcs.&nbsp; Plus it is fast, since the functions are declared inline.&nbsp; I like the way the constants are named.&nbsp; Personally, I would have defined a couple more:<BR><BR>const double Twenty5Point4 = 25.4<BR>const double TwoPoint54 = 2.54<BR>const double Ten = 10.0<BR><BR>etc.<BR></P>
    <P>&nbsp;</P>
  • 2005-01-07 13:12
    <P>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.</P>
    <P>but those const declarations are a total WTF; maybe he hoped the compiler would calculate those and not&nbsp;the run time?</P>
  • 2005-01-07 13:14
    [:|]&nbsp; Wow!&nbsp; I can see creating the conversions, but having to declare the constants for 1/12 is unacceptable.&nbsp; [:D]<br>
  • 2005-01-07 13:16
    <P>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.<BR></P>
    <P>&nbsp;- Sergio Pereira</P>
  • jesper 2005-01-07 13:18
    <P><FONT style="BACKGROUND-COLOR: #efefef">What's the licensing terms for that code? Cause I could sure use it.</FONT></P>
  • Goudinov 2005-01-07 13:26
    <P>What's next?</P>
    <P><FONT color=#0000ff>function</FONT> ThisFunctionConvertsFeetToInches (Feet) {<BR><FONT color=#008000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//here we go....</FONT><BR>}</P>
  • Gil-Galad 2005-01-07 13:27
    jesper:

    <P><FONT style="BACKGROUND-COLOR: #efefef">What's the licensing terms for that code? Cause I could sure use it.</FONT></P>
    <P>
    </P>
    <P>You would be granted the license for one year and five days.</P>
    <P>const double OneYear5Days = 370.0/365.0&nbsp;&nbsp;&nbsp; //1.01369863</P>
  • 2005-01-07 13:31
    <pre>Moin,<br /><br />While I can see the reason behind the Pi and Deg2Rad/Rad2Dec (I <br />always confuse them myself) definitions, why on earth should one <br />want to have a constant for OneThird? I mean, on what planet is <br />it easier to write OneThird instead of 1./3.? Yet alone <br />One2Pt20462262185th. If you can remember that name, you could as <br />well write 1./2.20462262185. Or is that in case the value of 1./3. <br />should ever change?<br /><br />And why oh why are these variables and functions at all? If the <br />author wanted to make it fast he should've used preprocessor macros.<br /><br />-- <br />Henryk Plötz<br />Grüße aus Berlin</pre>
  • 2005-01-07 13:34
    <SPAN id=_ctl0_MainContent__ctl0_PostForm_PreviewBody>I'm not Isaac's coworker (although my son is named Isaac, an interesting coincidence) but here's an attempt at a justification ...
    <P>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&nbsp;real-time performance requirements.</P>
    <P>Division is often much slower than multiplication, even <EM>with</EM> 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.)</P>
    <P>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".)</P>
    <P align=right>-- Scott</P></SPAN>
  • 2005-01-07 13:36
    <P>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</P>
    <P>&nbsp;</P>
    <P>and/or defends names like "OnePtThreeFourTimesFiveSixSevenEight"</P>
  • 2005-01-07 13:49
    WTF?&nbsp; This&nbsp;makes sense to me!&nbsp; What do you do when the Lbs-&gt;Kgs conversion factor changes?&nbsp; Huh, Mr. Smarty Pants?
  • 2005-01-07 14:00
    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.&nbsp; Am I the only person seeing this?<br>
    <br>
  • alexb 2005-01-07 14:36
    <P>
    :
    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.&nbsp; Am I the only person seeing this?
    </P>
    <P>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&nbsp;defined within the same entry. It's a very elegant and standardized way to handle formatting.</P>
    <P>I mean, seriously, "contaminated", "crap", and "stylesheets" in the same sentence? [^o)]</P>
  • 2005-01-07 14:37
    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.&nbsp; 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.<br>
    <br>
  • 2005-01-07 14:48
    I'm not complaining about you using stylesheets, I'm just baffled as to why your RSS feed doesn't strip them out.<br>
    <br>
    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.&nbsp; Your RSS doesn't have header that defines the stylesheet,
    without with your style tags are pretty useless.&nbsp; So why isn't it
    stripping the style tags and their contents?&nbsp; 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.&nbsp; Strangely
    enough it leaves the &lt;span&gt;&lt;/span&gt; tags alone.<br>
  • JamesCurran 2005-01-07 15:04
    <P>
    Isaac's Father:
    <SPAN id=_ctl0_MainContent__ctl0_PostForm_PreviewBody>And "static_cast" -- never heard of it. </SPAN>
    </P>
    <P>Those lines should look like:</P>
    <P><FONT face="Courier New"><STRONG><SPAN class=kwd>const</SPAN> <SPAN class=kwd>float</SPAN>&nbsp; fDeg2Rad&nbsp;= static_cast&lt;float&gt;(Deg2Rad);</STRONG></FONT></P>
    <P>which is the modern C++ way of saying </P>
    <P><FONT face="Courier New"><STRONG><SPAN class=kwd>const</SPAN> <SPAN class=kwd>float</SPAN>&nbsp; fDeg2Rad&nbsp;= (float)Deg2Rad;</STRONG></FONT></P>
    <P>except, apparently, when Alex posted it, the &lt;float&gt; was taken as embedded HTML and striped from the message.<BR></P>
  • alexb 2005-01-07 15:06
    <P>
    :
    I'm not complaining about you using stylesheets, I'm just baffled as to why your RSS feed doesn't strip them out.<BR><BR>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.&nbsp; Your RSS doesn't have header that defines the stylesheet, without with your style tags are pretty useless.&nbsp; So why isn't it stripping the style tags and their contents?&nbsp; 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.&nbsp; Strangely enough it leaves the &lt;span&gt;&lt;/span&gt; tags alone.<BR>
    </P>
    <P>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.&nbsp;If it's trying to enforce its own styles, it should care to, at least, respect the standard way of handling CSS.</P>
    <P>You shouldn't blame the RSS provider (or any content provider, for that matter) if they're offering you a fully standardized&nbsp;enhanced experience. If your aggregator is misbehaving, you should either re-configure/re-write it, or switch to&nbsp;a better one -- there's a plethora of them out there.</P>
    <P>&nbsp;</P>
  • 2005-01-07 15:21
    <span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;">I think
    this person may not realize that even a crappy compiler will optimize
    out any math between literals.&nbsp; It doesn't change the
    run time speed of a program to just write 1.0/1760 instead of
    One1760th. <br>
    <br>
    I've seen even experienced programmers sometimes unable to grasp this
    concept.&nbsp; 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.&nbsp; If you don't trust your compiler to do that you're
    better off programming in assembly.<br>
    <br>
    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! </span>
  • 2005-01-07 15:27
    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:
    <pre>
    const double CONVERT_INCH_MM = 1.0/25.4;
    </Pre>

    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:
    <pre>
    const double One3Pt785411th = 1.0/3.78644278401;
    </pre>

    which just screams for someone
    to 'fix' it later on.
  • alexb 2005-01-07 16:03
    <P>
    :
    <BR>If you went: <BR>&lt;pre&gt; <BR>const double CONVERT_INCH_MM = 1.0/25.4; <BR>&lt;/Pre&gt; <BR><BR>then your intent is perfectly clear without the need for comments. <BR>
    </P>
    <P>"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.</P>
    <P>I think CENTIMETERS_PER_INCH, INCHES_PER_CENTIMETER&nbsp;(or any variant of those) would be a very decent set of constant names for this purpose.</P>
    <P>&nbsp;</P>
  • Jokke 2005-01-07 16:54
    Goudinov:
    <p>What's next?</p>
    <p><font color="#0000ff">function</font> ThisFunctionConvertsFeetToInches (Feet) {<br><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//here we go....</font><br>}</p>
    <br>
    <br>
    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] <br>
  • memorex 2005-01-07 17:25
    <P>'I've seen even experienced programmers sometimes unable to grasp this concept.&nbsp; I've heard some excuses like "I don't trust the compiler,"'</P>
    <P>Which brings me to pet peeves of mine: </P>
    <UL>
    <LI>people not understanding what the compiler will generate&nbsp;</LI>
    <LI>people who can't read enough assembly to SEE what the compiler generates&nbsp; </LI>
    <LI>people who -assume- that X technique is faster because someone somewhere told them it was</LI>
    <LI>people who don't understand that gaining a couple clock ticks enhancement is pointless when we're waiting -minutes- for a query to return...</LI></UL>
  • Jacob K 2005-01-07 17:43
    The WTF that I see is the naming conventions for each const.<br>
    <br>
    <br>
    <br>
    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] <br>
  • 2005-01-07 17:47
    What language was this written in? Javascript? LOL
  • brandonh6k 2005-01-07 18:25
    <P>
    what exactly does 1/1760 signify?
    </P>
    <P>1760 is the number of yards in a mile.</P>
  • JoeNotCharles 2005-01-07 18:52
    :
    WTF?&nbsp; This&nbsp;makes sense to me!&nbsp; What do you do when the Lbs-&gt;Kgs conversion factor changes?&nbsp; Huh, Mr. Smarty Pants?


    But the conversion factor *is* changing!

    http://www.physics.capcollege.bc.ca/oldphys108/kilogram_standard.htm
  • JoeNotCharles 2005-01-07 18:55
    Hey - I'm logged in for once. Cool. But quoting's still broken! Gawd, how hard can it be to set this software up?
  • 2005-01-07 19:25
    I have an explanation. Intellisense.
  • 2005-01-07 19:43
    This has *got* to be a joke.<br>
  • 2005-01-08 10:18
    :
    <br>
    Plus it is fast, since the functions are declared inline.<br>
    <br>
    <pre class="coloredcode"><span class="kwd">I hope this comment is sarcastic, because things like "const</span> <span class="kwd">double</span> &amp;cm" as a parameter definition can be so bad for performance...<br><br></pre>
    <br>
    <br>
  • 2005-01-08 10:42
    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.&nbsp; At
    first, I was mystified by this counterintuitive result, but after
    looking at the disassembly of the compiler-generated code, I realized
    why:&nbsp; 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.<br>
    <br>
    Bottom line:&nbsp; 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.<br>
  • 2005-01-08 12:31
    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:<br>
    float fHours = fDays / 24.;<br>
    will promote fDays to a double, divide by 24, discard the extra precision and shove it into fHours.<br>
    float fHours = fDays / 24.f;<br>
    will use only float precision math.<br>
  • foxyshadis 2005-01-08 18:04
    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.<br>
    <br>
    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.<br>
  • Katja 2005-01-10 04:31
    :
    <p>Where is the WTF in this?&nbsp; It looks like a
    perfectly good library for performing unit conversions and geometric
    calcs.&nbsp; Plus it is fast, since the functions are declared
    inline.&nbsp; I like the way the constants are named.&nbsp; Personally,
    I would have defined a couple more:<br><br>const double Twenty5Point4 = 25.4<br>const double TwoPoint54 = 2.54<br>const double Ten = 10.0<br><br>etc.<br></p>
    <p>&nbsp;</p>
    <br>
    <br>
    WTF??? You're defining those constants completely wrong!!!<br>
    <br>
    const double Twenty5Point4 = 20/5.4;<br>
    const double TwoPoint54 = 1/2.54;<br>
    const double Ten = 10.0; // Well, you got this one right, I think...<br>
    <br>
    You also forgot the semi-colons so are you a VB programmer? [:P]<br>
  • aapopfriets 2005-01-10 09:57
    But then again, if you define constants like this:<br>
    <br>
    
    const double&nbsp;&nbsp; CentimeterPerInch = 2.54;<br>
    <br>
    What if you decide to use it for a different purpose, instead of doing
    imperial &lt;-&gt; 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:<br>
    <br>
    
    const double&nbsp;&nbsp; TwoPointFiftyFour = 2.54;<br>
    <br>
    or, less flexible:<br>
    <br>
    
    const double&nbsp;&nbsp; CentimeterPerInchAndOneTenthOfTheAmountOfBottlesInACrateOfTwentyFourPlusOnePointFour = 2.54<br>
    <br>
    I don't think either of both ways is 'better' or the 'best'. It really depends on the spec.<br>
  • 2005-01-10 10:34
    Will someone <STRONG>please</STRONG> back me up when I say that Katja's picture is reminiscent of Renee Zellweger?
  • 2005-01-10 10:42
    One does have to be a little careful when writing expressions that
    should be optimized by the compiler.&nbsp; 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.&nbsp; Because of
    that, the compiler generally should not rewrite the former as the
    latter.<br>
  • 2005-01-10 11:39
    I am reminded of some classics from a "A Field Guide to Your Unix Sysadmin":

    <p>
    <ul>
    <li> <code>alias kitty cat</code>
    <li> <code>alias process_table ps</code>
    </ul>

  • Katja 2005-01-10 13:44
    <P>
    :
    Will someone <STRONG>please</STRONG> back me up when I say that Katja's picture is reminiscent of Renee Zellweger?
    </P>
    <P>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...</P>
  • 2005-01-10 14:51
    <P>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.</P>
    <P>Oh yeah, being an American I have no idea what 186CM or 61KG equates to. We're on the dewey decimal system over here.</P>
  • 2005-01-10 15:00
    "We're on the dewey decimal system over here."?<br>
    <br>
    WTF!&nbsp; I hope you're being sarcastic.<br>
    <br>
  • 2005-01-10 15:18
    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
  • argyle 2005-01-10 16:20
    :

    <p>Oh yeah, being an American I have no idea what 186CM or 61KG equates to. <br>
    </p>
    <br>
    <br>
    Well, according to the post, you need only multiply 186 by One30Pt48th to find out.<span class="cmt"></span><span class="kwd"></span><br>
  • 2005-01-12 03:51
    :
    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
    <br>
    <br>
    Now that's a WTF... I quoted this post yesterday, and I even checked whether the quote worked, but WTF? It's gone now.<br>
  • 2005-01-12 05:43
    While I can see the reason behind the Pi and Deg2Rad/Rad2Dec (I <br>
    always confuse them myself) definitions, why on earth should one <br>
    want to have a constant for OneThird?
    <br>
    <br>
    You never know when the value of one third will change in the future...<br>
  • alphonsebrown 2005-05-12 04:59
    <P>
    alphonsebrown:
    While I can see the reason behind the Pi and Deg2Rad/Rad2Dec (I <BR>always confuse them myself) definitions, why on earth should one <BR>want to have a constant for OneThird?
    <BR><BR>You never know when the value of one third will change in the future...<BR>
    </P>
    <P>I agree it can change - "the number theory" is not a constant in my opinion also Katja seems very nice and those 186/61 are just the perfect measures and if she keeps it constant - I'll marry her =)))</P>
  • ... 2005-05-12 08:07
    Anonymous:
    While I can see the reason behind the Pi and Deg2Rad/Rad2Dec (I <br>
    always confuse them myself) definitions, why on earth should one <br>
    want to have a constant for OneThird?
    <br>
    <br>
    You never know when the value of one third will change in the future...<br>
    <br>
    Sigh. It has been pointed out already that x/3 is far slower than
    x*oneThird. This is basic optimisation folks, if you divide by a
    constant a lot then you should get its inverse once and then multiply
    by that. Of course that doesn't excuse the horrible names and pintless
    calculations when you are writing the value in the comment anyway.<br>
  • curtisk 2005-05-12 10:49
    Anonymous:
    <p>*snip*</p>
    <p>Oh yeah, being an American I have no idea what 186CM or 61KG equates to. We're on the dewey decimal system over here.</p>
    <br>
    <br>
    Man, that was funny! LOL<br>
  • Maarx 2010-01-11 22:48
    I can explain every single one of those constants in three words.

    Tab Auto Complete.
  • Melinda Gordon 2010-06-10 07:34
    While I can see the spirit of the code...I think the ghost whisper is calling you to cross over...
  • cindy 2011-03-02 09:45
  • Cousj001 2011-11-18 15:03
    I'll admit to haven written code much like this. While my name perhaps made a little more sense (similar to
    double InchesToCentimetres = 1/2.54; 
    ) I do have a large file of constants like this. However, it is just a library, in perhaps a more traditional sense - I 'borrow' code from it that I actually need into programs that need it, and have it in their files, or at least a library just to go with that application that includes the necessary ones, since I can't see any programs that will be requiring the Euler-Mascheroni constant any time soon. At least if I do have to put in something, I won't have to look it up again.