• (cs)

    Mmm. Sweet, sweet apples.

  • Michael (unregistered)

    why oh why?? at least after the third "if" the dev should have figured out that there is somehow a pattern....

  • (cs)

    Grind it up and make apple sauce

  • Scott (unregistered)

    Indenting code like that is for streamlining - it makes it faster.

  • GrailSeekr (unregistered)

    This post is pre-dated Apples 0th, 2038. Epoch fail.

  • EatenByAGrue (unregistered)

    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)

  • Candy (unregistered)

    Oh monther...

  • The Nerve (unregistered)

    Several things the developer needs to "learn."

    1. No such thing as const reference in PHP.
    2. Hard-coded values are generally bad.
    3. Whitespace is optional: ergo it's there to make the code more readable, not less.

    To his credit, at least this code is bulletproof. It will never print "Apples," nor will it crash if 13, -82, 3.14, or "Hallelujah" is passed.

    Captcha: amet -- amet fan is frequently disappointed.

  • Seriously curious (unregistered)

    I will soon be looking for a job as a programmer. Do you really need no skills to get one?

  • Mr. S (unregistered) in reply to The Nerve
    The Nerve:
    Several things the developer needs to "learn."
    1. No such thing as const reference in PHP.
    2. Hard-coded values are generally bad.
    3. Whitespace is optional: ergo it's there to make the code more readable, not less.

    To his credit, at least this code is bulletproof. It will never print "Apples," nor will it crash if 13, -82, 3.14, or "Hallelujah" is passed.

    Captcha: amet -- amet fan is frequently disappointed.

    What about FILE_NOT_FOUND?

  • Anonymous (unregistered)

    I always feel a bit wrecked when I wake up on New Year's Day but I never realised that I was sleeping through the entire month of Apples.

  • Robyrt (unregistered)

    And why is there a period after May?

  • The Nerve (unregistered)

    Oh, wait. I think I figured out how the indentation got that way. Here's the previous iteration.

    <? //convert month number to month name
    function monther($inter){
    $months = array("Apples", "Jan.", "Feb.", "Mar.", "Apr.", "May.", "Jun.", "Jul.", 
                    "Aug.", "Sept.", "Oct.", "Nov.", "Dec.");
            if($inter == 1){
                echo $months[1];
                } else {
                  if($inter == 2){
                    echo $months[2];
                  } else {
                    if($inter == 3) {
                       echo $months[3];
                  } else {
                    if($inter == 4) {
                       echo $months[4];
                    } else {
                      if($inter == 5) {
                       echo $months[5];
                    } else {
                       if($inter == 6) {
                          echo $months[6];
                       } else {
                          if($inter == 7) {
                            echo $months[7];
                       } else {
                          if($inter == 8) {
                             echo $months[8];
                          } else {
                             if($inter == 9) {
                                echo $months[9];
                             } else {
                                if($inter == 10) {
                                   echo $months[10];
                                } else {
                                   if($inter == 11) {
                                      echo $months[11];
                                   } else {
                                      if($inter == 12) {
                                         echo $months[12];
                                      }
                                   }
    // end converting month
    ?>
    

    Now to make sure it never prints "Apples" and to avoid an arithmetic operation and to make sure you don't have to do a type-check and never have an out-of-bounds error, this would be quicker (assuming equal penalties of extra checks) for valid values Jan.-Mar. Ergo, perhaps we can rule out insanity and settle for a verdict of felony ignorance and misdemeanor pre-mature optimization.

  • Anonymous (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?
    It's possible, the only problem is that you'll end up working for the sort of company that gets posted about on TDWTF. Trust me, that's not something you want. Far better to get a decent job with an employer that appreciates a genuine skillset.
  • robo (unregistered)

    Truly inspirational

  • Sam (unregistered)

    If the 0th month was "Smarch" I might have died.

  • Pokepoke (unregistered)

    If the earth dies and the 0 month occurs, this guy is prepared!

  • notadummy (unregistered)

    I consider myself not a programmer. I hack around with PHP now and again to get things done and it sometimes works. I learned how to "program" things by looking at someone else's (who I was told later wasn't a very good programmer) ColdFusion work and copying it.

    I would not ever take a job as a programmer because I simply am not qualified. Nowhere near.

    And yet, even I wouldn't produce code like that. I would be a step up from whoever wrote that code. Outstanding.

  • bl@h (unregistered)

    function monther($inter), did anyone ready this as 'mother' ? I was expecting a return of $offspring

  • Rajendra Kumar (unregistered)

    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.

  • (cs)

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

  • MP (real) (unregistered)

    I'm not sure, but I may be Kevin S., because even though I didn't submit this story, I'm pretty sure I work on this "codebase".

    captcha: jugis - When the previous developer returned for a visit, I went straight for the jugis.

  • MP (real) (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.

    TRWTF

  • wtf (unregistered) in reply to Aaron

    Apples is the cruelest month. Except for Frimaire.

  • (cs) 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...

    Right...Because an array is the right answer.

  • prionic6 (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.

    Great comment! Enjoyed it. Would read again.

  • VictorSierraGolf (unregistered)

    AAAAAaaaaaaaarhg! My head hurts...

  • (cs) in reply to prionic6

    Thanks! ;)

  • the beholder (unregistered) in reply to Robyrt
    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
  • (cs) in reply to the beholder
    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.

  • (cs) 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?

    You need the most important skill of all: The ability to hoodwink whoever is interviewing you that you know everything.

  • Buddy (unregistered)

    I like the period after May, and how September is abbreviated to four characters while the other months are abbreviated three characters.

  • (cs)

    Ah, a classic WTF. Bad indenting, hilarious! What a shame it ruins otherwise great code!

  • (cs)

    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!

  • gizmore (unregistered)

    It`s also nice to read the src-comment "convert month number to month name" and then using echo to output it.

    Good luck here is a wrapper function in case you need to use the value instead of just outputting it:

    function getMonther($inter) { ob_start(); monther($inter); return ob_get_clean(); }

  • Burpy (unregistered)

    As long as a code has the slightest thing to do with Apple then it's definitely a WTF!

  • (cs)

    function monther($inter) does not return any value. It does, however, echo the answer. WTF!

  • (cs) in reply to The Nerve
    The Nerve:
    To his credit, at least this code is bulletproof. It will never print "Apples," nor will it crash if 13, -82, 3.14, or "Hallelujah" is passed.
    'Bulletproof' is only a good attribute for code that you don't want to kill with a hail of gunfire.
  • Bryan The K (unregistered)

    The real wtf is that he was supposed to use, string date ( string $format [, int $timestamp ] right??

    Either that or he was supposed to be using XML somehow. Maybe to have a MySQL database that returns the month of the year when you pass in the numerical value. This comes back as an XML Response that he can de-serialize and echo out.

    If you'll excuse me I have a wooden table, a camera and a print-out that I need to address.

  • (cs) in reply to Buddy

    It shows a period after every month on my tty. Do I need Web 2.0 uniascii codepage support perhaps?

  • Darth Tabeous (unregistered)

    I have indented the code...pray I don't indent it any further.

  • John (unregistered) in reply to The Nerve

    The real WTF is that since all arrays in PHP are hashes and digits are transparently converted; the entirety of the code could be done with no bump element, an integer=>string array, and an isset test with a throw when there's no conversion.

    Oi! What a mess. See the trees not the forest.

  • kjordan (unregistered)

    No oranges month?

  • Ronan (unregistered)

    Not really a WTF, that's the standard way of coding with Joomla (according.

  • (cs)

    That is a monther-functer.

  • Ronan (unregistered)

    ...according to the code of most extensions available on the official joomla repository).

  • Bernie (unregistered) in reply to Robyrt
    Robyrt:
    And why is there a period after May?
    Testing. Notice that all the valid months end with a period while Apples does not.
  • Peter (unregistered)

    Eat an apple, and go with the flow man!

  • (cs)

    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]
  • Pedro (unregistered) in reply to Sam

    Smarch is the 13th month, not the 0th.

    Damn Smarch weather!

    Captha: acsi - Dyslexic character code

Leave a comment on “The 0th Month”

Log In or post as a guest

Replying to comment #:

« Return to Article