1

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?

asked Aug 17, 2015 at 23:36

1 Answer 1

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.

answered Aug 18, 2015 at 1:25
4
  • Should it be '' rather than None, though? The latter would cause noticeable trouble more quickly if something did end up accessing month_name[0]. Commented Aug 18, 2015 at 9:26
  • You can put whatever you want there. Commented Aug 18, 2015 at 14:38
  • Why not overload the [] function such that month_name[0] throws an error? Commented Aug 18, 2015 at 20:55
  • That's probably a good idea. Commented Aug 18, 2015 at 21:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.