- 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
Welcome to being the source material for TheDailyDevTroll.com ...
Admin
The reason is most likely that changing input parameters are considered bad style by some. (And eclipse even warns me when I do it). I do obvious not code c# in eclipse, but maybe there is the samme issue with c#
Admin
Admin
I don't know about you, but an In Bed Irish girl... heh I got something I wouldn't mind embedding in her.
Admin
If it were an out, ByRef, etc, then it would make sense not to manipulate that variable itself.
Admin
I think t0pC0dr is back...
Guys, if x = x % 13 ; x = 0 if x == 1 is not a wtf, I really, REALLY don't want to code with you. Any of you.
If keeping two iterators going where only one is appropriate is not a wtf, I'm going to send you back to school.
If building an array of constants via loops and case statements is not a wtf, I don't want to code behind you.
Yeah, I agree. If you can't figure what this one returns by looking, don't expect me to recommend you for hire. HOWEVER, there is one final wtf.
WTF kind of program architecture actually needs this sort of array to be returned? WTF is the role that this function plays in the system?
Maybe most of the software engineers that come by are still enjoying their well-earned breaks.
Admin
You expecting them to add new months to the year sometime soon?
Seriously, either pick another name for your constant, have a second constant, or just say "12". Someone may want to get a shorter list of months...and as it stands, they could see the "const int MONTHS", assume that's how many months are going to be returned, and change that in a misguided attempt to shorten the list. Never mind it'll screw up the rest of the calculations, cause you're making a constant do double duty.
Admin
public static List<String> getMonths(int month) { List<String> list = Arrays.asList(new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" });
}
Better to use higher API ...
Admin
Admin
EDIT: The Other RTWF, as ever, is the number of brain-dead fools who think the problem is that the routine is not efficient or well coded, rather than that it exists at all. You cannot fix this problem by rewriting the subroutine but only by deleting it. You guys are all micro-optimising when you should be algorithmically optimising.
Admin
I'm sure it populates a dropdown list somewhere, conveniently putting the current month at the top of the list. I really REALLY wouldn't want to use one of your applications if you aren't even considerate enough to help your users out with the month.
Admin
And who's Em, anyway?
Admin
Ah, the For-Case paradigm. Clbuttic.
Admin
Yet another WTF: a newbie gets assigned a job, does not understands what he's looking at, and sees "WTF's" everywhere.
thedailywtf.com is becoming a WTF by itself!!
Admin
Admin
And even more i hate the idea of maintaining the applications you wrote!
You could have used IllegalArgumentException and a descriptive message, but no!
Oh and by the way: i don't know how months are counted in .NET, but your coding style is Java. In Java months are numbered from 0-11, not 1-12.
Admin
Actually no, because I assumed the slice function would take length as its second parameter, not the ending index. To my opinion, it is the more common way. I could also be optional (if omitted, continue until the end is met.)
Admin
I don`t agree with you. Imagine for example that you need to show such "moved" list in web application. It is simpler (and better) to inject already prepared list into combobox than doing 12 single inserts to combobox model using offset modulo 12.
best regards
Admin
This exception is for flame only :P
Admin
I believe that this depends on the business logic rather than language specific counting, and in real life February is second month not first :P
best regards
Admin
Baracktober
Admin
Not a .net programmer here but that function allocates a new string and sends it off to be consumed. If no one frees it up stream is this a memory leak?
Just my $0.02
Admin
Admin
Simplest and best of all is probably to just split the list into two subranges and do two range inserts.
Admin
Admin
"I have yet to understand what the function does, or how exactly it's used." Oh come on. It's just the For / Select Case paradigm, with the twist that it's actually used a little. Okay, there are better ways, you can start by replacing the for and removing the breaks, but on the whole nothing new or noteworthy. And the use... well, just grep the source tree, lazy bum. And of course we have to end with an unsubstantiated jab at the lead for not worrying about the probably non-existent memory leak. Well, I suppose it's better than the bitmap non-WTF. I guess you have to take progress where you can find it.
Admin
Your pseudo-code looks a lot like my scala
Admin
So this would be your solution? Why not have the dropdown populated with the months in the correct order, with the item's value set to the month number. Then simply auto-selecting the current month using the month number.
Admin
The second element of an array has an index of 1. What is presented to the user doesn't have to be coupled to the implementation; in most systems you'd use a formatting helper rather than just printf("%d") to convert a date to a user visible string.
Admin
a(11) = 11 a(12) = 12 a(13) = 1 a(14) = 1 a(15) = 2 a(16) = 3
b(11) = 11 b(12) = 12 b(13) = 1 b(14) = 1 b(15) = 1 b(16) = 1
Admin
Admin
You're doing way too much work there to populate a combobox. Given the original routine, this is all you neeed: comboBox1.DataSource = GetMonths(DateTime.Now.Month);
Well worth writing a routine to generate that list, especially if you are going to use it in several places.
1 million calls to the original code takes 600ms on my machine. That's more than adequate performance for the task at hand.
The original code isn't very good, but do the cost benefit analysis and convince me it's worth refactoring. It's not.
Admin
Hmmm, I think we have a loser.
Admin
Admin
Admin
I never realized that not-so-great minds also thought alike. Learn something new everyday.
Admin
The list is being newed but never deleted. Then, a copy of the newed list is returned. I believe that is what the Philip meant by "un-managed resources were disposed of properly".
Admin
Either way, only unmanaged resources (images, file handles, sockets, etc) can be leaked, and even that's kinda difficult. A list is fine, as it's all managed.
Admin
Many fond memories, violated! Thanks soooo much!
Admin
That joke writes itself. Actually, given enought time, it's could even be self-modifying code.
Admin
I optimized the loop to only one iteration, it is now 12 times better solution ...
public static List<String> getMonths(int month) { for (int i = 0; i < 1; i++) { switch (month) { case 0: return Arrays.asList(new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }); case 1: return Arrays.asList(new String[] { "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "January" }); case 2: return Arrays.asList(new String[] { "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "January", "February" }); case 3: return Arrays.asList(new String[] { "April", "May", "June", "July", "August", "September", "October", "November", "December", "January", "February", "March" }); case 4: return Arrays.asList(new String[] { "May", "June", "July", "August", "September", "October", "November", "December", "January", "February", "March", "April" }); case 5: return Arrays.asList(new String[] { "June", "July", "August", "September", "October", "November", "December", "January", "February", "March", "April", "May" }); case 6: return Arrays.asList(new String[] { "June", "July", "August", "September", "October", "November", "December", "January", "February", "March", "April", "May" }); case 7: return Arrays.asList(new String[] { "July", "August", "September", "October", "November", "December", "January", "February", "March", "April", "May", "June" }); case 8: return Arrays.asList(new String[] { "August", "September", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July" }); case 9: return Arrays.asList(new String[] { "September", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August" }); case 10: return Arrays.asList(new String[] { "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September" }); case 11: return Arrays.asList(new String[] { "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October" }); case 12: return Arrays.asList(new String[] { "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" }); } }
}
Admin
There's also Mono AOT compiles.
Admin
Admin
My bad.. could be a bit better, also, used a % instead of / for the initial value.
Admin
I dunno... The fact that they are hard-coded strings and not integers or enumerations or at least resource strings is sorta WTFish to me.
Admin
Don't bother, your solution is neither masterpiece nor funny code. It`s nearly proper and to late :P
Admin
Admin
The truly sad part about your rant is that if
a.) They are populating some sort of dropdown list (for example) with this
and
b.) They want it in that order
then
The only way to populate a pick list in the proper order in many windowing toolkits would be to write a custom renderer for the list.
That, of course would be a good way to go about it (though would have it's own host of maintenance issues), assuming the toolkit you were using allowed that (most web frameworks don't). If not, your only option would be to provide the list in the desired order or roll your own widget or widget extension.
Frankly, as a developer, I'll take the less "cool" implementation that is clear and requires less customization of existing code to work.
Admin
There isn't even a need to create an array with the source names of the months.
CultureInfo already contains this. int startMonth = 6
List<string> months = new List<string>(CultureInfo.CurrentCulture.DateTimeFormat.MonthNames.Take(12)); months = months.Skip(startMonth ).Concat(months.Take(startMonth )).ToList();
What I do not (yet) understand is why MonthNames is 13 long to begin with...