• Jay (unregistered) in reply to EatenByAGrue
    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 (unregistered) in reply to WTF-land braver
    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 (unregistered)

    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.

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

    Actually, the line should've said something like:

    function getMonthCountForSelectedYear() { if Year .GT. 46BC return 12; }

  • Jim (unregistered)

    That's an interesting way to avoid using magic numbers, but I would probably stick with the good old constant standby.

  • Luiz Felipe (unregistered) in reply to Springer
    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)
    </pre>
    

    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 (unregistered) in reply to Luiz Felipe
    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)
    </pre>
    

    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)

  • (cs) in reply to Matt Westwood
    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 (unregistered) in reply to CFM
    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 (unregistered) in reply to the beholder
    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 (unregistered) in reply to frits

    Nope, no functions to set selected year!

Leave a comment on “Nondeterministic Months”

Log In or post as a guest

Replying to comment #:

« Return to Article