Hopefully I have something new to add to the argument

Sean Reque seanthenewt at yahoo.com
Tue Jan 8 07:50:12 PST 2008


James Dennett Wrote:
ps, but this is D, where member functions are virtual by default.
> 
> That's OK, it just makes writing safe code take a little more
> effort. 

Well if everyone is agreed that virtual function overriding is a bad idea, could we at least get some kind of a warning message at compile time when it happens? If the compiler is smart enough to stuff the v-table with garbage functions, it could also inform us that it is doing so. Of course, I still don't agree that the compiler shouldn't be placing the --correct-- functions in the v-table. The way it is now, whenever a programmer decides to create a class that inherits from another, he has to understand the entire class hierarchy of that inherited class to be sure he doesn't accidentally override a function that disables the class from taking advantage of inclusion polymorphism.

This HiddenFuncError feature breaks inclusion polymorphism, because having a class B inherit from class A no longer implies that an object of type B is fully capable of acting as an object of type A, regardless of whether or not the programmer intended to make it that way. That's a huge deal, because most of the advantage of OOP comes from this type of polymorphism, more so than encapsulation and data-aggregation.   The fact that this important piece of information is only revealed under specific conditions at runtime is what makes it so dangerous. In my opinion, this alone makes D OOP inferior to that of most other modern languages.

If this is going to be a permanent feature,  then there should at least be a way to get a warning at compile time that a class is hiding functions from a superclass, which could cause your entire program to crash.



More information about the Digitalmars-d mailing list