- 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
Looked like someone was learning as they were coding. First they learned switch/case then they moved to arrays.
Admin
This is a completely useful function. It returns the 12 month and includes a rotation, so you get the month from June to December and Januar to May, if you pass 6 (June) as an argument.
Admin
monthList.add("thrist");
captcha: distineo
Admin
OK, TRWTF here is definitely the developers. They've spent months trying to figure out what this function does? It's immediately obvious to me, and I don't even know C#.
It inputs a month number and returns a list of the twelve months of the year, starting from that month. So if you input 7, you'll get July--December, then January--June.
Granted, this is not the best possible way the original developer could have implemented this, but it's far from a WTF.
Addendum (2010-01-13 12:15): My mistake. They didn't spend months trying to figure it out, just "a fair amount of time." Still ridiculous.
Admin
Utterly riveting! What happened next?
Seriously, a substandard but apparently working function, and someone using the 'refactor' tool in visual studio are... just completely normal. I mean the function could be better but it's not wrong. There's no wtf here. All I can say is that they were probably developing for an embedded system where no file system was available, that's all.
Admin
Besides, in embedded systems, you don't have a file system so you can't just load some month-names table. Not a WTF.
Admin
Can you develop for embedded systems in .Net?
Admin
Sure, but since there's no filesystem, you need about 200 MB worth of binary const files for the runtime.
Admin
The Battle of Hastings!!!
Admin
Ran the function...
Output..
For x:-1 January February March April May June July August September October November
For x:0 December January February March April May June July August September October November
For x:1 January February March April May June July August September October November December
For x:2 February March April May June July August September October November December January
For x:3 March April May June July August September October November December January February
For x:4 April May June July August September October November December January February March
For x:5 May June July August September October November December January February March April
For x:6 June July August September October November December January February March April May
For x:7 July August September October November December January February March April May June
For x:8 August September October November December January February March April May June July
For x:9 September October November December January February March April May June July August
For x:10 October November December January February March April May June July August September
For x:11 November December January February March April May June July August September October
For x:12 December January February March April May June July August September October November
For x:13 January February March April May June July August September October November
Admin
Time to combine two memes: Irish Girl and Embedded Systems. Write your own joke.
Admin
Have you ever heard of Windows CE or Windows Mobile? Or how about Windows XPe?
Admin
Wow! A double Troll.
Admin
Hey, that's kinda handy! Mind if I use it?
Admin
It looks ok to me as others have said it will return the 12 months from the month specified. It's not written in a great way but will work from first glance.
Can we please stop having WTF's that aren't WTF's that's 2 out of the last 3 posts. What the WTF is that about!!
Admin
Wow, this is just... not a WTF at all. Is Alex even reading these before posting?
Admin
Other than being ugly, it's not much of a WTF. At the risk of being abused, here's how I would do it (static tests not shown):
static List<string> m_months = new List<string>( new string[] { "January","February","March","April", "May","June", "July","August","September","October","November","December" } ); public static List<string> GetMonths(int month) { month--; List<string> months = new List<string>(); for (int i = month; i < month + 12; i++) { months.Add(m_months[i % 12]); } return months; }
Admin
TRWTF is Philip, who submitted a piece of code that he didn't understand, and treated it as a WTF, when it was a decent way of performing the task.
Everyone point and laugh at Philip.
Admin
If I was your boss I would
CAPTCHA: usitas - Use it and I'll call you an ass :o)
Admin
I am starting to wonder if Alex if knows how to code... or just looks at a long line of code as, wow, they must have done it wrong.
Admin
Developers who inherit code who aren't capable of understanding what it does, so they think it's a WTF?
Doesn't make for very interesting reading.
Admin
That's a valid refactoring (assuming it was automated).
One of the things about refactoring is that the sum effect is larger than you'd expect from looking at the individual commits. In this case it also sounds like the lead developer is going for a warning-free codebase which is laudable.
Admin
Author already established that there is a file system. The code used app settings.
Also, the function could have been easier using LINQ syntax: List<string> months = new List<string> { "January", "Feb... months = months.Skip(month).Concat(months.Take(month)).ToList();
Admin
Perhaps Alex meant that Philip is the WTF. So it's sort of like a meta-WTF.
Admin
The biggest WTF here is probably that the function is in the "SQLHelpers.cs" files.
Or perhaps it's a meta WTF. WTF is it doing on TDWTF?
Admin
OK, I think it's time for The Daily WTF to become The Monthly WTF
Admin
"These are not the unmanaged resources you've been warned about..."
I'm rather impressed by that. We've gone all the way from idiots who insist that "Warnings are just what compilers do. If it was really an error, the compiler wouldn't just call it a warning" to wannabe PHB idiots who think that a clean, warning-free build is more important than correctness.
Oil will one day run out; climate change is inevitable; and, one way or another, it's pretty clear that God doesn't really like us all that much.
But it's cheering to know that, no matter how hard we try to eliminate the bastards, idiots will always prosper.
Admin
The only thing wrong that I can see is that the switch doesn't have a default case. But not a WTF. Alex, this is 2 non WTFs this week. Are you feeling ok?
Admin
I don't think it will output the same depending on your OS language. At least that's what happens in MSSQL and .NET when I do stuff like this on my French OS.
One example I have is a Java application sending dates to the server in format "Feb 01, 2010". My computer would be sending "Fév 01, 2010" instead.
Admin
The switch/case is a tad bit silly, but nevertheless I can see the usefulness of a function to get a month list starting from an arbitrary month. I'd probably name it better though.
While I'm not sure how those Lists work, if it was me, I'd probably make list of the month names starting at January, count down the list to my starting month, then cut everything before my starting point into another array, and swap the two before appending them back together. This would be much faster with linked lists.
Admin
I've seen that switch/case code on here before. Like, I'm pretty sure it's the exact same code.
And it doesn't make a lot of sense in context.
I think Alex screwed up rewriting this, and copy-pasted the code from the next Classic WTF instead of this story.
Admin
I see what they're doing there, but it could be written a lot more concisely: put the months into an array, then iterate through the array 12 times from the start month, wrapping when you reach the end of the array of course.
That wouldn't make it execute much faster or anything, but at least it would look a helluvah lot nicer and have a smaller code footprint.
Admin
Admin
Edit: Great; first a double post, then the delete button takes me back to the top of the comments (an actual wtf!)
Admin
Except that the month names are hardcoded, and no attempt at i18n is done. (Maybe thats TRWTF..........yeah I got nothing)
Admin
That's what InvariantCulture is for.
Admin
Yes, but:
So, for the sake of refactoring code that is only moderately bad but (presumably) works, you're willing to introduce a bug and slow down the application?
Admin
TRWTF is the lack of typos and/or grammatical errors. This doesn't feel like TDWTF at all.
Admin
trwtf is that he took it to his boss and asked if any one has done refactoring and then pokes fun at his boss.
Admin
A Triple Lindy!
Admin
There are no unmanaged resources in this code sample.
I'd say that eliminating compiler warnings from a project is an important use of time. Even if they're just noise, they could obscure other significant warnings.
Admin
Most likely off by one, but:
private static List<string> GetMonthsStartingFrom(int startingMonth) { var months = new List<string> { {"Jan"}, {"Feb"}, {"March"}, {"April"}, {"May"}, {"June"}, {"July"}, {"Aug"}, {"Sept"}, {"Oct"}, {"Nov"}, {"Dec"}, {"Jan"}, {"Feb"}, {"March"}, {"April"}, {"May"}, {"June"}, {"July"}, {"Aug"}, {"Sept"}, {"Oct"}, {"Nov"} }; startingMonth = startingMonth % 12; return months.GetRange(startingMonth, 12); }
Admin
I Agree. There is a Delphi application I maintain. When I inherited it, there were upwards of a thousand warnings. We spent significant time clearing the warnings which enabled us to locate some bugs.
Admin
Also, index out of range.
Admin
The line I am curious about is
Is there a legitimate reason to do this in C#? In C or C++, I can't think of one. If the parameter month were a pointer and the program multithreaded, this would make sense. However, the parameter is an int, so there's no way that another thread could change. Moreover, there is nothing wrong with reassigning to your parameters, in C at least.
Admin
Can we use this for a code contest like Alex tried to get going a while back? I see we've already had a couple of people give it a miss.
I'll toss my wrong entry into the pot, see how many errors you can find ...
Addendum (2010-01-13 13:45): Of course, that's if you like the style that the previous developer used, but I would go instead for something more akin to:
But I think I may be off by one as well...
Admin
No, seriously, knock yourselves out. Use a medium sized rock or a two-by-four or a wodge of PHP code or some horse tranquillizers or something. It'd be far more entertaining.
She's still hot, though.
Admin
Yeah, but it uses linq. Which is cool and shiny.
Admin
Yea, that too.
Admin
The most mind-boggling is this:
Why would one consider using the above instead of:
Of course, for the real solution, I would split a normal month name array in two, and then concatenate the parts back together in the reverse order. Not perhaps the most optimized solution (might create unneeded array allocations), but most probable to be written bug-free and the easiest to see what it is doing.
In somewhat pseudo-syntax (not any particular language):
(Feel free to point out the bugs and wtfs in my code...)