Nondeterministic Months

« Return to Article
  • Mayan 2012-01-05 12:02
    FOOLS!!!!
    BWAAHAHAHA!!!

    (FRIST)
  • ContraCorners 2012-01-05 12:06
    Unless, of course, you're using the Ethopian Calendar.

    http://www.tourismethiopia.org/
  • Mason Wheeler 2012-01-05 12:09
    I used to write functions like that, but then I took an arrow in the knee.
  • Coyne 2012-01-05 12:09
    Or if some fool changes the number of months in the calendar. Then it'll be inaccurate for the new years...or the old.
  • zelmak 2012-01-05 12:15
  • PedanticCurmudgeon 2012-01-05 12:16
    Lousy Smarch weather!
  • PedanticCurmudgeon 2012-01-05 12:17
    zelmak:
    inb4 lame comment about how lame linking to xkcd is.
  • Carl 2012-01-05 12:17
    I'm shocked! Shocked, I tell you. Daily WTFs two days in a row!

    I was expecting more time to work on my clever comment. Now, all I have is this.
  • Kivi 2012-01-05 12:19
    There are calendars where the number of months changes from year to year. The Jewish calendar roughly alternates between 12 and 13 in order to synchronize between the cycle of new moons and the solar year.

    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.

    Not really related, but amusing: http://www.improbable.com/2011/10/14/ig-nobel-winner-writes-best-abstract-ever/. Best scientific abstract ever.
  • AP2 2012-01-05 12:20
    Well, this code is obviously buggy; it didn't work at Kodak.
  • frits 2012-01-05 12:21
    One can only assume there is a function somewhere to set the selected year. I'll bet it looks something like this:
    function setSelectedYear(year)
    
    {
    }

  • Zylon 2012-01-05 12:22
    zelmak:

    That's, uhhh.... not really applicable here. You fail.
  • some guy 2012-01-05 12:22
    PedanticCurmudgeon:
    zelmak:
    inb4 lame comment about how lame linking to xkcd is.


    nb4 lame comment on how lame it is to complain about xkcd lamely.
  • JH 2012-01-05 12:27
    Plausible explanation: it implements an interface designed to support calendars with variable years.

    The "selected" year is an object field.

    In this implementation getMonthCountForSelectedYear() always returns 12.

    In some other implementation for some other calendar, it makes a decision depending on the year.
  • Joe 2012-01-05 12:29
    function returnTwelve(){
    return 12;
    }
  • MojoMonkeyfish 2012-01-05 12:31

    #DEFINE TWELVE = 12;

    function getMonthCountForSelectedYear()
    {
    return TWELVE;
    }


    There, I fixed it. Totally didn't account for twelve changing. Could have been a real pain in the butt.
  • da Doctah 2012-01-05 12:31
    Code fails to pass standards for following reason: "12 is a magic number". Suggest defining a named literal and assigning it the suitable value, then returning that name from this function.

    Edit: curse you MonkeyMojoFish for looking over my shoulder as I type!
  • MojoMonkeyfish 2012-01-05 12:31
    Btw, why is twelve such a strange word to say and spell?
  • the beholder 2012-01-05 12:34
    Kivi:
    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.
    Gee, why can't people ever be satisfied?
    function getMonthCountForSelectedYear(string strMonthName)
    
    {
    return 12;
    }
    There you go. Happy now?
  • Captain Obvious 2012-01-05 12:37
    I can see it being useful for fiscal years - especially when they change when they occur.

    Of course, I'm not saying it's a WTF...but it's probably a WTF.
  • Anketam 2012-01-05 12:40
    Zylon:
    zelmak:

    That's, uhhh.... not really applicable here. You fail.
    Agreed, xkcd is 'random' this is static. Even though I admit as soon as I saw the article xkcd was the first thing to come to mind.
  • WTF-land braver 2012-01-05 12:42
    the beholder:
    Kivi:
    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.
    Gee, why can't people ever be satisfied?
    function getMonthCountForSelectedYear(string strMonthName)
    
    {
    return 12;
    }
    There you go. Happy now?
    Congratulations sir! Between the parameter that doesn't relate to what the function is supposed to do, the hungarian notation, and the use of string where int would be a more sensible choice you managed to escalate this WTF to a new level.

    I tip my hat to you now.
  • Perry 2012-01-05 12:45
    It's such a shame this guy has left now as I need to write a function that calculates the number of days in any given week and he could've helped.

    sub getDaysInAnyGivenWeek {
    my ($date) = @_;

    # get integer value of first day in week
    my $intStart = getIntegerValueOfFirstDayInWeek ($date);

    # get integer value of last day in week
    my $intDone = getIntegerValueOfLastDayInWeek ($date);

    # error checking left as an exercise for the reader
    return $intDone - $intStart;
    }

    (It's nested function calls all the way down!)
  • me 2012-01-05 12:46
    #DEFINE POSSIBLE_MONTHS_IN_THE_YEAR;

    function getMonthCountForSelectedYear(aYear)
    {
    int year_counter = 0;

    year_counter = year_counter + 1;

    for (var i=1; i <= POSSIBLE_MONTHS_IN_THE_YEAR; i++)
    {
    year_counter++;
    }

    if (year_counter == 12)
    {
    return 12;
    }
    else
    {
    //hmmmm....
    }
    }

    Who is askimet?
  • Ant 2012-01-05 12:49
    Jon-Paul continues, "I particularly like the way you don't even have to pass in the selected year to still get the correct return value. It's such a shame this guy has left now as I need to write a function that calculates the number of days in any given week and he could've helped."

    Try asking the Samoans how many days there were last week!
  • Thayla 2012-01-05 12:51
    If you're going with days in a week method what about hours in a day method, or minutes in an hour method.

    I'm not a particular fan of constants, because sometimes they are wrong. I've found constants like months = 12 before when it should clearly be 42.
  • Nagesh 2012-01-05 12:54
    In al mune-base calanders, there is sometime being extra munth aded.
  • C-Octothorpe 2012-01-05 12:58
    me:
    Who is askimet?
    An evil, racist AI bent on stopping the dissemination of funny and/or applicable content.
  • Jack 2012-01-05 12:59
    Kivi:
    ... the lack of a parameter to the function is highly suspicious.


    I would guess that the "selected year" is stored in a global variable somewhere (which may be a WTF itself) ... except that the submitter, who presumably knows the system pretty well, was also surprised/amused by the missing parameter.
  • Nagesh 2012-01-05 13:02
    On years with extra munth, Hindu calander is requiring appropriate secrifise.

  • You laugh, but... 2012-01-05 13:03
    I seriously worked on a group project with someone in CS college who did that.


    #define FORTY 40
    ...
    for(i=0; i < FORTY; i++) {
    ...
    }

    I DO like doing something like,

    #define MONTHS_PER_YEAR 12

    because then later when you see code like,

    for(m=0; m < 12; m++) {
    do_something(m);
    }

    versus

    for(m=0; m < MONTHS_PER_YEAR; m++) {
    do_something(m);
    }

    ...it is self documenting. "Oh, he's iterating over the months in the year."

  • usitas 2012-01-05 13:03
    Kivi:
    There are calendars where the number of months changes from year to year. The Jewish calendar roughly alternates between 12 and 13 in order to synchronize between the cycle of new moons and the solar year.

    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.

    Not really related, but amusing: http://www.improbable.com/2011/10/14/ig-nobel-winner-writes-best-abstract-ever/. Best scientific abstract ever.


    When are all these religions out there finally get it: we have a globally used calendar, and stop using all other junk that relate to non-existing mythological creatures such as the god (deliberately lowecase)?
  • Jack 2012-01-05 13:04
    MojoMonkeyfish:
    Btw, why is twelve such a strange word to say and spell?


    Well, it's a hold-over from an old base-12 number system. That's why it's its own word, instead of "twoteen," or "ten-two," or something. I believe it's the same reason we have the word "dozen," and there are 12 inches in a foot. That probably doesn't answer your question, though...
  • EatenByAGrue 2012-01-05 13:08
    Ant:
    Jon-Paul continues, "I particularly like the way you don't even have to pass in the selected year to still get the correct return value. It's such a shame this guy has left now as I need to write a function that calculates the number of days in any given week and he could've helped."

    Try asking the Samoans how many days there were last week!


    10, of course, if you ask the French Republicans.
  • Nagesh 2012-01-05 13:08
    Many time year is having extra munth. I am on far left at last adhik mas festival.

  • Jack 2012-01-05 13:09
    usitas:
    When are all these religions out there finally get it: we have a globally used calendar, and stop using all other junk that relate to non-existing mythological creatures such as the god (deliberately lowecase)?


    They almost universally DO use the Gregorian calendar for anything non-religious, don't they? What do you care how they decide when their holidays will be?
  • S&H IT 2012-01-05 13:16
    To be fair, the Hebrew calendar sometimes has 13 months, depending on if it's a leap year. http://en.wikipedia.org/wiki/Hebrew_calendar#Names_of_months
  • EatenByAGrue 2012-01-05 13:17
    usitas:

    When are all these religions out there finally get it: we have a globally used calendar, and stop using all other junk that relate to non-existing mythological creatures such as the god (deliberately lowecase)?


    By a "globally used calendar", you're talking about the one with:
    * a 7-day week from Genesis
    * days named after Tyr, Odin, Thor, Frig, and Saturn
    * months named after Janus, Mars, Maia, Juno, and the deified Julius and Augustus
    Because that clearly in no way involves mythological creatures.

    The One True Calendar, though, is obvious: Start at UTC midnight on what is conventionally called Jan 1, 1970, and count the number of seconds (defined by cesium atoms) since then.
  • DMAA 2012-01-05 13:18
    Here's a tip for Jon-Paul regarding the week-length function, although I don't know JavaScript very well. Check if the API has a firstDayOfWeek() and lastDayOfWeek() function, or some equivalent, then subtract the former from the latter, and add one.

    daysOfWeek = lastDayOfWeek(n) - firstDayOfWeek(n) + 1

    This also elegantly handles cases where there are days between weeks. Those would have incorrectly been counted if you used just firstDayOfWeek(n+1) - firstDayOfweek(n).

    This algorithm fails, however, for weeks that end before they start. You may want to do a Math.Abs()-equivalent to handle that.

    Of course, all this assumes roughly equal-length days (give or take a leap second). Should the last day's length approach 0, you may want to leave out the final "+ 1".

    Hope this helps. In case you need more assistance, I can send you a library with thousands of important numerical constants for date calculations, from ONE through EIGHTYSIXTHOUSANDFOURHUNDRED and many more.
  • Anonymous Guy 2012-01-05 13:26
    there you go:

    function getDayCountForSelectedWeek()
    {
    # return 6;
    return 7;
    }
  • Anonymous Guy 2012-01-05 13:28
    Anonymous Guy:
    there you go:

    function getDayCountForSelectedWeek()
    {
    # return 6;
    return 7;
    }


    that was supposed to be a // not a # :)

    showed that if this guy had written one perhaps he would have prepared the week days go down to 6 :)
  • Will 2012-01-05 13:46
    function isDaysCommentFunny (today) {
    
    return "no"
    }
  • undefined 2012-01-05 13:55
    MojoMonkeyfish:

    #DEFINE TWELVE = 12;

    function getMonthCountForSelectedYear()
    {
    return TWELVE;
    }


    There, I fixed it. Totally didn't account for twelve changing. Could have been a real pain in the butt.



    I like JavaScript and plain C mixed together.
  • snoofle 2012-01-05 14:01
    I asked my wife, and she definitively told me that you will be much happier in life if all your periods have 28 day cycles.

    I never argue with my wife because she is always right (she told me so)!
  • dlevy 2012-01-05 14:02
    The function should really have a parameter for "planet" in case the code is exported.
  • Foobar 2012-01-05 14:04
    "Twelve" is so strange because it is a word invented by elves. It is a subtle fairy revenge against the English.

    Now you know.
  • geoffrey 2012-01-05 14:18
    Had the code's author used the number 12, Jon-Paul would have thrown the silly programmer "magic number" pet peeve out there. Had the author defined it in a constant, Jon-Paul would have lamented its lack of flexibility. Here he goes, makes it easy to read, and easy to change, and he still gets submitted to this site. Unbelievable.
  • Silfax 2012-01-05 14:21
    me:
    #DEFINE POSSIBLE_MONTHS_IN_THE_YEAR;


    Who is askimet?


    Imet is the guy who wrote the code, I think he is a friend of Nagesh... Go ask him.
  • Pham Nuwen 2012-01-05 14:23
    EatenByAGrue:

    The One True Calendar, though, is obvious: Start at UTC midnight on what is conventionally called Jan 1, 1970, and count the number of seconds (defined by cesium atoms) since then.

    I'm Programmer-Archaeologist Pham Nuwen, and I approve of this message.
  • J.R.R. Trollkein 2012-01-05 14:26
    Foobar:
    "Twelve" is so strange because it is a word invented by elves. It is a subtle fairy revenge against the English.

    Now you know.

    This makes perfect sense.

    Good thing we didn't anger the dwarves. Counting "Ten, Eleven, Twarf" would just be silly.
  • PiisAWheeL 2012-01-05 14:29
    usitas:
    Kivi:
    There are calendars where the number of months changes from year to year. The Jewish calendar roughly alternates between 12 and 13 in order to synchronize between the cycle of new moons and the solar year.

    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.

    Not really related, but amusing: http://www.improbable.com/2011/10/14/ig-nobel-winner-writes-best-abstract-ever/. Best scientific abstract ever.


    When are all these religions out there finally get it: we have a globally used calendar, and stop using all other junk that relate to non-existing mythological creatures such as the god (deliberately lowecase)?


    I don't understand the question.
  • Spit Can - Make Weight 2012-01-05 14:31
    Nagesh:
    Many time year is having extra munth. I am on far left at last adhik mas festival.

    I wasn't aware that high school was even available in India, yet I'm seeing an execution of the "High School Hero" headlock before my very eyes.
  • PedanticCurmudgeon 2012-01-05 14:43
    EatenByAGrue:
    usitas:

    When are all these religions out there finally get it: we have a globally used calendar, and stop using all other junk that relate to non-existing mythological creatures such as the god (deliberately lowecase)?


    By a "globally used calendar", you're talking about the one with:
    * a 7-day week from Genesis
    * days named after Tyr, Odin, Thor, Frig, and Saturn
    * months named after Janus, Mars, Maia, Juno, and the deified Julius and Augustus
    Because that clearly in no way involves mythological creatures.
    It's even worse than you think. Since the other two days are named after the Sun and the Moon, and the five you mention are also planet names (think of the Romance language versions), the days of the week are actually based on astrology.
  • Boog, I Am Your Father! (aka Behold The Return Of Zunesis!)! 2012-01-05 15:39
    Foobar:
    "Twelve" is so strange because it is a word invented by elves. It is a subtle fairy revenge against the English.

    Now you know.
    I think the fairy revenge against the English was making them all fairies. Seriously, it's like, you whistle at some chick and all these guy's asses pop up in the air. I guess they're used to grasping their ankles. At least they have great hospitals for the reconstructive surgery when I'm done with them. And I only mean that half-sarcastically. The Her Royal Highness's Plastic Surgeons with wonders for my formerly average endowment. I could make a bitch elephant cry now!

    Arrrrggggggg!!! Even this elephant pussy is too fucking tight for me now!!! rrrrrrrrr!!! Oh! Oh!
    OOOOOOOOOOOOHHHHHHHHHHHHH YEEEEEEEAAAAAAAAHHHHHHHH!!!!
  • bloo 2012-01-05 15:48
    ContraCorners:
    Unless, of course, you're using the Ethopian Calendar.

    http://www.tourismethiopia.org/
    Tour is meth iopia? that's as bad as pen island - the place for all your scribbling purchases.
  • siggi 2012-01-05 15:49
    may i help?


    getDaysInLunarMonth = function () { return 28; }

    getDaysInWeek = function () {
    var daysInLunarMonth = getDaysInLunarMonth();
    return daysInLunarMonth / 4;
    }


    tricky isn't it?
  • Bldsquirrel 2012-01-05 15:49
    MojoMonkeyfish:

    #DEFINE TWELVE = 12;

    function getMonthCountForSelectedYear()
    {
    return TWELVE;
    }


    There, I fixed it. Totally didn't account for twelve changing. Could have been a real pain in the butt.


    ...but 12 is a magic number you need:

    #DEFINE TWELVE = 12;
    #DEFINE MONTHS_IN_A_YEAR = TWELVE


    function getMonthCountForSelectedYear()

    {

    return MONTHS_IN_A_YEAR;

    }

  • Boog, I Am Your Father! (aka Behold The Return Of Zunesis!)! 2012-01-05 15:54
    C-Octothorpe:
    me:
    Who is askimet?
    An evil, racist AI bent on stopping the dissemination of funny and/or applicable content.
    "Who Is Askimet?" The thrilling new feature film about a diabolical entity that random takes people's voices just as they become vitally necessary. Thruought the story, people are demanding to know the anwser to the titular phrase. Oh, and it's racist! Bwa-ha-ha-ha!!!

    "Who Is Askimet?" - Coming Halloween 2012, Scared Yet?

    Then later, we'll have "'Who's In My Ass?', I Meant!" - the thrilling new adult feature parody of the thrilling new feature film "Who Is Askimet?" concerning a diabolical interloper on a key scene where a naive, young pornographic actress is unable to ask who has begun penetrating her anus, as she was still blowing her co-star. The mystery persists until she's able to cough up that ebony footlong. Again, she persists: "Who's in my ass?, I meant". Who, indeed! Ha ha ha!

    "'Who's In My Ass?', I Meant!" - Cuming Christmas 2012, Scared Wet? Yeah? A little fear turns you on?
  • Nagesh 2012-01-05 16:02
    S&H IT:
    To be fair, the Hebrew calendar sometimes has 13 months, depending on if it's a leap year. http://en.wikipedia.org/wiki/Hebrew_calendar#Names_of_months


    Hindu Calendar also having extra month. Hindu follow lunar cycle, so no leap year. but sometime leap month. ;)
  • C-Octothorpe 2012-01-05 16:03
    Boog, I Am Your Father! (aka Behold The Return Of Zunesis!)!:
    [stuff only one with a soul as demented as zunesis can write]
    What, no "invisible" comments? I'm disappointed...
  • Springer 2012-01-05 16:05
    MojoMonkeyfish:

    #DEFINE TWELVE = 12;

    function getMonthCountForSelectedYear()
    {
    return TWELVE;
    }


    There, I fixed it. Totally didn't account for twelve changing. Could have been a real pain in the butt.


    /* OBSOLETED
    #define ONE 1
    #define TWO (ONE+ONE)
    #define THREE (TWO+ONE)
    #define FOUR (TWO+TWO) //optimized to use TWO instead of ONE
    #define FIVE (FOUR+ONE)
    #define SIX (FOUR+TWO)
    #define SEVEN (FOUR+TWO+ONE) //Oh, now we are a geek...
    #define EIGHT (FOUR+FOUR) //more OPTIMIZATION
    #define NINE (EIGHT+ONE)
    #define TEN (EIGHT+TWO)
    #define ELEVEN (EIGHT+TWO+ONE)
    #define TWELVE (EIGHT+FOUR)
    ******* END OBOLETED *****/

    /***
    * The previous number definitions were inefficient, so we have
    *optimised for maximum usefulness (we leave how not to do it above
    *as an example for the n00bs who don't know better
    */
    #define ONE 1
    #define TWO (ONE<<ONE)
    #define THREE (TWO+ONE)
    #define OLD_FOUR (TWO<<ONE)
    #define FOUR (ONE<<TWO) // Much better than TWO<<ONE
    #define FIVE (FOUR+ONE)
    #define SIX (FOUR+TWO)
    #define SEVEN (FOUR+TWO+ONE)
    #define OLD_EIGHT (ONE<<THREE)
    #define EIGHT (FOUR<<ONE) //Could do ONE<<THREE, but better to use powers of two
    #define NINE (EIGHT+ONE)
    #define TEN (EIGHT+TWO)
    #define ELEVEN (EIGHT+TWO+ONE)
    #define TWELVE (EIGHT+FOUR)
    #define THIRTEEN (EIGHT+FOUR+ONE)
    #define FOURTEEN (EIGHT+FOUR+TWO)
    #define FIFTEEN (EIGHT+FOUR+TWO+ONE)
    #define OLDER_SIXTEEN (ONE<<FOUR)
    #define OLD_SIXTEEN (EIGHT<<ONE)
    #define SIXTEEN (FOUR<<TWO)


    No Magic numbers!!
  • Santa 2012-01-05 16:07
    MojoMonkeyfish:
    Btw, why is twelve such a strange word to say and spell?

    Well, we used to have a base six notation where 6 was referred to as an elf. Twelve derives from Two Elves, but over time it has run together.

    I think eleven is related too....
  • Samoan Joe 2012-01-05 16:08
    Ant:
    Jon-Paul continues, "I particularly like the way you don't even have to pass in the selected year to still get the correct return value. It's such a shame this guy has left now as I need to write a function that calculates the number of days in any given week and he could've helped."

    Try asking the Samoans how many days there were last week!
    Like
  • Nagesh 2012-01-05 16:09
    C-Octothorpe:
    Boog, I Am Your Father! (aka Behold The Return Of Zunesis!)!:
    [stuff only one with a soul as demented as zunesis can write]
    What, no "invisible" comments? I'm disappointed...


    Disappointment is inevitable with life you are leading on Planet Earth. If you want to live blesed life, accept role of religion and follow it religiously.
  • Jim 2012-01-05 16:09
    Nagesh:
    On years with extra munth, Hindu calander is requiring appropriate secrifise.

    The kid in the blue who you intend to sacrifice looks so Glum!!!
  • pedant 2012-01-05 16:13
    Jack:
    MojoMonkeyfish:
    Btw, why is twelve such a strange word to say and spell?


    Well, it's a hold-over from an old base-12 number system. That's why it's its own word, instead of "twoteen," or "ten-two," or something. I believe it's the same reason we have the word "dozen," and there are 12 inches in a foot. That probably doesn't answer your question, though...
    And yet you would think that "teen" derives from "ten" rather than "twelve"....

    Does that mean that pre-decimalization we got to twelve and then said "one one", "one two"....etc, and it was only with decimalization (where we kept eleven and twelve - why not, they're already words for such quantities - backward compatibility and all that) that we introduced thirteen etc...
  • Boog, I Am Your Father! (aka Behold The Return Of Zunesis!)! 2012-01-05 16:15
    C-Octothorpe:
    Boog, I Am Your Father! (aka Behold The Return Of Zunesis!)!:
    [stuff only one with a soul as demented as zunesis can write]
    What, no "invisible" comments? I'm disappointed...
    Oh, it's just never good enough, is it?!

    I slave over my keyboard for minutes at a time composing these treasures! And you just waltz in from work and throw it in my face!

    Hmm.. you know what? I think this is the perfect opportunity to tell you - your penis has never satisfied me! You know all those "orgasms" I've had. Well check out the finger quotes: they were fake!

    Our son has such a bigger dick than you - he must have gotten from my side of the family as from what I've seen, my father must have been at least 1/8th donkey! Why'd I have to carry the big dick gene, I'm the woman!? Shouldn't you have the huge cock gene, Baby Dick! Sperm Fail! AAAAAAAAA!!!!
  • Maurits 2012-01-05 16:16
    Springer:
    MojoMonkeyfish:

    #DEFINE TWELVE = 12;

    function getMonthCountForSelectedYear()
    {
    return TWELVE;
    }


    There, I fixed it. Totally didn't account for twelve changing. Could have been a real pain in the butt.


    /* OBSOLETED
    #define ONE 1
    #define TWO (ONE+ONE)
    #define THREE (TWO+ONE)
    #define FOUR (TWO+TWO) //optimized to use TWO instead of ONE
    #define FIVE (FOUR+ONE)
    #define SIX (FOUR+TWO)
    #define SEVEN (FOUR+TWO+ONE) //Oh, now we are a geek...
    #define EIGHT (FOUR+FOUR) //more OPTIMIZATION
    #define NINE (EIGHT+ONE)
    #define TEN (EIGHT+TWO)
    #define ELEVEN (EIGHT+TWO+ONE)
    #define TWELVE (EIGHT+FOUR)
    ******* END OBOLETED *****/

    /***
    * The previous number definitions were inefficient, so we have
    *optimised for maximum usefulness (we leave how not to do it above
    *as an example for the n00bs who don't know better
    */
    #define ONE 1
    #define TWO (ONE<<ONE)
    #define THREE (TWO+ONE)
    #define OLD_FOUR (TWO<<ONE)
    #define FOUR (ONE<<TWO) // Much better than TWO<<ONE
    #define FIVE (FOUR+ONE)
    #define SIX (FOUR+TWO)
    #define SEVEN (FOUR+TWO+ONE)
    #define OLD_EIGHT (ONE<<THREE)
    #define EIGHT (FOUR<<ONE) //Could do ONE<<THREE, but better to use powers of two
    #define NINE (EIGHT+ONE)
    #define TEN (EIGHT+TWO)
    #define ELEVEN (EIGHT+TWO+ONE)
    #define TWELVE (EIGHT+FOUR)
    #define THIRTEEN (EIGHT+FOUR+ONE)
    #define FOURTEEN (EIGHT+FOUR+TWO)
    #define FIFTEEN (EIGHT+FOUR+TWO+ONE)
    #define OLDER_SIXTEEN (ONE<<FOUR)
    #define OLD_SIXTEEN (EIGHT<<ONE)
    #define SIXTEEN (FOUR<<TWO)


    No Magic numbers!!


    Only n00bs use + when they could use |
  • bleh 2012-01-05 16:24
    ContraCorners:
    Unless, of course, you're using the Ethopian Calendar.

    http://www.tourismethiopia.org/


    Or these dudes manage to get the Hanke-Henry Permanent Calendar to catch on...

    http://www.universetoday.com/92306/new-year-new-calendar-but-johns-hopkins-scholars-say-we-need-a-permanent-edition/
  • Video Idea 2012-01-05 16:30
    Mason Wheeler:
    I used to write functions like that, but then I took an arrow in the knee.

    I have an idea for a YouTube video, but no idea how to make it.

    Gather up video clips of 20 or 30 guards in Skyrim giving the "arrow to the knee" bit, and put them back to back.

    Immediately after this, add the clip in Terminator 2 where Arnold is shooting all of the guards in their kneecaps.
  • Matt Westwood 2012-01-05 18:00
    Kivi:
    There are calendars where the number of months changes from year to year. The Jewish calendar roughly alternates between 12 and 13 in order to synchronize between the cycle of new moons and the solar year.

    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.

    Not really related, but amusing: http://www.improbable.com/2011/10/14/ig-nobel-winner-writes-best-abstract-ever/. Best scientific abstract ever.


    For terseness, what about Frank Nelson Cole's lecture in which he demonstrated that:

    2^67 - 1 = 147573952589676412927 = 761838257287 × 193707721

    without uttering a word?
  • Matt Westwood 2012-01-05 18:03
    AP2:
    Well, this code is obviously buggy; it didn't work at Kodak.


    The reason that never caught on is because every single month would then contain a Friday the 13th. Yeah, the superstitious peasants who get voted into office would have adopted *that* as the national calendar, defly.
  • Matt Westwood 2012-01-05 18:06
    MojoMonkeyfish:
    Btw, why is twelve such a strange word to say and spell?


    So as to make "twelve plus one" an anagram of "eleven plus two".

    Why are "one" and "two" similarly? They should be "wun" and "too".
  • Matt Westwood 2012-01-05 18:11
    Boog, I Am Your Father! (aka Behold The Return Of Zunesis!)!:
    Foobar:
    "Twelve" is so strange because it is a word invented by elves. It is a subtle fairy revenge against the English.

    Now you know.
    I think the fairy revenge against the English was making them all fairies. Seriously, it's like, you whistle at some chick and all these guy's asses pop up in the air. I guess they're used to grasping their ankles. At least they have great hospitals for the reconstructive surgery when I'm done with them. And I only mean that half-sarcastically. The Her Royal Highness's Plastic Surgeons with wonders for my formerly average endowment. I could make a bitch elephant cry now!

    Arrrrggggggg!!! Even this elephant pussy is too fucking tight for me now!!! rrrrrrrrr!!! Oh! Oh!
    OOOOOOOOOOOOHHHHHHHHHHHHH YEEEEEEEAAAAAAAAHHHHHHHH!!!!


    You do know that eleven in German is elf?
  • Tud 2012-01-05 18:49
    In Haskell it's easier:


    monthcountforyear 0 = 12
    monthcountforyear n
    | n > 0 = monthcountforyear (n - 1)
    | n < 0 = monthcountforyear (n + 1)


    (Well no, I have never written anything over 6 lines long in Haskell, why do you ask?)
  • Tud 2012-01-05 19:02
    Matt Westwood:
    MojoMonkeyfish:
    Btw, why is twelve such a strange word to say and spell?


    So as to make "twelve plus one" an anagram of "eleven plus two".

    Why are "one" and "two" similarly? They should be "wun" and "too".


    Because English.
  • PiisAWheeL 2012-01-05 19:46
    Tud:
    Matt Westwood:
    MojoMonkeyfish:
    Btw, why is twelve such a strange word to say and spell?


    So as to make "twelve plus one" an anagram of "eleven plus two".

    Why are "one" and "two" similarly? They should be "wun" and "too".


    Because English.


    English is a Germanic language; Being derived from German, and have you looked at German lately?
  • Cheong 2012-01-05 21:30
    FYI, for a number of calendar, some years do have leap month and month count don't necessary even across the years.
  • Coyne 2012-01-05 21:35
    MojoMonkeyfish:
    Btw, why is twelve such a strange word to say and spell?


    Not nearly as strange to say and spell as "twaddle".
  • Son Of Thor 2012-01-05 22:24
    Well I like forward thinking with descovery of Kepler 20 which is in the habital zone of its solar system it most likely dont have twelve mounth in the year and Kepler 20lings may want to run the software
  • da Doctah 2012-01-05 22:29
    PedanticCurmudgeon:
    EatenByAGrue:
    By a "globally used calendar", you're talking about the one with:
    * a 7-day week from Genesis
    * days named after Tyr, Odin, Thor, Frig, and Saturn
    * months named after Janus, Mars, Maia, Juno, and the deified Julius and Augustus
    Because that clearly in no way involves mythological creatures.
    It's even worse than you think. Since the other two days are named after the Sun and the Moon, and the five you mention are also planet names (think of the Romance language versions), the days of the week are actually based on astrology.

    It's even worse than you think. In Japanese the days of the week have names that essentially read "Sun-day", "Moon-day", "Fire-day", "Water-day", "Wood-day", "Gold-day" and "Earth-day". And since in Japanese the planet Mercury is "Water-star", Venus is "Gold-star", Mars is "Fire-star", Jupiter is "Wood-star" and Saturn is "Earth-star", there's a one-to-one correspondence between the days of the week and the astrological planets.
  • Gunslinger 2012-01-05 22:30
    If they ever take my suggestion to move to a rational 28 day/13 month calendar, then this function will be useful. You will rue the day you mocked him!
  • Matt Westwood 2012-01-06 01:26
    Gunslinger:
    If they ever take my suggestion to move to a rational 28 day/13 month calendar, then this function will be useful. You will rue the day you mocked him!


    "Useful"? It'll be *wrong*!
  • corroded 2012-01-06 04:28
    J.R.R. Trollkein:
    Foobar:
    "Twelve" is so strange because it is a word invented by elves. It is a subtle fairy revenge against the English.

    Now you know.

    This makes perfect sense.

    Good thing we didn't anger the dwarves. Counting "Ten, Eleven, Twarf" would just be silly.


    You mean "Ten, Dwarven, Twdwarve"?


  • CFM 2012-01-06 04:56
    Actually both English and German are derived from Proto-Germanic. English is no more derived from German than humans are derived from chimpanzees.
  • Lost 2012-01-06 05:58
    He forgot about Undecimber
  • undefined 2012-01-06 06:06
    da Doctah:
    PedanticCurmudgeon:
    EatenByAGrue:
    By a "globally used calendar", you're talking about the one with:
    * a 7-day week from Genesis
    * days named after Tyr, Odin, Thor, Frig, and Saturn
    * months named after Janus, Mars, Maia, Juno, and the deified Julius and Augustus
    Because that clearly in no way involves mythological creatures.
    It's even worse than you think. Since the other two days are named after the Sun and the Moon, and the five you mention are also planet names (think of the Romance language versions), the days of the week are actually based on astrology.

    It's even worse than you think. In Japanese the days of the week have names that essentially read "Sun-day", "Moon-day", "Fire-day", "Water-day", "Wood-day", "Gold-day" and "Earth-day". And since in Japanese the planet Mercury is "Water-star", Venus is "Gold-star", Mars is "Fire-star", Jupiter is "Wood-star" and Saturn is "Earth-star", there's a one-to-one correspondence between the days of the week and the astrological planets.


    It's better than you think. In Russian days of week have names "the day after day without work" (Понедельник, Monday), "second day after day without work" (Вторник, Tuesday), "day at the middle of work week" (Среда, Wednesday), "fourth day" (Четверг, Thursday), "fifth day!!!" (Пятница, Friday), "Shabbat" (Суббота, Saturday) and "Resurrection" (Воскресенье, Sunday).
  • cappeca 2012-01-06 06:15
    MojoMonkeyfish:

    #DEFINE TWELVE = 12;

    function getMonthCountForSelectedYear()
    {
    return TWELVE;
    }


    There, I fixed it. Totally didn't account for twelve changing. Could have been a real pain in the butt.


    +1
    No magic numbers!
  • Going half way 2012-01-06 06:20
    Surely, that's all a step in the right direction, but still ridden with magic stuff and not the implemention of Zermelo-Fraenkel which I expected from you. I gave you everything i.e. zero and what do I get in return? You can do better guys!
  • makes sens 2012-01-06 06:22
    So in Russia months count you?
  • Bas 2012-01-06 06:23
    This looks like a fail attempt at a constant.
  • Nagesh 2012-01-06 07:58
    Nagesh:
    S&H IT:
    To be fair, the Hebrew calendar sometimes has 13 months, depending on if it's a leap year. http://en.wikipedia.org/wiki/Hebrew_calendar#Names_of_months


    Hindu Calendar also having extra month. Hindu follow lunar cycle, so no leap year. but sometime leap month. ;)

    I am saying that already, idiot.
  • Captain Boolean 2012-01-06 08:14
    int getMonthCountForSelectedYear(int year)
    
    {
    DateTime tmpDate = new DateTime(year, 1, 1);
    IList<DateTime> allDaysInYear = new List<DateTime>();
    while (tmpDate.Year == year)
    {
    allDaysInYear.Add(tmpDate);
    tmpDate = tmpDate.AddDays(1);
    }
    return allDaysInYear.Select(d => d.Month).Distinct().Count();
    }


    Future proofed?
  • SonicLover 2012-01-06 08:41
    I can actually defend this.

    This function, when originally written, was a lot more complicated and actually calculated how many months were in the given year. Most likely some idiot who didn't realize there were always 12 months in the year; I've seen enough TDWTF to know those are commonplace in these situations. Later someone noticed it always returned 12, and simplified it as such, and then deleted the year parameter in the function call because it wasn't used.

    As for why the function itself wasn't deleted, I'm sure there's a reason for that, too.
  • Jens 2012-01-06 09:22
    Reason: A static code analysis tool complained about a magic number.
  • golddog 2012-01-06 09:53
    undefined:
    da Doctah:
    PedanticCurmudgeon:
    EatenByAGrue:
    By a "globally used calendar", you're talking about the one with:
    * a 7-day week from Genesis
    * days named after Tyr, Odin, Thor, Frig, and Saturn
    * months named after Janus, Mars, Maia, Juno, and the deified Julius and Augustus
    Because that clearly in no way involves mythological creatures.
    It's even worse than you think. Since the other two days are named after the Sun and the Moon, and the five you mention are also planet names (think of the Romance language versions), the days of the week are actually based on astrology.

    It's even worse than you think. In Japanese the days of the week have names that essentially read "Sun-day", "Moon-day", "Fire-day", "Water-day", "Wood-day", "Gold-day" and "Earth-day". And since in Japanese the planet Mercury is "Water-star", Venus is "Gold-star", Mars is "Fire-star", Jupiter is "Wood-star" and Saturn is "Earth-star", there's a one-to-one correspondence between the days of the week and the astrological planets.


    It's better than you think. In Russian days of week have names "the day after day without work" (Понедельник, Monday), "second day after day without work" (Вторник, Tuesday), "day at the middle of work week" (Среда, Wednesday), "fourth day" (Четверг, Thursday), "fifth day!!!" (Пятница, Friday), "Shabbat" (Суббота, Saturday) and "Resurrection" (Воскресенье, Sunday).


    I don't roll on Shabbat!

    (OK, not quite the quote...)
  • xtremezone 2012-01-06 11:19

    function getMonthCountForSelectedYear(year)
    {
    var counts = {};

    for(var i=0; i<99999; i++)
    {
    counts["" + i] = 12;
    }

    var count = counts["" + year];

    if(typeof count != "undefined")
    {
    return count;
    }

    return "file not found";
    }
  • callcopse 2012-01-06 11:50
    You might get different numbers of days in the week if you live in Samoa, last week you only got 6.
  • Anon 2012-01-06 12:32
    That wasn't funny after the first day. Please stop.
  • Boog, I Am Your Father! (aka Behold The Return Of Zunesis!)! 2012-01-06 13:10
    Anon:
    Mason Wheeler:
    I used to write functions like that, but then I took a cock in the ass.
    That wasn't funny after the first day. Please stop.
    Better?
  • Jay 2012-01-06 14:14
    EatenByAGrue:
    The One True Calendar, though, is obvious: Start at UTC midnight on what is conventionally called Jan 1, 1970, and count the number of seconds (defined by cesium atoms) since then.


    Do you really think that would be a useful calendar?

    Okay, quick now: Is 1326419200 in the future or the past?

    Using this calendar, when does your next vacation start?

    Will it be day or night 2304180 seconds from now?

    This is a great time-keeping scheme for computers. Not so good for people.
  • Jay 2012-01-06 14:16
    WTF-land braver:
    the beholder:
    Kivi:
    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.
    Gee, why can't people ever be satisfied?
    function getMonthCountForSelectedYear(string strMonthName)
    
    {
    return 12;
    }
    There you go. Happy now?
    Congratulations sir! Between the parameter that doesn't relate to what the function is supposed to do, the hungarian notation, and the use of string where int would be a more sensible choice you managed to escalate this WTF to a new level.

    I tip my hat to you now.


    Good point.


    function getMonthCountForSelectedYear(boolean strMonthNumber)
    {
    return 12;
    }


    There, fixed that for you.
  • tom 2012-01-06 14:39
    It may seem pointless but I honestly prefer to read code with such functions instead of a codebase full of random integers with no comment whatsoever. It's not always obvious that a 12 represents the number of months or that the 7 in a function is the number of days.
  • Matt Westwood 2012-01-06 14:51
    tom:
    It may seem pointless but I honestly prefer to read code with such functions instead of a codebase full of random integers with no comment whatsoever. It's not always obvious that a 12 represents the number of months or that the 7 in a function is the number of days.


    This. Spent ages debugging a piece of code once where the bug was caused by the stupid prick of a programmer mistakenly using 12 for number of hours in the day. It took some time to find all the places where 12 was being used in this specific context (and not for number of months in the year) and changing it to a parameter whose value was assigned 24.

    I wouldn't use a function myself (static final int, maybe, or a PARAMETER if it were FORTRAN) but as tom says, better than a magic number.
  • Paul Renault 2012-01-06 15:55
    Actually, the line should've said something like:

    function getMonthCountForSelectedYear()
    {
    if Year .GT. 46BC
    return 12;
    }
  • Jim 2012-01-06 16:42
    That's an interesting way to avoid using magic numbers, but I would probably stick with the good old constant standby.
  • Luiz Felipe 2012-01-07 08:14
    Springer:
    MojoMonkeyfish:

    #DEFINE TWELVE = 12;

    function getMonthCountForSelectedYear()
    {
    return TWELVE;
    }


    There, I fixed it. Totally didn't account for twelve changing. Could have been a real pain in the butt.


    /* OBSOLETED
    #define ONE 1
    #define TWO (ONE+ONE)
    #define THREE (TWO+ONE)
    #define FOUR (TWO+TWO) //optimized to use TWO instead of ONE
    #define FIVE (FOUR+ONE)
    #define SIX (FOUR+TWO)
    #define SEVEN (FOUR+TWO+ONE) //Oh, now we are a geek...
    #define EIGHT (FOUR+FOUR) //more OPTIMIZATION
    #define NINE (EIGHT+ONE)
    #define TEN (EIGHT+TWO)
    #define ELEVEN (EIGHT+TWO+ONE)
    #define TWELVE (EIGHT+FOUR)
    ******* END OBOLETED *****/

    /***
    * The previous number definitions were inefficient, so we have
    *optimised for maximum usefulness (we leave how not to do it above
    *as an example for the n00bs who don't know better
    */
    #define ONE 1
    #define TWO (ONE<<ONE)
    #define THREE (TWO+ONE)
    #define OLD_FOUR (TWO<<ONE)
    #define FOUR (ONE<<TWO) // Much better than TWO<<ONE
    #define FIVE (FOUR+ONE)
    #define SIX (FOUR+TWO)
    #define SEVEN (FOUR+TWO+ONE)
    #define OLD_EIGHT (ONE<<THREE)
    #define EIGHT (FOUR<<ONE) //Could do ONE<<THREE, but better to use powers of two
    #define NINE (EIGHT+ONE)
    #define TEN (EIGHT+TWO)
    #define ELEVEN (EIGHT+TWO+ONE)
    #define TWELVE (EIGHT+FOUR)
    #define THIRTEEN (EIGHT+FOUR+ONE)
    #define FOURTEEN (EIGHT+FOUR+TWO)
    #define FIFTEEN (EIGHT+FOUR+TWO+ONE)
    #define OLDER_SIXTEEN (ONE<<FOUR)
    #define OLD_SIXTEEN (EIGHT<<ONE)
    #define SIXTEEN (FOUR<<TWO)


    No Magic numbers!!


    Except by that magic 1 in this line:
    #define ONE 1

    #include <time.h>
    #define ONE (Pow(CLOCKS_PER_SEC, NULL))
  • undefined 2012-01-07 15:07
    Luiz Felipe:
    Springer:
    MojoMonkeyfish:

    #DEFINE TWELVE = 12;

    function getMonthCountForSelectedYear()
    {
    return TWELVE;
    }


    There, I fixed it. Totally didn't account for twelve changing. Could have been a real pain in the butt.


    /* OBSOLETED
    #define ONE 1
    #define TWO (ONE+ONE)
    #define THREE (TWO+ONE)
    #define FOUR (TWO+TWO) //optimized to use TWO instead of ONE
    #define FIVE (FOUR+ONE)
    #define SIX (FOUR+TWO)
    #define SEVEN (FOUR+TWO+ONE) //Oh, now we are a geek...
    #define EIGHT (FOUR+FOUR) //more OPTIMIZATION
    #define NINE (EIGHT+ONE)
    #define TEN (EIGHT+TWO)
    #define ELEVEN (EIGHT+TWO+ONE)
    #define TWELVE (EIGHT+FOUR)
    ******* END OBOLETED *****/

    /***
    * The previous number definitions were inefficient, so we have
    *optimised for maximum usefulness (we leave how not to do it above
    *as an example for the n00bs who don't know better
    */
    #define ONE 1
    #define TWO (ONE<<ONE)
    #define THREE (TWO+ONE)
    #define OLD_FOUR (TWO<<ONE)
    #define FOUR (ONE<<TWO) // Much better than TWO<<ONE
    #define FIVE (FOUR+ONE)
    #define SIX (FOUR+TWO)
    #define SEVEN (FOUR+TWO+ONE)
    #define OLD_EIGHT (ONE<<THREE)
    #define EIGHT (FOUR<<ONE) //Could do ONE<<THREE, but better to use powers of two
    #define NINE (EIGHT+ONE)
    #define TEN (EIGHT+TWO)
    #define ELEVEN (EIGHT+TWO+ONE)
    #define TWELVE (EIGHT+FOUR)
    #define THIRTEEN (EIGHT+FOUR+ONE)
    #define FOURTEEN (EIGHT+FOUR+TWO)
    #define FIFTEEN (EIGHT+FOUR+TWO+ONE)
    #define OLDER_SIXTEEN (ONE<<FOUR)
    #define OLD_SIXTEEN (EIGHT<<ONE)
    #define SIXTEEN (FOUR<<TWO)


    No Magic numbers!!


    Except by that magic 1 in this line:
    #define ONE 1

    #include <time.h>
    #define ONE (Pow(CLOCKS_PER_SEC, NULL))


    #define ONE Pow(NULL, NULL)

  • dkf 2012-01-09 04:09
    Matt Westwood:
    Spent ages debugging a piece of code once where the bug was caused by the stupid prick of a programmer mistakenly using 12 for number of hours in the day. It took some time to find all the places where 12 was being used in this specific context (and not for number of months in the year) and changing it to a parameter whose value was assigned 24.
    That tells me that the code was not correctly factored, with uses of date calculations spread out all over the code rather than being concentrated into one expert module (file, class, etc., according to language).
  • Sir Robin The Not-So-Brave 2012-01-09 07:42
    CFM:
    Actually both English and German are derived from Proto-Germanic. English is no more derived from German than humans are derived from chimpanzees.

    Actually English is the bastard child of Frisian and French.
    (ok, not exactly, but in 1066 Anglo-Saxon and Old Frisian were still mutually intelligible)

    So English is like the early homo sapiens killing the neanderthal men and raping their women. It's exactly that. English sounds like a rape to the ears.
  • me 2012-01-19 16:37
    the beholder:
    Kivi:
    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.
    Gee, why can't people ever be satisfied?
    function getMonthCountForSelectedYear(string strMonthName)
    
    {
    return 12;
    }
    There you go. Happy now?


    Dude, this is JavaScript, JavaScript doesn't care how many parameters you give to function definitions, you can still call the function with arguments (and the word string there is a syntax error in JS).
  • JP 2012-08-06 17:16
    Nope, no functions to set selected year!