- 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
Admin
Maybe they use just quarters: 0, 15, 30, 45. In this case padding is only needed for the 0. But the code is bad anyways.
Admin
sprintf('%05.2f', $min);
Done.
Admin
Not so much brainfart as a head full of nothing but flatulence.
Admin
Or perhaps minutes have to be recorded in units of 10 minutes or more. That would not be uncommon for something like time recording.
Admin
I like how the if/else statement could just be replaced with: $min = '00';
Admin
Am I seeing correctly? Aren't those 2 blocks (if and else) doing the same thing?
Admin
If only there were Date libraries with formatting....
Admin
Well, if you zero pad a 3, you can easily tell which is the real data and which is the padding. But if you zero pad a 0 that causes data loss. How would you ever be able to get the original zero back?
Admin
Have we ever thought of a WTF Score, for example the number of WTFs per line? This sample would set the bar pretty high.
Admin
The worst part is the curly brace on the same line as the if statement, instead of being on the next line where it belongs.
Admin
I'm looking really hard at that inner if/else clause, and I swear it does nothing whatsoever. Unless this is javascript and you've got to convert "twelvey" values into 12.
Admin
Yep. Good old YAGNI principle: You aren't gonna need it!
Admin
If ($hours==12) $hours = 12 else $hours = $hours
redundancy is redundant
Admin
Really? A formatting preference is worse than only padding some of the time, or pointlessly assigning $hours the value it already holds?
Admin
And I expect the coder to read your article and fix the code. if ($min == 0) { if ($hours == 12) { $hours = 12; $min = '00'; } else if($min == 1) { $hours = $hours; $min = '01'; } else if($min == 3) { $hours = $hours; $min = '03'; } else if($min < 10) { $hours = $hours; $min = '0' + $min; } else { $hours = $hours; $min = '00'; } }
Admin
(Ah, my bad, the "else if" blocks are misplaced.)
Admin
I assumed at first glance that this was part of some code to advance some time value. That is, the check for if ($hours == 12) was meant to then set $hours = 1, else $hours = $hours + 1. Although, I would assume such code would be part of a larger if ($min == 59), $min = 0... [do above], else $min = $min + 1. Perhaps it once said all that, then they worked out that they could just use some built-in functions to handle adding one minute to a time value, and "updated" the code to not add anything, instead of removing it entirely. Still a serious WTF if that's the case.
Admin
Yes it is. In fact, formatting is the second-most important thing.
The first one is a good sarcasm detector.
Admin
The worst part are the people formatting if as if it were a function by placing opening brace on the next line and leaving out space between keyword and opening parentheses.
That must be the most brainless way of formatting if blocks.
Admin
I actually find 'then' and 'endif' much nicer to read code. Verbose FTW!
Admin
Lol? I smell sarcasm :)