• Rodnas (unregistered) in reply to frits
    frits:
    the beholder:
    Robyrt:
    And why is there a period after May?
    Because it's an abbreviation of the month named Mayonnaise. Which is fortunately four months apart from Apples, because apples and mayonnaise don't go well together

    Apparently you've never heard of Waldorf salad.

    Yeah, but what if you can't find any Waldorfs anywhere? Then you only got Apples en Mayonnaise.

  • (cs)

    Everyone knows it should have been 'App.' instead of 'Apples'.

  • Ken B. (unregistered) in reply to bl@h
    bl@h:
    function monther($inter), did anyone ready this as 'mother' ? I was expecting a return of $offspring
    No, that's the function seasoner() -- $offspring, $offsummer, $offautumn, and $offwinter. Well, those and $salt and $pepper.
  • Zapp Brannigan (unregistered)

    Another WTF is that this code is not international. Apple is only the 0th month in the United States. Almost every where else Orange is the frist month. Except for some Asian countries that use those little ears of corn.

  • The Nerve (unregistered) in reply to nobulate

    [quote user="nobulate"]This code is designed for something.. bigger. Any noob can just call:

    return months[$inter];

    Your code blows up in production when it encounters an unrecognized value. I see this way too often. Error checking FTW.

  • Rich (unregistered) in reply to nobulate

    Oh my God! A quintuple-rainbow!

    What can it mean????

    eros: a feeling of intense arousal at seeing multiples of an object normally observed singly.

  • (cs) in reply to Rodnas
    Rodnas:
    Yeah, but what if you can't find any Waldorfs anywhere? Then you only got Apples en Mayonnaise.

    I think we're just out of Waldorfs.

  • agb (unregistered) in reply to Rajendra Kumar
    Rajendra Kumar:
    Dear colleague, I have requirements for this exact code. Except I needing the months in Arabic or Hindi. Could you pls post the code? Also, I have doubts about JUnit testing for this. Could you pls provide this as well? It's urgent! pls! Tnanks in advance.

    Best comment I've ever read on TDWTF

  • vovo (unregistered) in reply to Aaron
    Aaron:
    No doubt the original code was just a bunch of if/else/return statements; somebody caught wind of this and told the code monkey, "you idiot, use an array!" And he did...

    You are so right, and after hours of trying to figure out why $months[1] didn't return "Jan.", he popped in "Apples", et voila!

    captcha: causa - produces effectas, three causas equal one trifecta

  • Matt (unregistered)

    Hahaha!

    This guy doesn't know about the "elseif" keyword in PHP.

  • Anon (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    Rodnas:
    Yeah, but what if you can't find any Waldorfs anywhere? Then you only got Apples en Mayonnaise.

    I think we're just out of Waldorfs.

    Have you tried the Ritz salad? It's apples, grapefruit and potatoes in mayonnaise.

  • CoderDan (unregistered) in reply to nobulate

    Ohhh I see the Navajo blanket pattern.....or it's half DNA for Fortran++

    captcha esse - This code appears to be a poorly written esse

    nobulate:
    This code is designed for something.. bigger. Any noob can just call:
    return months[$inter];
    No this was designed like this, it has a purpose. I think I found that purpose: copy/paste the code and zoom out, it makes a pattern... Now if we can just find out what it all means.

    [image]

  • Don (unregistered) in reply to frits
    frits:
    the beholder:
    ... apples and mayonnaise don't go well together

    Apparently you've never heard of Waldorf salad.

    I have heard of Waldorf salad (my wife makes it every year to go with Thanksgiving dinner) and I'd have to agree with the beholder.
  • (cs) in reply to Anon
    Anon:
    ObiWayneKenobi:
    Rodnas:
    Yeah, but what if you can't find any Waldorfs anywhere? Then you only got Apples en Mayonnaise.

    I think we're just out of Waldorfs.

    Have you tried the Ritz salad? It's apples, grapefruit and potatoes in mayonnaise.

    Nope, don't think I ever tried that.

    Don't think I ever will, either.

  • bricon (unregistered)

    I have had it with these monther-functing apples on this monther-functing site!

  • Leo (unregistered) in reply to EatenByAGrue
    EatenByAGrue:
    Apparently Kevin S's predecessors have the same power to create months out of thin air as Julius and Augustus Caesar.

    captcha: suscipere (to acknowledge a Roman-related wtf)

    Didn't they (or others for them) just rename existing months? Quintilis and Sextilis, IIRC. (i.e. 5th and 6th, with September/October/November/December, 7th/8th/9th/10th, following. They weren't really creative with their month names. N.B. the Roman new year started in March.)

    Speaking of Romans, I'm pretty sure Biggus Dickus or Naughtius Maximus could have written better code than this. And the Romans didn't even have 0, which made it tough for them to indicate successful termination of their C programs.

  • (cs)

    Calm down, it's Joomla. That code will fit right in.

  • TooTea (unregistered) in reply to Robyrt

    That's why it's called "a period"! It repeats itself, there has to be one every month...Otherwise it wouldn't be a period anymore.

    So to fix your question accordingly: Why the hell doesn't "Apples" have a period?

    aptent: someone good at building temporary canvas housings

  • TooTea (unregistered)

    In fact, "monther" is a completely valid function name. The author is just using the Reverse Hungarian notation, in which "monther" stands for a function that does something with months, "e"choes its output and is "r"eentrant

    nimis: misspelled name of an US Navy Fleet Admiral

  • Jay (unregistered)

    Oh, I see the problem! He left out

    if($inter == 0){
      echo $months[0];
    

    Add that and the code will be good.

  • Jay (unregistered) in reply to Buddy
    Buddy:
    I like the period after May, and how September is abbreviated to four characters while the other months are abbreviated three characters.

    And if it's okay to appreviate September to 4 letters, why bother to abbreviate June and July at all?

  • Jay (unregistered) in reply to Seriously curious
    Seriously curious:
    I will soon be looking for a job as a programmer. Do you really need no skills to get one?

    I recently had to modify an existing system, and as I reviewed the code, I was incredibly impressed at how the authors managed to get this thing to mostly work through shear diligence and hard work, despite an obvious total lack of any skill or talent.

  • (cs)

    I know posting "working" code isn't funny, but eh.

    function monther($m) {
      return date('M',mktime(1,1,1,min(12,max(1,(int)$m))));
    }

    The above function will, obviously, coerce any value into a valid one. Coercion not your style? You want to watch the world burn? Look no further:

    function monther2($m) {
      if (!ctype_digit((string)$m) || $m < 1 || $m > 12) {
        $up = new Exception('Lousy Smarch Weather!');
        throw $up;
      }
      return date('M',mktime(1,1,1,$m));
    }
  • boog (unregistered)

    At least he used "else if" instead of "if". He's coding for performance! How do you like them apples?

  • (cs) in reply to TooTea
    TooTea:
    That's why it's called "a period"! It repeats itself, there has to be one every month...Otherwise it wouldn't be a period anymore.

    So to fix your question accordingly: Why the hell doesn't "Apples" have a period?

    The apples are pregnant. Apparently they were the same apples with the brief cameo in "American Pie".

  • Sylver (unregistered) in reply to Seriously curious
    Seriously curious:
    I will soon be looking for a job as a programmer. Do you really need no skills to get one?
    Nope. You need to be brilliant to fix legacy code such as the one you have just read.
  • Sylver (unregistered) in reply to ubersoldat
    ubersoldat:
    You know, I've always have bad words for VBA programmers, but lately PHP people are getting in my nerves... I have a PHP guy on my side who codes with Dreamweaver and I'm pretty sure he'll pull something like this... Hell!
    Share the wealth, then.
  • (cs)

    By the time you get to the level of indentation that

    echo $months[7];
    is on, the air gets thinner, hence the need for a clairvoyant mountain sherpa.

  • Sylver (unregistered)

    In the spirit of fairness, let's remember that the file is called "learn". It's clearly written by someone who has little/no experience as a programmer and who managed to cobble code that actually did what was expected.

    It's worth a good laugh, but let's not be too mean, we don't know the circumstances of this learner.

  • Your Name (unregistered)

    Not a WTF:

    Thirty days hath September, Apples, June, and November; All the rest have thirty-one, Save February, with twenty-eight days clear, And twenty-nine each leap year.

  • (cs) in reply to Rajendra Kumar
    Rajendra Kumar:
    Dear colleague, I have requirements for this exact code. Except I needing the months in Arabic or Hindi. Could you pls post the code? Also, I have doubts about JUnit testing for this. Could you pls provide this as well? It's urgent! pls! Tnanks in advance.

    I award you one Internet, good sir. Well met.

  • (cs) in reply to Jay
    Jay:
    Seriously curious:
    I will soon be looking for a job as a programmer. Do you really need no skills to get one?

    I recently had to modify an existing system, and as I reviewed the code, I was incredibly impressed at how the authors managed to get this thing to mostly work through shear diligence and hard work, despite an obvious total lack of any skill or talent.

    Been there, seen that. Caused me to invent the phrase "beating the code into submission".

  • The Bytemaster (unregistered) in reply to Pedro
    Pedro:
    Smarch is the 13th month, not the 0th.

    Damn Smarch weather!

    That takes place durring the Swinter season, correct? (Though some people prefer the term Wummer)

  • Marc B (unregistered) in reply to Jay
    Jay:
    Buddy:
    I like the period after May, and how September is abbreviated to four characters while the other months are abbreviated three characters.

    And if it's okay to appreviate September to 4 letters, why bother to abbreviate June and July at all?

    Because then he'd need 5 characters (for "June." and "July.") -- look at "May.".

    This WTF is entertaining on so many levels...

  • Kyle (unregistered)

    Easy to know how this brilliant mind created that...

    In PHP documentation there's a lot of examples like that: $arrayName = array("apples", "bananas", "oranges", "pears"); http://br2.php.net/manual/en/function.array.php

    He just copy/paste the example and "adapted" it. Clever guy hahaha :)

  • (cs) in reply to Matt
    Matt:
    Hahaha!

    This guy doesn't know about the "elseif" keyword in PHP.

    Yes, because that is what's wrong with this code.

  • Marvin the Martian (unregistered) in reply to Don
    Don:
    I have heard of Waldorf salad (my wife makes it every year to go with Thanksgiving dinner)
    Hm --- "Waldorf salad, so greatly tasty you only want to eat it once a year"? Not really an endorsement.

    Any once-a-year food should be none-a-year; if it had any redeeming culinary capacity you'd eat it more often. I vote to outlaw those voluntarily-once-a-year-things, they're just masochism. File together with: inlaws for the holidays.

  • Kyle Z. (unregistered) in reply to Marvin the Martian

    Maybe that kind of food (once-a-year) is really good, but it's so caloric that if you eat more than one time a year you may have a heart-attack (like Christmas feast).

    But we're talking 'bout a salad... so I assume that is really bad and deserve a vote to outlaw.

  • The Nerve (unregistered) in reply to Kyle Z.
    Kyle Z.:
    Maybe that kind of food (once-a-year) is really good, but it's so caloric that if you eat more than one time a year you may have a heart-attack (like Christmas feast).

    But we're talking 'bout a salad... so I assume that is really bad and deserve a vote to outlaw.

    TAN alert!

    OTAH, it's a really boring Monday...holidays are specific times when you can indulge: I'm thinking candy (Easter), hot dogs (July 4th), carb-load (Thanksgiving and Christmas). Some people think you should indulge everyday and some think you should never indulge. Others think that it's ok to celebrate special occasions. I'm thinking the never-indulgers are the healthiest and the special-occasion-indulgers are the happiest.

  • Ken B. (unregistered) in reply to D-Coder
    D-Coder:
    Jay:
    Seriously curious:
    I will soon be looking for a job as a programmer. Do you really need no skills to get one?
    I recently had to modify an existing system, and as I reviewed the code, I was incredibly impressed at how the authors managed to get this thing to mostly work through shear diligence and hard work, despite an obvious total lack of any skill or talent.
    Been there, seen that. Caused me to invent the phrase "beating the code into submission".
    s/code/coder/
  • Ken B. (unregistered) in reply to Kyle Z.
    Kyle Z.:
    Maybe that kind of food (once-a-year) is really good, but it's so caloric that if you eat more than one time a year you may have a heart-attack (like Christmas feast).
    One word: Tiramisu.

    (The recipe I use has over 5000 calories in a 9x13 inch pan, and it's a "once-every-several-years" food around here. We never did the calculations on how much fat is in it.)

  • Ãà (unregistered)

    You guys are knocking him for not using PHP's native functions, but the "Apples" month should give you a clue. This guy was tasked with working with the new iCalendar, a product from Apple that adds an extra month you can use to play with your iPods, iPhones, and iPads.

  • Kevin S (unregistered)

    My name is Kevin S. I work on websites for a living.

    I don't remember submitting this article, but I swear to God that this is my life. I must have blacked out and send this in and forgotten about it.

  • Cargo Cult FTW (unregistered) in reply to Marvin the Martian
    Marvin the Martian:
    Don:
    I have heard of Waldorf salad (my wife makes it every year to go with Thanksgiving dinner)
    Hm --- "Waldorf salad, so greatly tasty you only want to eat it once a year"? Not really an endorsement.

    Any once-a-year food should be none-a-year; if it had any redeeming culinary capacity you'd eat it more often. I vote to outlaw those voluntarily-once-a-year-things, they're just masochism. File together with: inlaws for the holidays.

            // 0      // 1       // 2
    $year = array("Apples", "Oranges", "Cherries", 
    ...
         // 1976           //1977          //1978
       , "uh, chestnuts?", "uh, walnuts?", "uh, pistachios?", 
    // finally, 1979!
    "1979", "1980", "1981", "1982",
    ...
    "2010", "2011", "2012"); // I doubt this code will be in use 3 years from now
    
    if (currdate() == date(monther(11), dayer(5, 4), 1979)) {
      return "Thanksgiving 1979";
        else if (currdate() == date(monther(11), dayer(5, 4), 1979)) {
            echo "Thanksgiving " + year[1979];
            } else if (currdate() == date(monther(11), dayer(5, 4), year[1980]) {
               echo "Thanksgiving " + year[1980];
    ...
    
  • (cs) in reply to Your Name
    Your Name:
    Not a WTF:

    Thirty days hath September, Apples, June, and November; All the rest have thirty-one, Save February, with twenty-eight days clear, And twenty-nine each leap year.

    Thirty days hath September, April, June, and no wonder. All the rest eat peanut butter, Except Grandma, and she drives a Buick.

    (That's the way we learned it when I was a kid.)

  • Mogri (unregistered) in reply to The Nerve

    [quote user="The Nerve"][quote user="nobulate"]This code is designed for something.. bigger. Any noob can just call:

    return months[$inter];

    Your code blows up in production when it encounters an unrecognized value. I see this way too often. Error checking FTW.[/quote]

    PHP issues a notice and continues normally. Production sites don't set error reporting thresholds that low, so there is A) no blowing up and B) no error to check.

    It's lazy coding, but it's not actually wrong.

  • mathew (unregistered)

    Every Java programmer knows the 0th month is January.

    And the 13th month is Undecimber, and is numbered 12.

    (And no, I'm not making this up. Check the docs for java.util.Calendar if you don't believe me.)

  • spelley (unregistered) in reply to nobulate
    nobulate:
    This code is designed for something.. bigger. Any noob can just call:
    return months[$inter];
    No this was designed like this, it has a purpose. I think I found that purpose: copy/paste the code and zoom out, it makes a pattern... Now if we can just find out what it all means. <snip />

    Technically, copying and pasting ANY piece of code multiple times and zooming out will create a pattern.

  • ÃÃ (unregistered) in reply to mathew
    mathew:
    Every Java programmer knows the 0th month is January.

    And the 13th month is Undecimber, and is numbered 12.

    (And no, I'm not making this up. Check the docs for java.util.Calendar if you don't believe me.)

    http://java.sun.com/javase/6/docs/api/java/util/Calendar.html#UNDECIMBER

    Although Gregorian calendars don't use it, apparently lunar calendars do.

  • Al (unregistered)

    I'm still trying to figure out why the dev didn't just subtract a one from the input and not put in "apples" in the first place. The if-then is just... sad.

    CAPTCHA: saepius A pious sapient?

Leave a comment on “The 0th Month”

Log In or post as a guest

Replying to comment #:

« Return to Article