• (cs) in reply to ShatteredArm
    ShatteredArm:
    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();
    ShatteredArm wins the thread.
  • sino (unregistered) in reply to Neville Flynn
    Neville Flynn:
    ...:
    Wow, this is just... not a WTF at all. Is Alex even reading these before posting?

    Perhaps Alex meant that Philip is the WTF. So it's sort of like a meta-WTF.

    Well, remember how Alex announced that he and Mark Botchyed-it-again have a new side project?

    Welcome to being the source material for TheDailyDevTroll.com ...

  • (cs) in reply to mk
    mk:
    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.

    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#

  • (cs) in reply to Synchronos
    Synchronos:
    function WrappingMonths(int startMonth) {
      const months = {"January", "February", ..., "December"}; // null-based indexing
      return months.slice(startMonth-1, 13-startMonth).concatenate(months.slice(0, startMonth-1));
    }
    

    (Feel free to point out the bugs and wtfs in my code...)

    Oh, I like that too...

  • (cs) in reply to Bim Job
    Bim Job:
    snoofle:
    Carl:
    Time to combine two memes: Irish Girl and Embedded Systems. Write your own joke.
    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!)

    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.

    I don't know about you, but an In Bed Irish girl... heh I got something I wouldn't mind embedding in her.

  • (cs) in reply to tiller
    tiller:
    mk:
    The line I am curious about is
    int _month = month;
    Is there a legitimate reason to do this in C#?
    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#
    I've always heard it to be bad form. C# scopes variables locally and does GC automatically, so no reason "not" to declare new variables if they impart more meaning to the code. months -> _months imparts nothing.

    If it were an out, ByRef, etc, then it would make sense not to manipulate that variable itself.

  • Right Wing-Nut (unregistered)

    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.

  • (cs) in reply to gray goat
    gray goat:
    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);
    

    }

    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.

  • bary (unregistered)

    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" });

    if (month < 1 || month > 12) {
    	throw new RuntimeException("WTF?");
    }
    
    List<String> returnList = new ArrayList<String>(); 
    	returnList.addAll(list.subList(month-1, 12));
    	returnList.addAll(list.subList(0, month-1));
    	
    return returnList;	
    

    }

    Better to use higher API ...

  • Anon (unregistered) in reply to Synchronos
    Synchronos:
    function WrappingMonths(int startMonth) {
      const months = {"January", "February", ..., "December"}; // null-based indexing
      return months.slice(startMonth-1, 13-startMonth).concatenate(months.slice(0, startMonth-1));
    }
    

    (Feel free to point out the bugs and wtfs in my code...)

    I think you have one too many startMonth's in there.

    function WrappingMonths(int startMonth) {
      const months = {"January", "February", ..., "December"}; // null-based indexing
      return months.slice(startMonth-1, 11).concatenate(months.slice(0, startMonth-1));
    }
    
  • (cs) in reply to Right Wing-Nut
    Right Wing-Nut:
    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?

    Exactly. What kind of poltroon goes to all that length to construct arrays full of months beginning from random points when the freakin' obvious thing to do is have one single goddamn static array full of months and apply an offset modulo 12 when you look up an entry? That, ladies and gentlemen, is TRWTF.

    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.

  • Plz Send Me The Code (unregistered) in reply to Right Wing-Nut
    Right Wing-Nut:
    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.

    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.

  • just me (unregistered) in reply to snoofle
    snoofle:
    Carl:
    Time to combine two memes: Irish Girl and Embedded Systems. Write your own joke.
    Embedded Irish Girl?
    I think you forgot a space, there.

    And who's Em, anyway?

  • Mortal (unregistered)

    Ah, the For-Case paradigm. Clbuttic.

  • --- (unregistered)

    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!!

  • (cs) in reply to Plz Send Me The Code
    Plz Send Me The Code:
    Right Wing-Nut:
    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.

    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.

    I really really wouldn't want to use one of your applications, since you have no understanding of indirection or indexing, and think that in order to access data items in a particular order, you actually have to physically arrange them in memory in that order! ROFL!
  • Design Pattern (unregistered) in reply to bary
    bary:
    if (month < 1 || month > 12) { throw new RuntimeException("WTF?"); }
    I do not want to code with you!

    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.

  • Synchronos (unregistered) in reply to Anon
    Anon:
    I think you have one too many startMonth's in there.

    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.)

  • bary (unregistered) in reply to DaveK

    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

  • bary (unregistered) in reply to Design Pattern
    Design Pattern:
    bary:
    if (month < 1 || month > 12) { throw new RuntimeException("WTF?"); }
    I do not want to code with you!

    This exception is for flame only :P

  • bary (unregistered) in reply to Design Pattern
    Design Pattern:
    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.

    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

  • Thg (unregistered) in reply to cHao
    cHao:

    You expecting them to add new months to the year sometime soon?

    Baracktober

  • Mike (unregistered)

    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

  • (cs) in reply to mk
    mk:
    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.
    Your instincts are correct. There is no reason to do this.
  • (cs) in reply to bary
    bary:
    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

    You are making an unproven assumption that the cost of inserting a string into the combobox is more than the cost of constructing a new string from a literal and inserting that string into a list; that needs profiling data to demonstrate it, it's entirely possible the combobox insert is handled cheaply as a reference.

    Simplest and best of all is probably to just split the list into two subranges and do two range inserts.

  • (cs) in reply to Mike
    Mike:
    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

    That would be what the story was getting at in the last line where it talks about
    whether or not un-managed resources were disposed of properly

  • Shinobu (unregistered)

    "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.

  • Ian (unregistered) in reply to Synchronos

    Your pseudo-code looks a lot like my scala

        def listMonths(start: Int): List[String] = {
            val months = List("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
            val (end, begin) = months.splitAt(start - 1)
            begin ::: end
        }
    
  • (cs) in reply to Plz Send Me The Code
    Plz Send Me The Code:
    Right Wing-Nut:
    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.

    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.

    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.

  • Pete (unregistered) in reply to bary
    bary:
    Design Pattern:
    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.

    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

    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.

  • @Deprecated (unregistered) in reply to Synchronos
    Synchronos:
    The most mind-boggling is this:
    _month = (_month % 13);
    if (_month == 0)
      _month = 1;
    

    Why would one consider using the above instead of:

    if (_month > 12)
      _month = 1;
    

    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

  • (cs) in reply to Right Wing-Nut
    Right Wing-Nut:
    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.
    Dyslexic much? it's "x = x % 13; if x == 0 then x = 1". Either way, it's a bit ugly, but i've seen far worse. In this case, "x %= 12" would have worked, since 0 and 12 trigger the same actions.
    Right Wing-Nut:
    If keeping two iterators going where only one is appropriate is not a wtf, I'm going to send you back to school.
    Appropriate, or necessary? While you could easily do some math to turn the loop variable into an index, keeping track of it separately is not evil -- especially if you're indexing into two different arrays. It's easier to see the moving parts when they're not hiding behind a bunch of stupid pointer tricks.
    Right Wing-Nut:
    If building an array of constants via loops and case statements is not a wtf, I don't want to code behind you.
    Yeah, that's pretty hideous. It's also been posted before. If we saw a post every time someone saw some "bad" code, Alex would never get a break.
    Right Wing-Nut:
    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?
    It's most likely a GUI utility function, with the returned list used to populate a select box. With the months arranged as the function arranges them, the first month in the list (ie: the current month) becomes the default. If the select box rarely gets set to something else, this can make things easier on the user.
  • Anon (unregistered) in reply to DaveK
    DaveK:
    bary:
    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

    You are making an unproven assumption that the cost of inserting a string into the combobox is more than the cost of constructing a new string from a literal and inserting that string into a list; that needs profiling data to demonstrate it, it's entirely possible the combobox insert is handled cheaply as a reference.

    Simplest and best of all is probably to just split the list into two subranges and do two range inserts.

    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.

  • Bob (unregistered) in reply to DaveK
    DaveK:
    Right Wing-Nut:
    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?

    Exactly. What kind of poltroon goes to all that length to construct arrays full of months beginning from random points when the freakin' obvious thing to do is have one single goddamn static array full of months and apply an offset modulo 12 when you look up an entry? That, ladies and gentlemen, is TRWTF.

    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.

    Hmmm, I think we have a loser.

  • (cs) in reply to Mike
    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

    .net uses garbage collection. Once no part of the running code refers to the string, it becomes eligible for deletion. So no, no leak here.

  • Plz Send Me The Code (unregistered) in reply to eclipsed4utoo
    eclipsed4utoo:
    Plz Send Me The Code:
    Right Wing-Nut:
    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.

    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.

    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.

    It would be an OK solution with me if the users wanted the list in that order. Your solution is great too if the users are OK with having that month selected, but not being at the top of the list. Whatever allows my users to work and make money is cool with me.

  • (cs) in reply to DaveK
    DaveK:
    Right Wing-Nut:
    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?

    Exactly. What kind of poltroon goes to all that length to construct arrays full of months beginning from random points when the freakin' obvious thing to do is have one single goddamn static array full of months and apply an offset modulo 12 when you look up an entry? That, ladies and gentlemen, is TRWTF.

    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.

    I never realized that not-so-great minds also thought alike. Learn something new everyday.

  • embsysdev (unregistered) in reply to Terry

    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".

  • (cs) in reply to embsysdev
    embsysdev:
    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".
    The newed list *itself* is returned. In .net, all objects (excluding value-types) are passed around by reference. At the end, the caller ends up with the very list the function was working with.

    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.

  • Jean-Luc Locutus (unregistered) in reply to Carl
    Carl:
    Time to combine two memes: Irish Girl and Embedded Systems. Write your own joke.
    Thanks. I did the mash-up and got Irish Borg Girl. Promptly peed my pants, it was so scary and wrong.

    Many fond memories, violated! Thanks soooo much!

  • Drone (unregistered) in reply to Carl

    That joke writes itself. Actually, given enought time, it's could even be self-modifying code.

  • WTF coder (unregistered)

    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" }); } }

    return Arrays.asList(new String[] {	
    	"January", "February", "March", "April", "May", "June", "July",	"August", "September", "October", "November", "December"
    });
    

    }

  • tracker1 (unregistered) in reply to Ernie

    There's also Mono AOT compiles.

  • tracker1 (unregistered)
    private static string[] _MonthNames = new string[] {
        "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
    };
    
    private static IEnumerable<string> GetMonths(int startingMonth)
    {
        //define return value
        var ret = new List<string>();
        
        //normalize startingMonth imput
        var m = (startingMonth % 12) - 1;
        if (m < 0) m = 0;
        if (m > 11) m = 11;
        
        while (ret.Count < 12) {
            ret.Add(_MonthNames[m]);
            m++;
            if (m > 11) m = 0;
        }
        
        return ret;
    }
  • tracker1 (unregistered) in reply to tracker1

    My bad.. could be a bit better, also, used a % instead of / for the initial value.

    private static string[] _MonthNames = new string[] {
        "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
    };
    
    private static IEnumerable<string> GetMonths(int startingMonth)
    {
        //define return value
        var ret = new List<string>();
        
        //normalize startingMonth imput
        int m = (startingMonth / 12) - 1;
        if (m < 0) m = 0;
        if (m > 11) m = 11;
        
        while (ret.Count < 12) {
            ret.Add(_MonthNames[m++ % 12]);
        }
        
        return ret;
    }
  • Rufus (unregistered)

    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.

  • WTF coder (unregistered) in reply to tracker1
    tracker1:
    My bad.. could be a bit better, also, used a % instead of / for the initial value.

    Don't bother, your solution is neither masterpiece nor funny code. It`s nearly proper and to late :P

  • (cs) in reply to tracker1
    tracker1:
    There's also Mono AOT compiles.
    Screw Mono. If it can't do what the real .net does, they need to fix it til it does -- not dumb down code for the VM that actually works.
  • Fedaykin (unregistered) in reply to DaveK
    DaveK:
    I really really wouldn't want to use one of your applications, since you have no understanding of indirection or indexing, and think that in order to access data items in a particular order, you actually have to physically arrange them in memory in that order! ROFL!

    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.

  • Jesse Houwing (unregistered)

    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...

Leave a comment on “Helpful SQL Helpers”

Log In or post as a guest

Replying to comment #:

« Return to Article