Half-open versus closed ranges, was Re: Interesting GCC extensions

Rainer Deyke rainerd at eldwood.com
Mon Sep 28 22:15:39 PDT 2009


Adam D. Ruppe wrote:
> I think this makes D's syntax superior. We can say a[0..$] where
> gcc would have to use the more annoying a[0...$-1].
> (pretending the $ worked of course)

Although I generally prefer half-open ranges over closed ranges, both
have their advantages and disadvantages.

Advantages of half-open ranges:
  - Empty ranges are valid: [0 .. 0]
  - Easy for subranges to go to the end of the original: [x .. $]
  - Easy to split ranges: [0 .. x] and [x .. $]

Advantages of closed ranges:
  - Symmetry.
  - Arguably easier to read.
  - ['a' ... 'z'] does not require awkward '+ 1' after 'z'.
  - [0 ... uint.max] is possible.


-- 
Rainer Deyke - rainerd at eldwood.com



More information about the Digitalmars-d mailing list