Click here to Skip to main content
15,893,663 members

The Insider News

   

The Insider News is for breaking IT and Software development news. Post your news, your alerts and your inside scoops. This is an IT news-only forum - all off-topic, non-news posts will be removed. If you wish to ask a programming question please post it here.

Get The Daily Insider direct to your mailbox every day. Subscribe now!

 
GeneralRe: Interfaces considered harmful Pin
Pete O'Hanlon23-Jun-15 3:28
mvePete O'Hanlon23-Jun-15 3:28 
GeneralRe: Interfaces considered harmful Pin
Rob Grainger23-Jun-15 5:24
Rob Grainger23-Jun-15 5:24 
GeneralRe: Interfaces considered harmful Pin
Rob Grainger23-Jun-15 5:43
Rob Grainger23-Jun-15 5:43 
GeneralRe: Interfaces considered harmful Pin
Pete O'Hanlon23-Jun-15 5:50
mvePete O'Hanlon23-Jun-15 5:50 
GeneralRe: Interfaces considered harmful Pin
Duncan Edwards Jones23-Jun-15 3:38
professionalDuncan Edwards Jones23-Jun-15 3:38 
GeneralRe: Interfaces considered harmful Pin
Rob Grainger23-Jun-15 5:29
Rob Grainger23-Jun-15 5:29 
GeneralRe: Interfaces considered harmful Pin
Pete O'Hanlon23-Jun-15 5:51
mvePete O'Hanlon23-Jun-15 5:51 
GeneralRe: Interfaces considered harmful Pin
Rob Grainger23-Jun-15 9:08
Rob Grainger23-Jun-15 9:08 
I think "Uncle Bob" hit the point very well - there are cases where multiple inheritance really does make things easier, it avoids having to duplicate the code of an interface implementation multiple times. To my mind, a programming language should be about making life easier for the user (programmer) rather than ease of implementation (as long as there is a feasible implementation).

For most languages, however, I think that the fact that polymorphism is implemented through vtables (ultimately inherited from Simula, but usually more directly from C++) is the sticking point. Laying out vtables for multiple inheritance isn't too tricky, but usually involves some kind of pointer manipulation when casting pointers. C++'s solution is kind of horrible when you look at the technical details.

However, Eiffel comes up with an entirely different solution, which actually isn't that different from that used by Self (a dynamically-typed Smalltalk-like language that introduced the idea of prototype-based inheritance). With this scheme, rather than using vtables, polymorphism is implemented by, at the worst case, some kind of lookup. In the worst case, this results in worse performance than C++, but as Self illustrated (influencing pretty well all later VMs including Java, .NET and VM) it is possible to optimise the common paths, often resulting in the called function effectively being included inline at the call site (that's the essence of HotSpot compilation - which is exactly why Sun bought in many of the Self team to work on the Java VM).

In .NET, the closest to a solution is extension methods. However, unlike polymorphic calls these are statically bound and cannot be overridden, so are much more limited. Given the nature of the VM, I think the best we can hope for here is some kind of mixin-based implementation.

Mixins give many of the good features of Haskell typeclasses. One of the best examples there is the Comparable type class, which (in C# terminology) provides default implementations of most of the methods - if you provide one method, you get the others for free, so defining "<" for a type allows the system to infer the rest (of course, you can still implement these if you can find a better implementation).

To my mind, though, at essence it simply comes down to finding solutions which make it easier for a programmer to write correct code. Single inheritance limits the space of available solutions, and having used languages with multiple inheritance, I frequently find it frustrating having to repeat boilerplate code in a number of classes - a process which is more likely to produce errors, especially if you omit one of the cases during maintenance.

Of course, all this doesn't obviate the usefulness of interfaces as a design concept - it is a very good idea to have clearly defined interfaces between components. I just feel that interfaces (as in C# and Java) mix this concept with a limited form of multiple inheritance.

I'm very hopeful C++ concepts will be closer to my idea of this, than the C#/Java model. Rust also has some promise in this area. Traits in Rust are like both Concepts and Interfaces, but allow for default method implementations much like I discussed above for Comparable.

(Wow, that was a bit of diatribe).
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.

GeneralRe: Interfaces considered harmful Pin
Pete O'Hanlon23-Jun-15 9:29
mvePete O'Hanlon23-Jun-15 9:29 
GeneralRe: Interfaces considered harmful Pin
TheGreatAndPowerfulOz23-Jun-15 10:23
TheGreatAndPowerfulOz23-Jun-15 10:23 
GeneralRe: Interfaces considered harmful Pin
Rob Grainger23-Jun-15 22:35
Rob Grainger23-Jun-15 22:35 
GeneralRe: Interfaces considered harmful Pin
TheGreatAndPowerfulOz24-Jun-15 5:39
TheGreatAndPowerfulOz24-Jun-15 5:39 
GeneralRe: Interfaces considered harmful Pin
Rob Grainger24-Jun-15 9:41
Rob Grainger24-Jun-15 9:41 
GeneralRe: Interfaces considered harmful Pin
TheGreatAndPowerfulOz25-Jun-15 13:44
TheGreatAndPowerfulOz25-Jun-15 13:44 
GeneralRe: Interfaces considered harmful Pin
TheGreatAndPowerfulOz25-Jun-15 13:47
TheGreatAndPowerfulOz25-Jun-15 13:47 
GeneralRe: Interfaces considered harmful Pin
szukuro23-Jun-15 3:43
szukuro23-Jun-15 3:43 
GeneralRe: Interfaces considered harmful Pin
Vark11123-Jun-15 4:02
Vark11123-Jun-15 4:02 
GeneralRe: Interfaces considered harmful Pin
Rob Grainger23-Jun-15 5:33
Rob Grainger23-Jun-15 5:33 
GeneralRe: Interfaces considered harmful Pin
Vark11123-Jun-15 8:40
Vark11123-Jun-15 8:40 
GeneralRe: Interfaces considered harmful Pin
TheGreatAndPowerfulOz23-Jun-15 10:26
TheGreatAndPowerfulOz23-Jun-15 10:26 
GeneralRe: Interfaces considered harmful Pin
Rob Grainger23-Jun-15 22:44
Rob Grainger23-Jun-15 22:44 
GeneralRe: Interfaces considered harmful Pin
TheGreatAndPowerfulOz23-Jun-15 10:08
TheGreatAndPowerfulOz23-Jun-15 10:08 
GeneralRe: Interfaces considered harmful Pin
Rob Grainger23-Jun-15 22:37
Rob Grainger23-Jun-15 22:37 
NewsMicrosoft forced to explain who really gets Windows 10 for free Pin
adriancs22-Jun-15 15:05
mvaadriancs22-Jun-15 15:05 
NewsWill Oracle v. Google mean the death of the API economy? Pin
Kent Sharkey22-Jun-15 13:02
staffKent Sharkey22-Jun-15 13:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.