FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

IBuffer, IReader, IWriter
Goto page 1, 2  Next
 
Post new topic   Reply to topic     Forum Index -> Mango
View previous topic :: View next topic  

What do you think we should do?
Retain the interfaces, and damn the torpedoes!
25%
 25%  [ 2 ]
Change to an abstract base-class, but leave the names intact
25%
 25%  [ 2 ]
As above, but rename to AbstractWriter et. al.
37%
 37%  [ 3 ]
As above, but rename to AWriter et. al.
12%
 12%  [ 1 ]
Total Votes : 8

Author Message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Dec 06, 2005 3:52 pm    Post subject: IBuffer, IReader, IWriter Reply with quote

IBuffer, IReader and IWriter are interfaces to describe the model exposed by mango.io ~ the relevant concrete classes implement these interfaces, and the interfaces themselves are very useful for decoupling implementation details.

But ... interfaces come at a cost in D. I don't know the exact details but large/long interfaces, combined with deep inheritance, cause the executable to grow at an alarming rate. Then there's a small concern regarding codegen where an interface is cast to a concrete class (happens implicitly, quite a lot in Mango applications).

I spent a good deal of time weighing up pros and cons, testing various alternatives etc, and this is what I came up with:

Arrow Keep IConduit as an interface, since it's intended to be applied across a variety of implementations

Arrow change IBuffer, IReader, and IWriter to be abstract base-classes instead of interfaces

Making these changes cuts down the executable size quite notably, both in the data-segment and code-segment (the debug version of unittest.d was 260KB smaller). The codegen is better in numerous cases, since there's no need for interface-casts; there's less register spills, and more optimal call-dereferencing (the patch & jump tables are gone).

I like interface abstractions, but would be happy to see these three interfaces become base-classes instead, since I don't expect anyone else to implement compatable classes that couldn't also use the provided base-class. Note that this is currently not the case for IConduit ~ hence it remains as an interface.

Thus, the names IReader, IWriter, IBuffer should actually become AbstractReader, AbstractWriter, and AbstractBuffer respectively. Or perhaps AReader, AWriter, and ABuffer ~ though that sounds a little odd. Such a change would require application code change to these names, and/or use auto wherever possible. Auto is a great feature Wink

As it stands, all code will still compile just fine using the existing names, but be more efficient. The issue is one of naming consistency ~ these classes, speculatively, could not be used as interfaces any more.

What do you think we should do?
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Tue Dec 06, 2005 4:12 pm    Post subject: Reply with quote

Are the abstract classes performing the exact same purpose as the Interfaces were? Is the programmer required to override the abstract methods in the exact same way? Is there an otherwise subtle difference in meaning in this context, between "abstract class" and "interface"?

If there's no real difference in purpose, it seems that the abstract class is still really an interface from the library user's pespective. I'm thinking, therefore, it would be natural to keep the "I" in "IReader" prepended. "AbstractReader" and such, while not too horrible to look at, looks and feels overly wordy. "AReader" just looks plain ugly.

So I vote that the "IReader" naming convention remain. I'm not experienced enough to know if this breaks any cardinal programming rule or not. But it does "feel" acceptible.

-JJR
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Tue Dec 06, 2005 4:26 pm    Post subject: Reply with quote

I guess there is the danger of people assuming the IReader has all the features of a D Interface, if the name is left unchanged. Is there very much of a difference in this context, though? Is there anything that users might try to do with an IReader that they shouldn't if it's an abstract class?

-JJR
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Dec 06, 2005 4:48 pm    Post subject: Reply with quote

JJR wrote:
I guess there is the danger of people assuming the IReader has all the features of a D Interface, if the name is left unchanged. Is there very much of a difference in this context, though? Is there anything that users might try to do with an IReader that they shouldn't if it's an abstract class?

-JJR

Yes, that the issue. Things with an 'I' prefix are, by convention, interfaces. Mango follows this convention. Thus, it doesn't sit well when IWriter can no longer be used as an interface, but must be the superclass instead:

Code:
class MyFancyWriter : MyOtherClass, IWriter  // nope! can't do that anymore!

Other than that, the user sees no usage-distinction between interface and base-class.
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Tue Dec 06, 2005 5:00 pm    Post subject: Reply with quote

Shocked

Okay, I see the problem quite clearly now. Apparently it didn't hit me the first time around.

It would be equivalent to attempting multiple inheritance, which is illegal in D, if one attempted to use the abstract class as if it were an interface. That's bad. So I take back my vote. I obviously didn't think it through far enough.

One of "AbstractReader" or "AReader" will have to do. I don't know which, though. I don't like the looks of "AReader," but I'm beginning to wonder if that form is the way to go afterall. It's hard to compete with brevity.

-JJR
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Dec 06, 2005 5:08 pm    Post subject: Reply with quote

I don't think you can take back a vote here ~ But please vote again Smile
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Tue Dec 06, 2005 5:13 pm    Post subject: Reply with quote

Can't take back and can't vote again! Sad
Back to top
View user's profile Send private message
teqdruid



Joined: 11 May 2004
Posts: 390
Location: UMD

PostPosted: Tue Dec 06, 2005 5:22 pm    Post subject: Reply with quote

The LAST thing we should be doing at this point is renaming things that are used in a bajillion and one places. The API needs to stay as constant as possible, and since IReader et. al. are performing the duties of an interface, they can keep their name, I say.

As for D's interfaces: they suck!!!! I really wanted to use them in the container API, but they really aren't even worth considering. Forget code size and optimization: they outight don't work! Interfaces, it turns out, aren't covariant with ANYTHING, so.... well, I could keep ranting about a huge and obvious deficiency that Walter is fully aware of, but I've been doing nothing but that when it comes to interfaces for the past year anyway.

So I guess my vote is obvious: if it provides any benefits rip out as many interfaces as possible, but keep the names the same!!
Back to top
View user's profile Send private message Send e-mail AIM Address
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Tue Dec 06, 2005 5:22 pm    Post subject: Reply with quote

I voted for the last choice but I'd like to qualify it by suggesting that the interface method be reconsidered at a later date, simply because the codegen might improve before D hits 1.0. Unless the abstract base class method proves superior from a usability standpoint at any rate.
Back to top
View user's profile Send private message
Derek Parnell



Joined: 22 Apr 2004
Posts: 408
Location: Melbourne, Australia

PostPosted: Tue Dec 06, 2005 5:22 pm    Post subject: Re: IBuffer, IReader, IWriter Reply with quote

kris wrote:

Arrow change IBuffer, IReader, and IWriter to be abstract base-classes instead of interfaces

Would it be useful keeping the current interfaces and creating new abstract classes so that coders can choose which implementation model they want to use?
_________________
--
Derek
skype name: derek.j.parnell
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Dec 06, 2005 5:26 pm    Post subject: Reply with quote

JJR wrote:
Can't take back and can't vote again! Sad

Post your vote, then, and I''ll keep tally Wink
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Dec 06, 2005 5:37 pm    Post subject: Re: IBuffer, IReader, IWriter Reply with quote

Derek Parnell wrote:
kris wrote:

Arrow change IBuffer, IReader, and IWriter to be abstract base-classes instead of interfaces

Would it be useful keeping the current interfaces and creating new abstract classes so that coders can choose which implementation model they want to use?

That's an interesting idea; yet the core set of Reader/Writer derivatives would need to pick one, and they really are noticeably more efficient when using base-classes.

What does not change are the obvious uses for interfaces, such as IWritable and IReadable, which make a user-class compatable with the I/O system. There are a few other like that, which don't change either. I'm really just targeting those that expose minimal benefit from being an interface. I'll give your idea more thought ...
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Tue Dec 06, 2005 5:39 pm    Post subject: Reply with quote

+1 "As above, but rename to AWriter et. al."
-1 "Change to an abstract base-class, but leave the names intact"

A question, though: since "inheriting" multiple interfaces is legal, is there any place in Mango where switching to abstract classes would prevent the user from inheriting from more than one "interface" (now turned abstract class). Or, by design, does mango prevent the need for that.
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Dec 06, 2005 5:46 pm    Post subject: Reply with quote

teqdruid wrote:
The LAST thing we should be doing at this point is renaming things that are used in a bajillion and one places. The API needs to stay as constant as possible, and since IReader et. al. are performing the duties of an interface, they can keep their name, I say.

As for D's interfaces: they suck!!!! I really wanted to use them in the container API, but they really aren't even worth considering. Forget code size and optimization: they outight don't work! Interfaces, it turns out, aren't covariant with ANYTHING, so.... well, I could keep ranting about a huge and obvious deficiency that Walter is fully aware of, but I've been doing nothing but that when it comes to interfaces for the past year anyway.

So I guess my vote is obvious: if it provides any benefits rip out as many interfaces as possible, but keep the names the same!!

Very Happy

Just wanted to point out that the change to user-code is actually quite trivial ~ a search and replace across files, since the names are quite distinct from anything else. Still, you make a valid point.
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Dec 06, 2005 5:53 pm    Post subject: Reply with quote

JJR wrote:
+1 "As above, but rename to AWriter et. al."
-1 "Change to an abstract base-class, but leave the names intact"

A question, though: since "inheriting" multiple interfaces is legal, is there any place in Mango where switching to abstract classes would prevent the user from inheriting from more than one "interface" (now turned abstract class). Or, by design, does mango prevent the need for that.


The places where people are liable to do so are supported by interfaces, and that won't change (IReadable and IWritable, for example). The three stooges of IBuffer, IReader and IWriter are very unlikely to ever be used in the same manner; if for no other reason that there's just a boat-load of methods to implement Smile

In short, these three were originally interfaces "just in case".
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Mango All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group