Version française
Home     About     Download     Resources     Contact us    
Browse thread
C++/C# inheritance is bad?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: Re: On the benefits of OO, Was: [Caml-list] C++/C# inheritance is bad?
Zitat von Jan Kybic <>:

> > I have a more fundamental question: Is inheritence actually useful
> for
> > anything?  By which I mean, are there real world problems which are
> > solved elegantly with inheritence which are otherwise difficult to
> > solve?  I'm not sure I've seen many.  I have seen many very
> tortuous
> > class hierarchies though.
> >
> Some personal thoughts:
> I think the OO methodology is good for creating reusable components
> and maintaining a clean interface between them.

This also can be done with module system.
Functors for example can help a lot here.

> I develop complex algorithms which consist of many building blocks.
> Often, I need to try many variants before settling on a final
> solution, sometimes there is not even any final solution - for each
> subclass of a problem a different sub blocks might be appropriate.
> It is a great time-saver if the building blocks can be swapped with
> as little
> change in the code as possible.

Modules and Functors are very good for this task.
Just change the used module.

If you need a certain flexibility that modules can not offer,
for example, selecting certain implementations by user input,
both paradigms can be combined: use OO-style for the selection
of the seperate modules.

> The inheritance is then a convenient way of code reuse.

But it's very overrated.
Inheritance is the most obvious OO technique,
and the way, how people tries to convince
non-OO-programmers from the advantage of OO.
But there are many other OO mechanisms,
and ofteh it turns out that inheritance is used, where
other OO-technics would be much better.
With setting OO equal to inheritance, code will become
weid and clumsy. So the advantages of OO can't be turned
into advantages for the code.

> Code reuse is important because it avoids code duplication.
> And code duplication is bad because it makes maintenance hard.

Yes, and modules and functors are very good here.

> However, I am not using the OO features of Ocaml much, mainly because
> of the speed penalty.

If you don't use them, it looks to me that you don't need them.

If there really would be a need for OO in your code,
you would use it, otherwise your program could not run as intended.

So: you use OO for your own convenience (because you seem to be used to
it), even other techniques are sufficient for gaibning the goal.

I would use OO , when it is necessary, and not, if not.

OO paradigm does solve some problems of non-OO code.
But most of them can be done with modules and functional programming
techniques (higher order functions) also.

For many tasks OO is used like Bells-and-Whistles, and inheritance as an
addiction. This makes code not better. Using that techinques that help,
and not those, that are hype, will make code better.