
Feature Articles
 Most Recent Articles
 Teleconference Horror
 I'm Blue
 A Massive Leak
 Ultrabase
 Science Is Science
 MegaAgile
 A Revolutionary Vocabulary
 ABCD
 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
Well 1 is actually 33.8f so it's just rounded the temperature down to the nearest 10.
Admin
Eh, the comment is just the usual braindead copypasting... I assume they got it from the line that declared ONE = 3.1415f
Admin
if ((1 != 30) && (((1 * 1)  (1 * 30)) != 0) && (((1 * 30)  (1 * 1)) != 0)) comment;
Admin
Genuine line from our codebase:
#define FOUR_SECONDS_IN_SECONDS 4
At least it's accurate, right?
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
Rather amusingly the value for PI can change if you are doing nonEuclidean 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.
Admin
Obviously two hundred and fiftyfour. Or was it a thousand hundreds and four fifths? I keep confusing those two common numbers.
Admin
Uhm.... no. Just... no.
Admin
My guess is one Thousand one Hundred and Fifty Four
Admin
"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 Indianasafe code.
Admin
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 "todo" 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, // TODO: write up last point and post this comment
Admin
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.
Admin
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 nonEuclidean geometry, which is also dependent upon the size of the circle.
Admin
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.
Admin
Given that PI can not be exactly represented, it is actually quite likely that the approximation used will change over time...
Admin
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).
Admin
"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 contextdependent. 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!
Admin
Look...
If you want the value of PI, do it the "easy" way:
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....
Admin
Maybe it's actually 30 frames, which corresponds to 1 second.
Admin
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.
Admin
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.
Admin
I submitted a good WTF article ages ago, but flavorless crud like this continues to get posted instead. Sigh.
Admin
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 phonecalls.
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.)
Admin
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.
Admin
You're TRWTF, I see
Admin
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.
Admin
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 hotshot mathematics whizkids 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 nonEuclidean 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.
Admin
π 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.
Admin
Hey, if you really want to know what pi is, and/ or set your magic number, go to https://hsm.stackexchange.com/questions/9871 .
Admin
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.
Admin
https://thedailywtf.com/articles/Soft_Coding see this article for the "constants are dumb in the first place" side of the argument.
Admin
For very, very large values of 1...
Admin
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 multidimensional 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.
Admin
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.