www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Array indices and (in|ex)clusive ranges

reply Michiel Helvensteijn <m.helvensteijn.remove gmail.com> writes:
I've been reading the "Case Range Statement" topic with some interest.

It has occurred to me that all those problems would be solved if array
indices started with 1 instead of 0. Just let arrays be indexed from 1 to
size and make the a..b syntax inclusive.

I'll be expecting this change to be put in D forthwith. ;-)

No, but seriously. Complete loss of backwards compatibility aside, wouldn't
this change solve the range problem to everyones satisfaction? Like, in
theory?

-- 
Michiel Helvensteijn
Jul 08 2009
next sibling parent Bill Baxter <wbaxter gmail.com> writes:
On Wed, Jul 8, 2009 at 10:48 AM, Michiel
Helvensteijn<m.helvensteijn.remove gmail.com> wrote:
 I've been reading the "Case Range Statement" topic with some interest.

 It has occurred to me that all those problems would be solved if array
 indices started with 1 instead of 0. Just let arrays be indexed from 1 to
 size and make the a..b syntax inclusive.

 I'll be expecting this change to be put in D forthwith. ;-)

 No, but seriously. Complete loss of backwards compatibility aside, wouldn't
 this change solve the range problem to everyones satisfaction? Like, in
 theory?

I think the answer is "no". Probably most everything to say about it has already been said in this thread: http://lambda-the-ultimate.org/node/1950 --bb
Jul 08 2009
prev sibling next sibling parent dsimcha <dsimcha yahoo.com> writes:
== Quote from Michiel Helvensteijn (m.helvensteijn.remove gmail.com)'s article
 I've been reading the "Case Range Statement" topic with some interest.
 It has occurred to me that all those problems would be solved if array
 indices started with 1 instead of 0. Just let arrays be indexed from 1 to
 size and make the a..b syntax inclusive.
 I'll be expecting this change to be put in D forthwith. ;-)
 No, but seriously. Complete loss of backwards compatibility aside, wouldn't
 this change solve the range problem to everyones satisfaction? Like, in
 theory?

I've suggested 0.5 as a compromise in the past (ok I haven't but that's beside the point). I feel that this suggestion was dismissed without fair consideration.
Jul 08 2009
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 08 Jul 2009 13:48:01 -0400, Michiel Helvensteijn  
<m.helvensteijn.remove gmail.com> wrote:

 I've been reading the "Case Range Statement" topic with some interest.

 It has occurred to me that all those problems would be solved if array
 indices started with 1 instead of 0. Just let arrays be indexed from 1 to
 size and make the a..b syntax inclusive.

 I'll be expecting this change to be put in D forthwith. ;-)

 No, but seriously. Complete loss of backwards compatibility aside,  
 wouldn't
 this change solve the range problem to everyones satisfaction? Like, in
 theory?

Maybe, but it sure introduces a plethora of other problems :) For instance, all reasonable processors use 0-based indexes, so you have to shoehorn your 1-based design into it, causing some code bloat, and loss of performance. Using zero-based indexes has many advantages, and you have to look at the whole picture, not just range statements. -Steve Marty: Why don't you just make ten louder and make ten be the top number and make that a little louder? Nigel: [pause] These go to eleven.
Jul 08 2009