• Little Bobby Tables (unregistered)

    Well 1 is actually 33.8f so it's just rounded the temperature down to the nearest 10.

  • Simon (unregistered)

    Eh, the comment is just the usual braindead copy-pasting... I assume they got it from the line that declared ONE = 3.1415f

  • bvs23bkv33 (unregistered)

    if ((1 != 30) && (((-1 * 1) - (-1 * 30)) != 0) && (((-1 * 30) - (-1 * 1)) != 0)) comment;

  • (nodebb)

    Genuine line from our codebase:

    #define FOUR_SECONDS_IN_SECONDS 4

    At least it's accurate, right?

  • Tim Ward (unregistered)

    The classic from IBM 360 assembler:

    R4 EQU 5

    Then within the scope of that any use of "R4", which universally in that language conventionally meant register 4, actually used register 5.

  • Little Bobby Tables (unregistered) in reply to Tim Ward

    Paraphrased from memory ...

    One of the old Digital VAX FORTRAN 77 manuals was explaining the use of the DATA statement and illustrated this using the example of pi, setting the variable PI to 3.1415926535 (or whatever).

    The rationale behind that, it was explained, was that if the value of pi were to change, this could be done in one place only.

  • (nodebb)

    They were referring to 1 fluid ounce which is exactly 30 ml. Or maybe one betrayal for 30 silver coins? One of these two options.

  • Kanitatlan (unregistered)

    I once came across the constant THFF, I'll see if any of you can guess what the value was. Even more fun than THIRTY since not only doesn't it say what the constant was for but leaves it with a surprisingly opaque name.

  • Kanitatlan (unregistered) in reply to Little Bobby Tables

    Rather amusingly the value for PI can change if you are doing non-Euclidean geometry, for example normal space time in the presence of a gravitational field. It doesn't of course change by much and also isn't a constant as it will vary with the gradient of the gravitational field.

  • Foo AKA Fooo (unregistered) in reply to Kanitatlan

    Obviously two hundred and fifty-four. Or was it a thousand hundreds and four fifths? I keep confusing those two common numbers.

  • Lucas (unregistered) in reply to Kanitatlan

    Uhm.... no. Just... no.

  • Jaloopa (unregistered) in reply to Kanitatlan

    THFF

    My guess is one Thousand one Hundred and Fifty Four

  • Foo AKA Fooo (unregistered) in reply to Little Bobby Tables

    "The rationale behind that, it was explained, was that if the value of pi were to change, this could be done in one place only."

    We call that Indiana-safe code.

  • Foo AKA Fooo (unregistered)

    On a more serious note, planning to clean up later is generally a bad idea. Either you'll be too lazy later, or simply forget about it, or as you say you have another fire to put out, and even if you get to it, you'll need to mentally page in the context again which takes much longer than fixing it right away, except for complete trivialities.

    I've made this experience myself and I've seen enough little "to-do" comments in other's code (which merely by me reading them and possibly asking their authors about them cause still more additional work). So I'll always try to do those little things properly right away (also gives you some small feeling of accomplishment while in the middle of some bigger task).

    Also, while I'm not sure about TAU, I do have constants for 180/PI and PI/180 in my code.

    Finally, // TO-DO: write up last point and post this comment

  • ooOOooGa (unregistered)

    I think this is more of a problem with bad comments. Both the constant's name and the comment above it are describing the value that the constant holds instead of what the value means or how it is used.

    A better choice would be something like:

    // Maximum concurrent connections allowed static constant float SESSION_MAX = 30.0f;

    That way, when the value changed from 1 to 30, neither the comment nor the constant's name needs to be adjusted. And people reading the code know what the constant is being used for.

    As for using magic numbers instead of constants as a bad habit: That works as long as you only have one of them hanging around at a time. If you leave them too long you can get magic number collisions - places where the same magic number value is being used for multiple things. For a value like 30, it might be rare. But I have had to replace the magic number 1 with constants so that I could then change it to 5 or something like that. And had to try and figure out which of all of these 1's are the 1's that I need to change to 5, and which should be left at 1.

  • Little Bobby Tables (unregistered) in reply to Kanitatlan

    Heh. You took the bait. This mistake is one of the more common mathematical howlers committed by someone who didn't quite grasp all the details of their undergraduate mathematics course.

    The value of pi never changes. What does change is the ratio of the diameter to the circumference of a circle in a non-Euclidean geometry, which is also dependent upon the size of the circle.

  • (nodebb) in reply to Mr. TA

    1 fluid ounce is not exactly 30 mL, whether you're using US or British outdated units. The former is about 1.5 % short and the latter about 6 % short.

  • THeCPUWizard (unregistered) in reply to Little Bobby Tables

    if the value of pi were to change, this could be done in one place only///

    Given that PI can not be exactly represented, it is actually quite likely that the approximation used will change over time...

  • Conradus (unregistered) in reply to THeCPUWizard

    The only reason your approximation would need to change would be if you got it wrong the first time or if your floating point implementation is changing (but probably not even then).

  • (nodebb) in reply to Foo AKA Fooo

    "you'll need to mentally page in the context again which takes much longer than fixing it right away, except for complete trivialities"

    Meh, there are always multiple things to focus on, so what should be done first is always context-dependent. If you're in the middle of working out a complex program flow when you spot an edge case that will need to be handled, it might not make sense to drop what you're doing so you can go look up what the spec says about the required handling. You leave yourself a TODO and continue the task that your brain is already primed for. You can't do everything at once, and many tasks are best accomplished atomically: that's why TODO lists are a thing!

  • (nodebb)

    Look...

    If you want the value of PI, do it the "easy" way:

       PI = ATAN(1.0) * 4.0
    

    Works every time. I never had to worry about it much after that. If you ARE using PI, chances you ARE using trig functions, and a single call at the beginning of a program is a small price to pay for not having to remember all those decimal places....

  • P (unregistered)

    Maybe it's actually 30 frames, which corresponds to 1 second.

  • Foo AKA Fooo (unregistered) in reply to alphajbravo

    That's right, but it's not what I was talking about. I was talking about cleaning up later vs. writing it cleanly in the first place, which doesn't interrupt the flow of thoughts.

  • Twither (unregistered) in reply to Little Bobby Tables

    And if you consider the limit of the ratio of circumference to diameter as the radius approaches zero, you'll find that PI is a constant independent of local curvature.

  • Ulysses (unregistered)

    I submitted a good WTF article ages ago, but flavorless crud like this continues to get posted instead. Sigh.

  • Angela Anuszewski (google) in reply to Simon

    No, it wasn't a cut and paste error. The constant was originally ONE = 1.0f. I can't share much detail about the actual application. but I totally forgot about that previous submission. They are both examples from the same product. I did actually go back and check to see if it was the same person responsible for both, and it wasn't. (I'm disappointed that it wasn't.) There are other WTFs involved here, but I only had a few moments to type this one up in between phone-calls.

    The original code had something like: foo = x; inverseFoo = (ONE - foo); So, the revised code has inverseFoo = (THIRTY - foo). More math weirdness ensues.

    There is absolutely no explanation in the code explaining why this change was made. I can track what bug it was related to in our tracking system, but there's no technical explanation of how this fixed the issue that was seen.

    (Also, the line right below the one mentioned declares ONE_HUNDRED_PERCENT = 100.0f. I can somewhat forgive this one, since it at least makes it obvious that it is a percentage. But it was still overkill.)

  • sizer99 (google)

    I've seen worse.

    | #define C_25_PCT 0.50

    You can probably guess exactly how this happened. The C_ is because you can't start the define with a number. The value was 0.25 (25% if you're doing 1=100%). This is bad naming style because it doesn't tell you a thing about why you need 25% - especially given the following. And there is no comment. I just happen to know it was a threshold.

    Then for whatever reason they needed 50% instead of 25% for the threshold, but didn't bother changing the name to C_50_PCT.

  • P (unregistered) in reply to Ulysses

    You're TRWTF, I see

  • euripides (unregistered)

    You're all doing it wront. Create a database table named "values" and then insert(name, type, value) values('PI','Constant',3.1415926)

    That way you can query the constants from the database and you don't have to define them in every program.

  • Little Bobby Tables (unregistered) in reply to Twither

    No, pi is a constant independently of its use as a measure of the ratio of the circumference to the radius of a circle.

    All you hot-shot mathematics whiz-kids who think you are all so much cleverer than muggles because you think you've learned something cool and exciting that sets you above mere mortals, coming over all smart about the value of pi in non-Euclidean geometries, have completely missed the point.

    Pi is (or can be) defined as the length of the circumference divided by the length of the diameter of a circle when it is embedded in a Euclidean geometry.

    When a circle is embedded in a different geometry, the ratio of its circumference to its diameter is not pi.

    Pi does not change value according to what shape of geometry you are working in.

  • (nodebb) in reply to Little Bobby Tables

    π is what π is. When the ratio of the diameter of a circle to the circumference of that circle is π, you know that you're in a flat geometry.

  • (nodebb)

    Hey, if you really want to know what pi is, and/ or set your magic number, go to https://hsm.stackexchange.com/questions/9871 .

  • Argle (unregistered)

    Variables named for their values doesn't really have a place in modern programming. But my first programming job was in ForTran and for cockpit equipment. Back 1979, memory could be VERY tight. It turned out that it better in some places to have global variables named ONE, TWO, THREE, etc. and use those rather than constants. Apparently, with that hardware it was more memory efficient and worth the extra effort to save the space.

  • beef (unregistered)

    https://thedailywtf.com/articles/Soft_Coding see this article for the "constants are dumb in the first place" side of the argument.

  • Bulletmagnet (unregistered)

    For very, very large values of 1...

  • markm (unregistered)

    PI is used in many mathematical formulae that do not depend on the geometry of space. Therefore mathematicians do not change PI. They change the formula for the circumference of a circle, something like:

    c = 2 * PI * (1 + correction_factor(r, riemann_tensor)) * r

    where 'c' is the circumference, 'r' is the radius, and the 'riemann_tensor' somehow describes the curvature of space (which doesn't have to be curved the same in different directions, nor the same everywhere, so in the general case this tensor might be a multi-dimensional matrix of functions of the x,y,z coordinates.) In flat space, the riemann_tensor = 0, the correction_factor = 0, and the formula reduces to:

    c = 2 * PI * r

    In a curved space, the correction factor approaches zero when r is small compared to the curvature of space. As it gets bigger, you'll need to calculate the correction factor, perhaps by integrating the riemann_tensor over the area of the circle - but tensors are where I gave up on Physics and switched to Engineering, so rather than trying to understand this calculation, I just consider drawing a circle on a sphere or a saddle.

  • (nodebb) in reply to Little Bobby Tables

    Twitter was agreeing with you.

    It doesn't matter what the local curvature of the space is, as your circle shrinks in size, the ratio of the circumference to the radius approaches pi. As the scale gets smaller, the space begins to look flatter.

  • Conradus (unregistered)

    "Tau is there now."

    For the greater good!

Leave a comment on “Some Kind of Magic”

Log In or post as a guest

Replying to comment #:

« Return to Article