- Feature Articles
- 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
fist*r^2
Admin
I'm also troubled by the fact that PI is a (local) function not a constant and the calculation operators have been explicitly forced to make a small floating point number before doing the multiplication (wasting precision).
Admin
Erm, what is then? https://www.php.net/manual/en/function.deg2rad.php
But, if one wanted to re-invent the wheel:
function degToRad (float $value): float { return ($value * M_PI) / 180; }
But, if one needed really small or absolutely large floats, PHP_FLOAT_MIN and PHP_FLOAT_MAX should be considered.
Admin
PHP does have an M_PI constant as well as a pi() function.
Then again, it also has a deg2rad() function.
Admin
Actually, pi() is defined as a global function in PHP, and its documentation suggests that "the M_PI constant which yields identical results to pi()", so they're equivalent as far as I'm concerned. I presume using a function probably has larger overhead, but I don't know the language well enough to know for sure. As far as the comment goes, it's funny, but I don't know if that's a WTF on its own : it's clearly wrong, and was probably left in there because the code was originally copied from somewhere else where it did something different. I'd much rather have such amusing comments than ones that want to be helpful but end up being very misleading.
Admin
In addition to the existing library of mistakes with -o at the end of their names, I think we can add "copypesto" to indicate a mistake in copypasta.
This complements "typo" when a msitake has been made typing, "spello" when a mistake is made in speling, and of course "grammo" when you done a grammatical mistake.
All we knead now is a similar word for a homophone horror.
Admin
The clear and obvious answer is that there was (in the same file, another file or a StackOverflow code snippet) a conversion function that did exactly what the comment said. It was copied and altered to produce another conversion function. Of course, no test (even if there were any) could verify the accurateness of the comment.
Admin
Wouldn't that only matter for fixed-point formats?
BTW doing computations on constants before mutable values come in saves cycles in compiled languages (the compiler can do the constexpr math).
Admin
Most likely true... but then that raises the question of why they couldn't write such a simple function from scratch.
Admin
//convert radians to comment here
Admin
Someone has just copy pasted a different function, changed the name and implementation, but forgot to change the comment. I expect we've all done similar at some point. What makes this special though (apart from reinventing a library function - which is easy to do when it has several million and the docs are so terrible - and PHP ridiculously having a function to return the constant Pi) is why on Earth you would go from "I need a function that converts degrees to radians" to "I'll just copy this Excel-related function and adjust it". I feel like we're only seeing the tip of something WTF iceberg here...
Admin
@ Prime Mover, is Hororphone taken?
Admin
I believe it has to end in -o to fit in with the rest, like phono or something similar.
Admin
Who know, maybe that is the way to convert from timestamps to php dates and the comment is correct ;)
Admin
Have worked on a project containing certain C-libraries.
Each of these libraries generally contained dozens if not hundreds of methods all in a single 'c' file thousands of lines long.
Many of those functions would repeat certain basic logic every single time in a perfect example of "anti-DRY".
The functions contained many comments, sometimes with a comment against nearly every line in the most useless way possible. E.g a comment above a line "i++" saying "//increment i".
The comments that DID matter, you know, the ones that should tell you what the often meaninglessly named function actually does, would just be repeated from some initial function all the way down. And hence be wrong for every function except, obviously, the first one.
Such a joy to maintain,
Admin
I'm estimating a 25% probability that this comment is actually a joke by the programmer.
Admin
If this were code under source control, it might be the case that this chunk of code got automatically merged during some branch-to-branch merge and it was too small to be noticeable-- whether that be the program noticing or a human eyeball failed to see it at a glance.
Admin
I wonder how you can not find it when you get
deg2rand()
in the search results viewport as soon as you type "deg" or "ra". Perhaps searching for "excel to php"?Addendum 2020-09-15 12:43: *deg2rad()
Admin
My favorite is "thinko"
Admin
What, are you homophonic?
Admin
anti-DRY = WET (Write Everything Twice)
Admin
Whoosh-o
Admin
seeing how excel handles dates (and stuff it considers dates), there actually might be an edge case where this could work. (never bet against excel behaving lika a PHB made software)
Admin
I use neither Excel nor PHP on a daily basis, but what I've heard said online about both of them would lead me to believe the comment is plausible...or at least accurate enough, often enough, that no one will notice.
Admin
No on said that they were using the standard Excel date/time format, maybe they are measuring month and day as the angular distance around the sun since the start of the year (in degrees). However, the writer needed to convert this measurement to his custom Access date/time format, which is the same measured angle, but measured in radians.
Admin
Pfft. Anti-DRY ==> DRY = Do Repeat Yourself.
Admin
Ah, yes; the 360-day financial calendar. Via Excel's DAYS360 function.
Admin
I rather like "phono", but it's already been taken by a brand / variety / style of audio connectors.
"Homophono" is a bit of a mouthful, but I suppose it will do.
I am also going to take control of "thinko", and as for "whoosho", that has to be promoted as a concept in its own right.
Admin
Admin
Don't forget scanno, for errors that come from scan & OCR. Tends to cause things like m => rn, rl => it, etc
Admin
What happened to deg1rad() ?
Admin
so, what is the article title then?
Admin
WET is more of a compliment (complement?) to DRY. The cost of abstraction is sometimes greater than the cost of repeating yourself once; and sometimes, things that look similar enough to be convinced actually aren't. So, write it twice, and then if you see a pattern, start generalizing.
Addendum 2020-09-28 22:13: s/convinced/combined/