- 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
1st of commend
Admin
Maybe he should send his code to them.
Admin
You posted this on the twenty-eightth on purpose, didn't you?
Admin
Lunchtime doubly so.
Admin
And that's TRWTF. To get the day number to append the suffix to you'll have to call "Now" again, getting two potentially conflicting dates. Sure, it's an unlikely bug, but most bugs are unlikely (otherwise you'd have already found and fixed them). So better take the date as a parameter (which would also make the function more flexible, in case you ever want to "pretty print" other dates but today).
Admin
That's a bigger WTF than the typo of 23->33
Admin
Given we don't have the method signature it's a bit harsh to assume that this is meant to do anything other than prettify today's date; probably by mashing the appropriate suffix onto it immediately after you've worked out the suffix. In that case, unless you called it at 1ms to midnight, I don't see it being that much of a problem.
Admin
the bigger WTF is that he didn't do day%10 in the switch and just had cases for 1,2,3 and default
Admin
Which would have worked especially well on the 11st, 12nd and 13rd.
Admin
b) As I also said, the bug is unlikely, but it's still there. In fact, the more unlikely, the worse (if you actually care for correct code). You'll probably never find this bug by testing, but it's still there.
Admin
TRWTF is needing to format dates in that pointlessly fussy format with "st", "nd", etc. What an utter waste of time, effort and life. The format "1 Jan 2014" oh all right, "Jan 1, 2014" should be perfectly adequate for anyone. Insisting on the ordinal modifiers is PHBness to the n degree.
Admin
Maybe, but I personally think releasing code into production with as obvious a bug as 23th/33rd of a month is more WTF-worthy, because that's something that absolutely should have been caught, rather than an incredibly rare edge case that may never have happened....
Admin
The problem is old code tends to get re-used. Someone along time later needs to do the same thing elsewhere in the project. They correctly search the associated libraries or code files for a function that does what they need. They find one, and read it over quickly to make sure it appears to do what they want. They don't however spend much time thinking about it careful, after all someone has already done that work. Suddenly their new 'use' for the old code hits that corner case and you get a bug.
I my experience when write something and you are aware of a corner case it does not handle its best to put the code in ( provided its reasonably trivial and unlikely to introduce its own problems ) because you want think about it later, even if you are the one calling the code, its just "oh I'll pass it through my handy foo() function I have used forever."
In this case just storing the date and using the stored value for the remainder of the function would make this safe to call frequently and call often. So when someone uses it in the batch report writer and schedules the job to run a little before midnight, things are okay.
Admin
The OP didn't say, but from the fact that the method went straight to the good old proverbial bit bucket suggests that the damn thing wasn't being invoked anywhere in the first place, so the reason the bug wasn't caught is because it wasn't even being called.
Admin
TRWTF is not using ISO date format, lest we forget the twenty-threeth of November.
Admin
Admin
The nth degree, you mean
Admin
Doesn't the page linked to actually say that C# doesn't allow stacked labels?
Admin
And why define num = "th" up front? Are we afraid default doesn't work?
Admin
Oh good, someone noticed my little joke.
Admin
It's been a little while since I dealt with it, but I think C# allows stacked labels, just not fall-through after any code. So
would work, but
would not.
Admin
"Stacked labels" are documented on that page but not illustrated: "...and each section can have one or more case labels."
Admin
Admin
Congrats, Scott, on getting the 23th comment in this comments section!
Admin
That's the joke... :\
Admin
+1
Admin
Admin
This
Admin
Admin
Your code would be a bigger WTF. Happy 11st and 13rd.
Admin
Admin
but why 33 ??????
Captcha: aliquam ...away from here...
Admin
The
antipattern is alive and well in the codebase I've inherited.Admin
Admin
Admin
I found this one just last week:
It was a
in the SQL, but that returns an Int:
?dt.Columns["BitFieldReturnedAsInt"].DataType.FullName "System.Int32"
Admin
suck it up
http://grammar.about.com/od/mo/g/ordnumberterm.htm
Admin
This is not a property of dates. It's a property of the English language. The i18n package should decide this for you.
Spanish locales would would switch the day and month. Also 1st "first" is not 1o "primero".
Admin
But only prettifying today's date is a failure of decomposition and justifies a WTF all on its own. The one method is trying to solve two problems a) getting today's date and b) prettifying a date.
In conflating these two it is eliminating itself as the solution for nearly all cases of b). It might have been eliminating itself as the solution to a) as well except that, as it happens, that solution pre-existed anyway.
I see many, many examples of this failing - only with more 'letters' and a lot more lines of code, and harder to fix - most days. This seems to be ubiquitous for Java, and I'd guess C# - if that's what the code is, less an issue in Ruby/Groovy (and the like) and virtually a non-issue in Lisp. (Love Clojure!)
Mind you, I suppose removing itself from the solution space of most problems could be seen as a good thing, since the method doesn't work. ;-)
Aside: I assume this code with in a system that had no non-English speaking users?
Admin
Admin
The "33rd" while lacking "23rd" tells us it was a typo, which unfortunately are not any kind of WTF.
Admin
He could also have posted it on the twenty-fiveth or the twenty-nineth. That would have been awesome.
Admin
The fact that he only explicitly called out a few numbers instead of covering all or none is the WTF. The fact that he half-assed it and still had a typo is icing.
Admin
It shows that the difficulty in testing exposes a flaw in the design of the code. If you were to try and test this method for 31 different days, it would be hard, since it does not accept a date parameter. It should then be restructured to do so, and then unit testing is much easier.
Admin
I too like boxes within boxes within boxes...
Admin
Forgive the trollishness of this comment, but is .net able to do the th/nd/rd suffix as part of date formatting yet? I haven't used .net for several years but I remember it being one parameter to php's date() function and a lot of work in c#
Admin
Admin
nope
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
Admin
This is one instance where I would just use a look up table. 31 days is small enough that it can be entered quickly with no need for quirky cleverness.
Admin
Coding for humans, right?