>>> The month is OK as well, although it is *quite* confusing that
>>> Calendar.JANUARY is defined as 0 and not as 1. So you have to add 1 to
[quoted text clipped - 15 lines]
> or something like that (I guess it gets even more complicated because
> there is no such constructor for Calender)...
Well, you are right, this is very clumsy. But if you know that the user inputs
the month as a number, then why don't you just use calendar.setMonth(m-1)?
Also, in your example, you omitted a line of code: In general, I would assume
that the user has entered a *string*, so you have to use a parser anyway to make
it a month. Using Integer.parseInt(String) is the wrong decision anyway because
it returns an integer and not a month. Hence, you need to replace it by
DateFormat.parse(String) :-)
On the other hand, if you use a combo box or something, you can get the indices
right in the first place. Then, starting with 0 is making it easier, I think.
Apart from that, I have never encountered an application where the user enters
*only* a month, and if he enters a whole date you need a DateFormat anyway.
> You could design a programming language whose array-indices start with
> -3, that would make as much sense.
So you want array-indices to start with 1? I don't see the analogy.
Making January=0 was a design decision which has advantages and disadvantages. I
would not consider it a heavy bug, though.
Cheers,
Simon
Ingo R. Homann - 14 Jul 2006 13:06 GMT
Hi,
>>Because everyone would think that it is specified different. E.g. when
>>you want the user to enter a month (e.g. "6" for "June"), then you
[quoted text clipped - 12 lines]
> Well, you are right, this is very clumsy. But if you know that the user inputs
> the month as a number, then why don't you just use calendar.setMonth(m-1)?
In fact, I'm doing it the way you mention. :-)
But I am aware that this is the worst of both worlds: (1) It works aroud
(i.e. does not work with) localisation and (2) at first glance one could
wonder "Why does he want to take the previous month and not the month
entered?"
> Apart from that, I have never encountered an application where the user enters
> *only* a month, and if he enters a whole date you need a DateFormat anyway.
Oh well, I am programming a financial application where dues have to be
paid every month. So, in the database there is stored the year (as int)
and the month (as int). (It does not make sense to store that both
together in a field of type 'date' because the 'day' is obsolete.) Now,
when retrieving datasets from the database, of course, '1' means
'JANUARY'. When I want to print a notification/bill, I want to say "The
dues have to be paid until 15 of January 2007". So, I need to convert
the (int,int) to a Date. This occurs on several places...
>>You could design a programming language whose array-indices start with
>>-3, that would make as much sense.
>
> So you want array-indices to start with 1? I don't see the analogy.
No - I'm saying that an array-indes starting with something other that
the common '0' makes as much sense as defining JANUARY as something
other that the common '1'.
> Making January=0 was a design decision which has advantages and disadvantages. I
> would not consider it a heavy bug, though.
Eh... I do not see *any* advantage until now!
Ciao,
Ingo
Simon - 14 Jul 2006 13:23 GMT
>> Making January=0 was a design decision which has advantages and
>> disadvantages. I
>> would not consider it a heavy bug, though.
>
> Eh... I do not see *any* advantage until now!
* forcing users to use localization :-)
* Imagine you want to present a combo box that lets the user select a month, the
current month being preselected. How do you do this? I would write
static final String[] MONTHS = {"January", "February", ... };
JComboBox dateBox = new JComboBox(MONTHS);
dateBox.setSelectedIndex(calendar.get(Calendar.MONTH));
...
calendar.set(Calendar.MONTH, dateBox.getSelectedIndex());
print("You selected "+MONTHS[dateBox.getSlectedIndex()]);
Starting numbering with one you would have to either define
MONTHS = { "UNUSED", "January", "February", ...}
and prevent it from going into the ComboBox or add one in several places.
Cheers,
Simon
Oliver Wong - 14 Jul 2006 15:19 GMT
>> You could design a programming language whose array-indices start with
>> -3, that would make as much sense.
>
> So you want array-indices to start with 1? I don't see the analogy.
It's the princple of least surprise. When you design something, you want
to surprise your users as little as possible. To me, it's quite surprising
that 5 refers to June and not May, for example. For array-indices, starting
at 1 or 0 is okay (both makes sense), but -3 or 42 or anything else would be
quite surprising as well.
- Oliver