Argumnentation against external function operator overloading is unconvincing

pineapple via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 25 03:58:24 PDT 2016


On Sunday, 25 September 2016 at 04:06:41 UTC, Jonathan M Davis 
wrote:
> Considering that a random access range is essentially an 
> abstraction for a dynamic array and that ranges were designed 
> with that in mind, I don't know how you can argue that dynamic 
> arrays shouldn't be treated as ranges.
>
> The auto-decoding is certainly an issue, but that only affects 
> ranges of char and wchar. The vast majority of dynamic arrays 
> are perfectly normal ranges.
>
> - Jonathan M Davis

Phobos' range facilities vomit when you try to deal with static 
arrays, and they have to be coerced into dynamic arrays before 
they can be dealt with. This is silly.

It gets under my skin that length and opIndex and opSlice produce 
different results in phobos' ranges depending on one's current 
position in the range. This doesn't make sense to me, and the 
only reason I can conceive of it having become how ranges work 
throughout phobos is because that's how dynamic arrays work if 
you force them to act as though they were ranges.

In every single other language I've used, the concept of an 
Iterable and an Iterator are distinct and very separate. An 
Iterator is something that can be iterated over; an Iterable is 
something which can produce an Iterator for iterating over its 
contents. In D, arrays are Iterables, and phobos endeavors to 
force them to be Iterators as well. It defies years of basic 
design wisdom regarding how to differentiate a collection and the 
means by which one enumerates the items in that collection.

Arrays are Iterables which should be able to produce an Iterator, 
in D's case a range. They should not themselves be Iterators.

"Poisoned m&ms are certainly an issue, but that only affects 
people who unwittingly eat them. You see, the vast majority of 
m&ms are perfectly innocuous."


More information about the Digitalmars-d mailing list