The documentation states:
An array that represents the months of the year in the current locale. This follows normal convention of January being month number 1, so it has a length of 13 and month_name[0] is the empty string.
Is this level of skeuomorphism warranted? Or is it confusing and potentially bug prone to start an array of expected values with no value?
1 Answer 1
It's better (and less confusing) to have the empty [0] placeholder at the beginning of the array so that you can just plug the month directly into the array indexer, than it is to start January at month 0 and have to perform a bit of conversion math to get the correct array index each time.
Sensible date implementations should not allow a month zero. Note that, for historical reasons, arrays typically start at an array index of zero.
-
Should it be
''
rather thanNone
, though? The latter would cause noticeable trouble more quickly if something did end up accessingmonth_name[0]
.jonrsharpe– jonrsharpe2015年08月18日 09:26:01 +00:00Commented Aug 18, 2015 at 9:26 -
You can put whatever you want there.Robert Harvey– Robert Harvey2015年08月18日 14:38:02 +00:00Commented Aug 18, 2015 at 14:38
-
Why not overload the [] function such that month_name[0] throws an error?Adam Ashwal– Adam Ashwal2015年08月18日 20:55:06 +00:00Commented Aug 18, 2015 at 20:55
-
That's probably a good idea.Robert Harvey– Robert Harvey2015年08月18日 21:02:56 +00:00Commented Aug 18, 2015 at 21:02