Chapel: Should the new `list` type use 0- or 1-based indexing?

Created on 14 Aug 2019  路  4Comments  路  Source: chapel-lang/chapel

This issue asks whether the new list type we've introduced should use 0- or 1-based indexing by default. This is somewhat related to issue #12988 (though also somewhat independent since that issue talks about things baked into the language and this one is about a type in a standard library).

My understanding is that list types in most languages use 0-based indexing. Will it be too confusing to users coming to Chapel to have to switch from 0- to 1-based indexing when they use Chapel's lists?

Libraries / Modules Design

Most helpful comment

My opinion is that list should follow the precedent set down by #12988. That issue calls for internal consistency across all "indexable" constructs, baked into the language or not. In designing list, I tried to stay consistent with what I saw to be the current status quo.


I think a new user coming to Chapel will initially be confused and irritated by the change from 0 to 1 based indexing as a "sane default", however they would get used to it rather quickly (speaking from personal experience).

What I think would be even more confusing is a lack of consistency across different areas of the language.

The user has "correctly" learned that the sane default is that when not explicitly specified, Chapel domains start at 1. But then, their new understanding is challenged by other data structures like list that start with 0. Having to contextualize and remember what data structures start with 0 or 1 seems to be a bad thing to me.

All 4 comments

My opinion is that list should follow the precedent set down by #12988. That issue calls for internal consistency across all "indexable" constructs, baked into the language or not. In designing list, I tried to stay consistent with what I saw to be the current status quo.


I think a new user coming to Chapel will initially be confused and irritated by the change from 0 to 1 based indexing as a "sane default", however they would get used to it rather quickly (speaking from personal experience).

What I think would be even more confusing is a lack of consistency across different areas of the language.

The user has "correctly" learned that the sane default is that when not explicitly specified, Chapel domains start at 1. But then, their new understanding is challenged by other data structures like list that start with 0. Having to contextualize and remember what data structures start with 0 or 1 seems to be a bad thing to me.

What I found is that there is still inconsistency in language. If you see args in main function, they are 0 based whereas all the other data structures are 1 based so we might want to correct this as well if we are sticking to 1-based indexing.

If you see args in main function, they are 0 based whereas all the other data structures are 1 based so we might want to correct this as well if we are sticking to 1-based indexing.

My attitude about this continues to be that arrays should feel free use whatever indexing scheme is most natural for them. I believe that for the args array that is passed in to main() it is very reasonable to make it a 0-based array because (a) the 0th argument isn't exactly one of the user-supplied arguments to the executable, it's the executable name itself and (b) I'm not aware of a language that doesn't use this convention. Maybe put another way: I think of (and use) args 1-n differently in most languages than I do arg 0, so giving it an index that's somewhat special / off the beaten path seems reasonable and attractive to me.

Back on the topic being asked about on this issue about List, I think @dlongnecke-cray's argument that if most things are 1-based in Chapel, Lists should be as well holds up, linking the two decisions. But I still think that, as proposed in issue #12988, we should probably make other things 0-based as well, along with Lists.

We made lists 0-based in PR #14684 as part of the larger #12988 effort.

Was this page helpful?
0 / 5 - 0 ratings