← Back to context

Comment by fuzztester

1 year ago

>Don't all of Wirth's languages let you use any ordinal as the array index? At leat in Pascal you can declare an integer subtype, say 7..17 and use that as the type of the index of an array. Then the first element is item 7.

Can confirm that about Pascal, since I had used it a lot earlier.

Don't know about the other Wirth languages.

>The point being that both the start at 0 and start at 1 camps can have it their own way.

Yes, but that is not the only point. Another reason, and maybe the more important one, is that having such custom array index ranges, can more naturally fit the problem domain. In fact you can even use user defined types for the ranges, e.g. so you can define an array with Sunday to Saturday as the indices and the values of (the equivalent of) an enum representing 1) weekdays and 2) weekends, as the corresponding values.

Then your code involving days and weekdays and weekends, will read more naturally, so will be easier to both read and maintain. And you only have to do those custom definitions once, up front, so it is not much extra work for the benefit gained.