Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: PowerBuilder Starts array index at 1
|
Posted: Mar 8, 2002 2:07 PM
|
|
That sounds like the kind of "feature" that makes me glad I have never done any code maintenance on PowerBuilder projects. I would hate to work on code where some goofball thought it would so clever to have negative indices for some arrays, while others start at random numbers. It is much better to not have ambiguity about such things.
On the other hand, Python allows negative indices, but they have a specific and very useful meaning: they allow you to access elements backward, from the end of the list. Python also has slices, which in conjunction with negative indices is amazingly powerful and and allows you to solve some problems very simply and cleanly compared to other languages (except those that also have these features!).
To answer the original question seriously, the reason arrays in many modern languages start with 0 (instead of 1) if probably because the seminal influence of the C programming language, where an array index is an offset from the beginning address of the array. Therefore, the first element would have a no (zero) offset. Because many programmers are accustomed to this, languages like Java, which could have chosen either 0 or 1 as the first element of an array, choose 0.
I know from experience working with Delphi and Visual Basic that it is annoying to use to 1-based arrays after using 0-based (in C/C++) for many years, but if the whole language works that way, you can quickly get used to it. Since Borland's excellent C++ Builder product is based on Delphi, some of the 1-based collections show through; this makes for a even more confusion because you are working with some 1-based collections in a 0-based language. However, that is a minor inconvenience and I still like C++ Builder better than any other tool for C++ development.
|
|