Re: OT: CoolIris releases PicLens 1.6 for Firefox Mac & Win



Captain Jake wrote:


Interesting comments on C++, a language I've always liked more than
most of the Delphi community does. Would you care to expand
on/demonstrate the points you made above about C++, by any chance?

Sure. Let's take the C++ semantics of "virtual" as an example.

class A {
public:

virtual int foo(int i);
}

class B: public A {

int foo(int i);
}


Class B inherits from A and overrides the virtual method foo introduced
in A.

Now then. Time passes. Eventually someone comes along and modifies
the base class. There are multiple avenues of silent failure that C++
will not alert you to.

First, what if Foo is deleted from the base class? B::foo is no longer
overriding the base class method, it's just introducing a new foo
method. Multiply this by a dozen or more descendents of A and you have
a truckload of foo running around that are completely unrelated.

C++ does not distiguish between introducing a new virtual method and
overriding an existing virtual method. For code maintenance over the
long haul, this is a problem. It is very rare that code that was
written to override a base behavior will work correctly if the base
behavior is no longer there. And yet, C++ cannot not flag this as a
compile time error.

The opposite case (method insertion) is also problematic - and more
common than the case above: Let's say B introduces a new virtual
method called Bar. The base class doesn't have a Bar, so there's no
issue. Some time later, however, if someone introduces a Bar into the
base class A, you'll have a problem. If the method Bar added to A
happens to be a virtual method, but the params don't match the Bar
introduced in B, then you'll get a compile error even though
technically the two methods could be maintained independently without
runtime issues. If you're lucky, you'll get a compile time error.
It's when you don't get a compiler error that the real nightmares begin.

This is covered in detail in Chapter 3 of "Delphi Component Design".

-Danny

--
Discover More with CoolIris: http://www.cooliris.com
.



Relevant Pages

  • a subtle change in behavior...
    ... 'public' access with 'public' and the code would still compile. ... the access of a virtual method defined in a base class. ... to create derived classes with the virtual method polymorphed as 'protected' ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Strategy Pattern problem (or casting problem)
    ... Bar b = new Bar; ... class method which is called by the base class logic. ... > Philippe SILLON ... productive O/R mapping for .NET: http://www.llblgen.com My .NET Blog: http://weblogs.asp.net/fbouma Microsoft C# MVP ...
    (microsoft.public.dotnet.languages.csharp)
  • strange performance of nested virtual methods
    ... I wanted to decorate the features of a base class by declaring a ... virtual method and deriving a new class, ... calling time per nesting level is very irregular. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Down casting objects
    ... Whats the best way to down cast obj to the correct type? ... better if you could simply declare a common abstract or virtual method in the base class that each derived class could override. ... then the best way to represent that is with a single overridden abstract or virtual method in the base class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: callable virtual method
    ... Does anyone know a way to write virtual methods that will raise an exception only if called without being overridden? ... Currently in the virtual method I'm checking that the class of the instance calling the method has defined that method as well. ... I'd like the base class to be virtual. ... Interface.method(self) # I want to process the cool stuff done my the base Interface ...
    (comp.lang.python)