Why aren't Ranges Interfaces?

rsw0x via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 26 12:03:14 PDT 2015


On Friday, 26 June 2015 at 18:37:51 UTC, Jack Stouffer wrote:
> I have been learning D over the past three weeks and I came to 
> the chapter in "Programming in D" on Ranges. And I am a little 
> confused on the choice to make Ranges based on the methods you 
> have in the struct, but not use a interface. With all of the 
> isInputRange!R you have to write everywhere, it just seems like 
> it would have made a lot more sense and made everyone's jobs 
> easier if the different types of Ranges where just interfaces 
> that you could inherit from.
>
> The only reason I can think of to not do it this way is the 
> weird distinction between structs and classes in D.

They're essentially compile-time interfaces.

I would prefer having a real name/binding implementation for 
this, like contract.


More information about the Digitalmars-d-learn mailing list