| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
Looked like someone was learning as they were coding. First they learned switch/case then they moved to arrays.
|
Re: Helpful SQL Helpers
2010-01-13 12:05
•
by
Daniel Migowski
(unregistered)
|
|
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.
|
|
monthList.add("thrist");
captcha: distineo |
|
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. |
|
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. |
|
Besides, in embedded systems, you don't have a file system so you can't just load some month-names table. Not a WTF.
|
Re: Helpful SQL Helpers
2010-01-13 12:20
•
by
Anish
(unregistered)
|
Can you develop for embedded systems in .Net? |
|
Sure, but since there's no filesystem, you need about 200 MB worth of binary const files for the runtime.
|
Re: Helpful SQL Helpers
2010-01-13 12:25
•
by
Ramses So let it be written so let it be done
(unregistered)
|
|
The Battle of Hastings!!!
|
|
Ran the function...
for (int x = -1; x <= 13; x++) { Console.WriteLine("For x:"+x.ToString()); List<string> months = GetMonths(x); foreach (string month in months) Console.WriteLine(month); Console.WriteLine(""); } 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 |
|
Time to combine two memes: Irish Girl and Embedded Systems. Write your own joke.
|
Re: Helpful SQL Helpers
2010-01-13 12:29
•
by
Ernie
(unregistered)
|
Have you ever heard of Windows CE or Windows Mobile? Or how about Windows XPe? |
Wow! A double Troll. |
Re: Helpful SQL Helpers
2010-01-13 12:34
•
by
Plz Send Me The Code
(unregistered)
|
|
Hey, that's kinda handy! Mind if I use it?
|
|
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!! |
Re: Helpful SQL Helpers
2010-01-13 12:37
•
by
...
(unregistered)
|
|
Wow, this is just... not a WTF at all.
Is Alex even reading these before posting? |
|
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; } |
|
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. |
Re: Helpful SQL Helpers
2010-01-13 12:39
•
by
SR
(unregistered)
|
If I was your boss I would CAPTCHA: usitas - Use it and I'll call you an ass :o) |
|
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.
|
Is this a new class of WTF's? 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. |
|
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. |
Re: Helpful SQL Helpers
2010-01-13 12:48
•
by
ShatteredArm
(unregistered)
|
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(); |
Re: Helpful SQL Helpers
2010-01-13 12:48
•
by
Neville Flynn
(unregistered)
|
Perhaps Alex meant that Philip is the WTF. So it's sort of like a meta-WTF. |
|
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? |
|
OK, I think it's time for The Daily WTF to become The Monthly WTF
|
|
"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. |
|
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?
|
Re: Helpful SQL Helpers
2010-01-13 12:55
•
by
Zach Bora
(unregistered)
|
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. |
|
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. |
|
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. |
|
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. |
Embedded Irish Girl? |
Embedded Irish Girl? Edit: Great; first a double post, then the delete button takes me back to the top of the comments (an actual wtf!) |
Re: Helpful SQL Helpers
2010-01-13 13:08
•
by
Ocson
(unregistered)
|
Except that the month names are hardcoded, and no attempt at i18n is done. (Maybe thats TRWTF..........yeah I got nothing) |
Re: Helpful SQL Helpers
2010-01-13 13:15
•
by
Anon
(unregistered)
|
That's what InvariantCulture is for. |
Re: Helpful SQL Helpers
2010-01-13 13:16
•
by
Anon
(unregistered)
|
Yes, but: 1) Your version produces different results than the original. 2) Your version is 2 to 3 times slower that the original. 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? |
|
TRWTF is the lack of typos and/or grammatical errors. This doesn't feel like TDWTF at all.
|
|
trwtf is that he took it to his boss and asked if any one has done refactoring and then pokes fun at his boss.
|
A Triple Lindy! |
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. |
|
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); } |
Re: Helpful SQL Helpers
2010-01-13 13:34
•
by
Anish
(unregistered)
|
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. |
Also, index out of range. |
|
The line I am curious about is
int _month = month; 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. |
|
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... |
Re: Helpful SQL Helpers
2010-01-13 13:41
•
by
Bim Job
(unregistered)
|
Embedded Irish Girl (C++ bitmap version), great idea! Best I can locate so far is an actual video of Erica. Knock yourselves out! 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. |
Re: Helpful SQL Helpers
2010-01-13 13:43
•
by
SpasticW3asel
(unregistered)
|
|
Yeah, but it uses linq. Which is cool and shiny.
|
Re: Helpful SQL Helpers
2010-01-13 13:52
•
by
gray goat
(unregistered)
|
Yea, that too. private static List<string> GetMonthsStartingFrom(int startingMonth) { const int MONTHS = 12; 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"} }; if (startingMonth < 0) startingMonth = MONTHS - Math.Abs(startingMonth) % MONTHS; startingMonth = startingMonth % MONTHS; return months.GetRange(startingMonth, MONTHS); } |
|
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...) |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |