• (cs) in reply to BiggBru
    BiggBru:

    Wow, whatever happened to people just going "You're wrong, and here's why..." Must we resort to name calling and flaming? And very thinly veiled, passive-aggressive sarcasm? Reading this forum should not bring images of "UFC'S Greatest Knockouts" to mind.

    Taking that chill pill sounds like a great idea...



    <font size="2">Sorry, but I do maintain more or less such code. so having someone defending it makes me thinly weiledly passivly agressivly sarcastic or however you say it in English. and as far as I am concerned - sometimes only a good knockout might bring someone to the path of rightneousness. ;) </font>
  • (cs) in reply to CornedBee

    Amen, Brother!!

  • (cs) in reply to Xarium
    Xarium:

    Here's a review of real world math libraries; there are 2 types; deterministic & non-deterministic.  A non-deterministic library is one that makes no guarantees about execution speed, it can't even guarantee that a function will complete in finite time (though it's a pretty poor library that stalls completely) - this type of library generally ships as the default with compilers, they are useful for simple things like sin, log etc. A deterministic library makes a guarantee about the execution speed of every function (even the trickier ones like acos, pow etc), and this is extremely important for games, banks, astronomy, databases and just about anything that matters - default math libraries are rarely used in places that matter.


    <font size="2">Is anyone as much interested as I am where does Xarium take his wisdom from? Xarium please share. I am really anxious to know.

    </font>
  • saltine (unregistered) in reply to niushiko

    If he needed those constants, then why didn't he put them directly in the functions?

    inline double Meters2Inches( const double &m )  { return m*( 1.0 / 0.0254 ); }
  • saltine (unregistered) in reply to saltine

    oops

    inline double Meters2Inches( const double &m ) { return m*( 1.0 / 0.0254 ); }

  • Anonymous (unregistered) in reply to niushiko

    I really need to throw in my $0.02... The code is funny - but it must be pretty fast.

    1. "inline double CM2MM( const double &cm )" is a pass by reference which is C++ only (that little &). So this can't be C.

    2. All the constants are divisions, so comments like "he didn't even use the constants for 2.54" are just silly.

    3. This is obviously built for speed... Has anyone wondered that this code really smells like Find & replace or a tiny shell script
    If he started off with a file full of lines like: mm -> inches 1.0/25.4 0.0393700787401575 it takes about 4 lines of linux shell code to convert it to the double declarations, replacing "1.0/" by "One", "." by "Pt", adding "th = " at end, does most of the work.

    Doing it like this is a lot faster to code than using descriptive names for everything.

  • (cs) in reply to saltine

    <font size="2">At least he... um... formatted it nicely?  (Where's a code reviewer when you need one?)


    </font>

  • Jay (unregistered) in reply to murphyman

    Yeah, this is C++, not C.

    And not entirely bad.  My guess is that all the things that are intended to be exposed -- the conversion functions -- have reasonable names while the things that are not intended to be exposed -- the constants -- have tortuous names that are unlikely to collide with anything a programmer using what this provides might dream up.

    The practice of making constants manifest as some sort of symbol makes sense -- when you use the values more than once.  I can't see that this is the case here, but it's a common practice.

    Limiting the scope of the constants to the file in which they're needed might be considered -- unless one wants to protect against another value of, for instance, Pi fr,p being defined.  (Although there's not much chance of another One2Pt20462262185th showing up at the party, is there?)

  • dok (unregistered)

    I can tell you exactly how this happened. It's required by the coding standards imposed by a misguided IT manager. "There will be no hard-coded values anywhere in the code." You have to create constants for every number and string. The rationale is that you need to be able to change the variable's value globally.

    If your code was evaluated with rules-based code review software including this rule, and your coding quality was assessed based on the number of points racked up for breaking the inflexible rules, you'd end up with this madness.

  • (cs) in reply to niushiko
    niushiko:
    ...<font size="2"> where does Xarium take his wisdom from? </font>

    [|-)]

    <font size="2">
    But I'm still waiting for your rebuttal.  Abuse doesn't count.

    </font>

  • (cs) in reply to Xarium
    Xarium:
    niushiko:
    ...<font size="2"> where does Xarium take his wisdom from? </font>

    <font size="2">But I'm still waiting for your rebuttal.  Abuse doesn't count.
    </font>


    that's not quite the answer to the question I asked. I do not even have to remind it. it's quoted above.

    I do not think I have to rebut anything. I said what I wanted to say. and maybe if you try to read it you will get it. I really appreciate your knowledge on C/C++ - I always admired people who could remember all detail about how it works were in what conditions,  I am simply disagreeing (whatever you spell it) with your defence over stupid constants names.

    get over me... and tell me in what 'real world' they call libraries deterministic and non-deterministic. where do they name constant like that. where do they let you write such code. I just simply do not want to get somewhere I won't belong in the future.
  • (cs) in reply to niushiko
    niushiko:
    BiggBru:

    Wow, whatever happened to people just going "You're wrong, and here's why..." Must we resort to name calling and flaming? And very thinly veiled, passive-aggressive sarcasm? Reading this forum should not bring images of "UFC'S Greatest Knockouts" to mind.

    Taking that chill pill sounds like a great idea...



    <FONT size=2>Sorry, but I do maintain more or less such code. so having someone defending it makes me thinly weiledly passivly agressivly sarcastic or however you say it in English. and as far as I am concerned - sometimes only a good knockout might bring someone to the path of rightneousness. ;) </FONT>

    Hey, it's all good. I'm still in school (CS major), and have not made it to the IT ranks just yet. Needless to say, I don't have to maintain anybody else's mess. Maybe the code brought up flashbacks of a past traumatic experience, pushing you to the brink of openin' up a good ole can of whoop'ass.

    Or maybe I've just spent too much time studying the finer points of Psychology and overanalyzed the situation. [:P]

  • (cs) in reply to Anonymous

    Anonymous:
    I really need to throw in my $0.02... The code is funny - but it must be pretty fast.

    1. "inline double CM2MM( const double &cm )" is a pass by reference which is C++ only (that little &). So this can't be C.

    2. All the constants are divisions, so comments like "he didn't even use the constants for 2.54" are just silly.

    3. This is obviously built for speed... Has anyone wondered that this code really smells like Find & replace or a tiny shell script
    If he started off with a file full of lines like: mm -> inches 1.0/25.4 0.0393700787401575 it takes about 4 lines of linux shell code to convert it to the double declarations, replacing "1.0/" by "One", "." by "Pt", adding "th = " at end, does _most_ of the work. Doing it like this is a lot faster to code than using descriptive names for everything.

    Nice. I think you've come the closest to explaining what was really going on through the coder's mind. Let's think about this for a second: Nobody in their right mind would use constant names that are actually HARDER to remember and retype unless they had an ulterior motive. It's not like he was just lazy and named his constants A, B, C and so on.

    It is possible that this code, within its context, is not a terrible WTF. While one could argue that every single post here in the Daily WTF is taken out of context, this one is just too bizarre to be a result of sheer ignorance.

    While we are only allowed to see one tree, a forest can be inferred.

  • (cs) in reply to BiggBru
    BiggBru:

    Hey, it's all good. I'm still in school (CS major), and have not made it to the IT ranks just yet. Needless to say, I don't have to maintain anybody else's mess. Maybe the code brought up flashbacks of a past traumatic experience, pushing you to the brink of openin' up a good ole can of whoop'ass.

    Or maybe I've just spent too much time studying the finer points of Psychology and overanalyzed the situation. [:P]



    <font size="2">yeah... once upon a time I, too, was at the univ and I thought the programmers community couldn't do as much crap as we are doing (I, myslef, can also be ashamed of a few of my inventions) but... unfortunatelly... yup... I am traumatized... and this code- </font><font size="2">esspecially the </font><font size="2">constants- remind me of this trauma.... ;)</font>
  • (cs)

    This code is simply bad. I mean very-very ugly and probably totally useless. CPU time, memory savings .. etc can't really justifies these constant "names", not even that example a few comments before mine. The division-multiplication debate makes a difference, but we're not in '90, when assembly was very popular.. even "embedded systems" are smarter than this. And this is a wtf because nowadays any compiler would change the pi/2 into 1.570796.. as long as it can fit into the varible of that type. And someone before me pointed out that this code must be C++, and there are a lots of good compilers for C++, and that's not just an urband legend ;]

    and happy new year :P

  • (cs) in reply to Dan
    Anonymous:
    It would be more readable to say  piOverTwo rather than 1.570795 and it would be faster than  pi/2.  Do the calculations once.

    Some of the other stuff is reasonable as well, like the conversion functions (if they're not already avaiable). But

    <font>"const</font> <font>double</font> One63360th     = 1.0/63360.0;" makes NO SENSE!



    There are 63360 inches in a mile.  The names are so horrible that it is difficult to make the connection.  I tried factorising and got suspicious when I saw 88 as the number remaining to factor.  If I had not factored out the threes, I would not have caught it.

    Sincerely,

    Gene Wirchenko

  • (cs) in reply to GoatCheez
    GoatCheez:
    I really do not see this as that bad. It's obviously C. The conversion functions are labled inline. If someone needed a full and fast basic unit conversion library, this would do it. The const variable names sucks, but awell. Is it just me? Am I missing something?


    Yes, I was the retard who tried to say this was C when it's "obviously" (lol) C++, prompting every other post to point that out. I need to be taken out back and shot. My B. :-/
  • Stan (unregistered)

    How did this get by:

    <font>inline double</font> Inches2KM( <font>const</font> <font>double</font> &i )      { <font>return</font> i*.0000254; }

    without a constant ohpointohohohohtwofivefour?

  • (cs) in reply to niushiko
    niushiko:
    ... and maybe if you try to read it you will get it. ... I am simply disagreeing (whatever you spell it) with your defence over stupid constants names.

    I've read your posts, yet you obviously haven't read mine.  Where do I defend the constant names (please quote me specifically defending the constant names)?
    Yep, I agree, they are a little strange, but that's it.  No big deal.
    You're making out like this is the worst code in the world - and that tells me you haven't seen any real world code. 
    You are ignorant, you were noticed and you cannot admit it.

    niushiko:
    ... tell me in what 'real world' they call libraries deterministic and non-deterministic. where do they name constant like that. where do they let you write such code. I just simply do not want to get somewhere I won't belong in the future.

    By your own admission you write only Java, therefore, you've had no experience with implementing real world math libraries - your world is very small, don't assume everybody's is.

  • Raw (unregistered) in reply to japh

    "Defending this code with numbers of how many CPU cycles are spent on different things on an Intel CPU? Does anyone know for sure it is meant to run on an Intel CPU?"

    It doesn't really matter if it is an Intel or not (btw, Intel make lots of other CPUs, not only x86), I've yet to see a CPU that does division faster than multiplication. I'm sure someone can dig up there pet Über-divider-CPU, but it is a fair assumption that you gain speed by removing unnecessary divisions.

    "Does anyone know if the code will run millions of times per second so that it actually makes a difference?"

    If it does, the code makes sense. Why assume everybody are idiots just because it is usually true?

    "Did anyone benchmark this code and see that it will actually be faster?"

    We need the complete program for a sensible benchmark, but it will be faster. If it is a noticeable and important difference is a completely different question.

    "Premature optimization is a favourite passtime for a lot of people who have once learned a little bit more about how a CPU works. It seldom does what they expect, or at least not as much."

    How do you know it is premature? Perhaps it is a response to performance problems?

    "Still, they gladly make the most bizarre code just because "it's faster" or "saves bytes"."

    Try programming for embedded control systems and you'll see exactly how important 'faster' and 'save bytes' can be...

    "Then again, if seeing this code gets you thinking about CPU cycles instead of the horrible constant names, then maybe there's no point in arguing..."

    I agree about the naming, it could be better. Also, if these constants are needed in a tight loop, I would prefer to define them just before the loop to keep things together.

  • (cs) in reply to Xarium
    Xarium:
    niushiko:
    ... and maybe if you try to read it you will get it. ... I am simply disagreeing (whatever you spell it) with your defence over stupid constants names.

    I've read your posts, yet you obviously haven't read mine.  Where do I defend the constant names (please quote me specifically defending the constant names)?
    Yep, I agree, they are a little strange, but that's it.  No big deal.
    You're making out like this is the worst code in the world - and that tells me you haven't seen any real world code. 
    You are ignorant, you were noticed and you cannot admit it.

    niushiko:
    ... tell me in what 'real world' they call libraries deterministic and non-deterministic. where do they name constant like that. where do they let you write such code. I just simply do not want to get somewhere I won't belong in the future.

    By your own admission you write only Java, therefore, you've had no experience with implementing real world math libraries - your world is very small, don't assume everybody's is.


    <font size="2">
    I am ignorant! I admit it!
    In my small world 'deterministic' means the opposite of stochastic. and those libraries of which you are talking are called 'dedicated'. I assume that one needs those 'dedicated/deterministic' libraries, not only for the reasons of the speed, but also the acurracy of the calculations. I have actually implemented a library to numeric calculations and it was done in C, but... yeah... that was not a real world. it was my own small world where we- only Java experienced-  assume that people could make use of our code. that's why we like to give names that mean something. that's why if we create a constant we use it afterwards. but hey... that's just my small world. and </font><font size="2">I am ignorant! I admit it!
    does this make you feel better? or maybe you want to insult me some more because I deffinitely don't like some parts this code? maybe you have a problem of low self-esteem, if you felt so offended by what I wrote? or maybe... maybe it's because I am a woman?...
    whatever it is </font><font size="2">I am ignorant! I admit it!
    happy?</font>
  • (cs) in reply to niushiko
    niushiko:
    Xarium:
    niushiko:
    ... and maybe if you try to read it you will get it. ... I am simply disagreeing (whatever you spell it) with your defence over stupid constants names.

    I've read your posts, yet you obviously haven't read mine.  Where do I defend the constant names (please quote me specifically defending the constant names)?
    Yep, I agree, they are a little strange, but that's it.  No big deal.
    You're making out like this is the worst code in the world - and that tells me you haven't seen any real world code. 
    You are ignorant, you were noticed and you cannot admit it.

    niushiko:
    ... tell me in what 'real world' they call libraries deterministic and non-deterministic. where do they name constant like that. where do they let you write such code. I just simply do not want to get somewhere I won't belong in the future.

    By your own admission you write only Java, therefore, you've had no experience with implementing real world math libraries - your world is very small, don't assume everybody's is.


    <font size="2">
    I am ignorant! I admit it!
    In my small world 'deterministic' means the opposite of stochastic. and those libraries of which you are talking are called 'dedicated'. I assume that one needs those 'dedicated/deterministic' libraries, not only for the reasons of the speed, but also the acurracy of the calculations. I have actually implemented a library to numeric calculations and it was done in C, but... yeah... that was not a real world. it was my own small world where we- only Java experienced-  assume that people could make use of our code. that's why we like to give names that mean something. that's why if we create a constant we use it afterwards. but hey... that's just my small world. and </font><font size="2">I am ignorant! I admit it!
    does this make you feel better? or maybe you want to insult me some more because I deffinitely don't like some parts this code? maybe you have a problem of low self-esteem, if you felt so offended by what I wrote? or maybe... maybe it's because I am a woman?...
    whatever it is </font><font size="2">I am ignorant! I admit it!
    happy?</font>



    ooooh look.    A cat fight... 
  • (cs) in reply to niushiko
    niushiko:
    Xarium:


    <font size="2">
     
    How about you both chill down a bit and drop the provocative attitude?

    The thing about the "deterministic libraries" makes perfect sense to me, even the name (guaranteed running times = deterministic) though I doubt the claim that banks care about guaranteed running times except in a few very specialized applications, namely stock brokering.

    But it really doesn't have anything to do with the criticism of this code. which is mainly for the really, really bad variable names.
    </font>
  • (cs) in reply to anon
    Anonymous:

    Besides, if a constant is named after its value, the programmer might as well write out the number. That is why this is a `WTF'.


    Not entirely. A constant named after its value is still a LOT better than using that value everywhere. If you mistype the name, you'll get a compiler error rather than a wrong value at runtime.
  • (cs) in reply to brazzy
    brazzy:
    Anonymous:

    Besides, if a constant is named after its value, the programmer might as well write out the number. That is why this is a `WTF'.


    Not entirely. A constant named after its value is still a LOT better than using that value everywhere. If you mistype the name, you'll get a compiler error rather than a wrong value at runtime.


    It's like half a wheel.
  • csrster (unregistered) in reply to murphyman
    murphyman:
    BiggBru:

    Wow, whatever happened to people just going "You're wrong, and here's why..." Must we resort to name calling and flaming? And very thinly veiled, passive-aggressive sarcasm?

    You must be new here.


    That's "You must be new here, you moron", you idiot!
  • alexr (unregistered) in reply to mlk

    Floating-point math includes exception handling and state bits that indicate the result of prior operations. For example, look at the INEXACT flag in most processors.

    As a result of the need to keep this meta state 100% correct for some numerical computations, compilers often do not fold floating-point computations at compile-time. If they do, they often provide a flag to prevent them from doing so.

    Consider another well-known example: a != a. Surely a is always equal to itself, right? Not so with IEEE-754 floating point numbers. a may be a NaN (Not a Number) value, which for the purposes of comparison is not equal to itself. Older versions (if not current -- I haven't regressed this) of Microsoft Visual C++ would always incorrectly eliminate this comparison.

    I suggest everybody here hunt down and read Goldberg's "What Every Computer Scientist Should Know About Floating-Point Arithmetic."

  • Wing (unregistered) in reply to alexr

    Think someone should break it to the guy that 1900 was not a leap year?
    http://en.wikipedia.org/wiki/Leap_years

  • (cs) in reply to csrster
    Anonymous:
    murphyman:
    BiggBru:

    Wow, whatever happened to people just going "You're wrong, and here's why..." Must we resort to name calling and flaming? And very thinly veiled, passive-aggressive sarcasm?

    You must be new here.


    That's "You must be new here, you moron", you idiot!

    More like "You must be new to the internet"

  • Alexander (unregistered)

    Cool! Is it GPL? Can I use this?

  • (cs)

    Apologies if someone already said this...

    but shouldn't the various items reference one another?  He makes a good start by defining and then using pi, but isn't OneThirtysixth equivalent to OneTwelfth / 3.0?  Or OneTwelfth * OneThird?  What if he needed to change one of the basic factors, like define OneThird as 1/4?  He'd have to edit every line item...

  • yin (unregistered) in reply to GalacticCowboy

    This exactly shows the author's lazyness. I sensed there must be some reasons for:

    <FONT color=#000099>const</FONT> <FONT color=#000099>double</FONT> One2Pt20462262185th = 1.0/2.20462262185;

    whilst:

    <FONT color=#000099>const</FONT> <FONT color=#000099>double</FONT> One4Pt44822th  = 1.0/4.44822161525;

    My guess would be, the application asks for higher accuracy in weight than in force.

  • (cs) in reply to drawkward

    I imagine it's something very much like that. I went on a SQL Server development course a year or so ago where the trainer related a story about a company he'd worked at where this kind of thing went on.

  • best_function_ever (unregistered)

    double Round(double val, int precision)
    {
        double v[] = { 1, 10, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8 };  // mgl. verlängern
        return floor(val* v[precision] + 0.5) / v[precision];
    }

  • Derekwaisy (unregistered)
    Comment held for moderation.
  • Jimmyanten (unregistered)

    prednisone without prescription medication: http://prednisone1st.store/# buying prednisone mexico

Leave a comment on “One2Pt20462262185th TwoPtZero”

Log In or post as a guest

Replying to comment #:

« Return to Article