- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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.
Admin
Good point.
There, fixed that for you.
Admin
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.
Admin
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.
Admin
Actually, the line should've said something like:
function getMonthCountForSelectedYear() { if Year .GT. 46BC return 12; }
Admin
That's an interesting way to avoid using magic numbers, but I would probably stick with the good old constant standby.
Admin
Except by that magic 1 in this line: #define ONE 1
#include <time.h> #define ONE (Pow(CLOCKS_PER_SEC, NULL))
Admin
#define ONE Pow(NULL, NULL)
Admin
Admin
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.
Admin
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).
Admin
Nope, no functions to set selected year!