Why aren't Ranges Interfaces?

2015-06-26 Thread Jack Stouffer via Digitalmars-d-learn
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,

Re: Why aren't Ranges Interfaces?

2015-06-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 26 June 2015 at 18:37:51 UTC, Jack Stouffer wrote: The only reason I can think of to not do it this way is the weird distinction between structs and classes in D. If anything, C++ is the weird one in having two keywords that mean the same thing... But the reason comes down to

Re: Why aren't Ranges Interfaces?

2015-06-26 Thread Jack Stouffer via Digitalmars-d-learn
Thanks for the reply! I understand the reasoning now. On Friday, 26 June 2015 at 18:46:03 UTC, Adam D. Ruppe wrote: 2) interfaces have an associated runtime cost, which ranges wanted to avoid. They come with hidden function pointers and if you actually use it through them, you can get a

Re: Why aren't Ranges Interfaces?

2015-06-26 Thread Jack Stouffer via Digitalmars-d-learn
On Friday, 26 June 2015 at 19:40:41 UTC, rsw0x wrote: On Friday, 26 June 2015 at 19:26:57 UTC, Jack Stouffer wrote: Thanks for the reply! I understand the reasoning now. On Friday, 26 June 2015 at 18:46:03 UTC, Adam D. Ruppe wrote: 2) interfaces have an associated runtime cost, which ranges

Re: Why aren't Ranges Interfaces?

2015-06-26 Thread Ali Çehreli via Digitalmars-d-learn
On 06/26/2015 11:37 AM, Jack Stouffer wrote: easier if the different types of Ranges where just interfaces that you could inherit from. If you think you need polymorphic interfaces, the next chapter talks about inputRangeObject():

Re: Why aren't Ranges Interfaces?

2015-06-26 Thread rsw0x via Digitalmars-d-learn
On Friday, 26 June 2015 at 19:26:57 UTC, Jack Stouffer wrote: Thanks for the reply! I understand the reasoning now. On Friday, 26 June 2015 at 18:46:03 UTC, Adam D. Ruppe wrote: 2) interfaces have an associated runtime cost, which ranges wanted to avoid. They come with hidden function pointers

Re: Why aren't Ranges Interfaces?

2015-06-26 Thread Dicebot via Digitalmars-d-learn
On Friday, 26 June 2015 at 19:26:57 UTC, Jack Stouffer wrote: How much of a performance hit are we talking about? Is the difference between using an interface and not using one noticeable? It can be huge difference if you take inlning in mind. LDC is capable of flattening most simple

Re: Why aren't Ranges Interfaces?

2015-06-26 Thread rsw0x via Digitalmars-d-learn
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.

Re: Why aren't Ranges Interfaces?

2015-06-26 Thread Justin Whear via Digitalmars-d-learn
On Fri, 26 Jun 2015 19:26:56 +, Jack Stouffer wrote: Thanks for the reply! I understand the reasoning now. On Friday, 26 June 2015 at 18:46:03 UTC, Adam D. Ruppe wrote: 2) interfaces have an associated runtime cost, which ranges wanted to avoid. They come with hidden function pointers