caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Oliver Bandel <oliver@first.in-berlin.de>
To: caml-list@yquem.inria.fr
Subject: Re: On the benefits of OO, Was: [Caml-list] C++/C# inheritance is bad?
Date: Sat, 17 Jan 2009 13:40:23 +0100	[thread overview]
Message-ID: <1232196023.4971d1b72fe87@webmail.in-berlin.de> (raw)
In-Reply-To: <87d4enfc5b.fsf_-_@fel.cvut.cz>

Zitat von Jan Kybic <kybic@fel.cvut.cz>:

> > 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.


Ciao,
   Oliver


  reply	other threads:[~2009-01-17 12:40 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-16 15:18 Kuba Ober
2009-01-16 15:58 ` [Caml-list] " Richard Jones
2009-01-16 16:28   ` On the benefits of OO, Was: " Jan Kybic
2009-01-17 12:40     ` Oliver Bandel [this message]
2009-01-16 18:27 ` Raoul Duke
2009-01-16 21:42   ` Kuba Ober
2009-01-17  3:14     ` Sashan Govender
2009-01-17 14:07       ` Kuba Ober
2009-01-18  6:24         ` Stefano Zacchiroli
2009-01-17 13:27 ` Jon Harrop
2009-01-17 14:35   ` Kuba Ober
2009-01-17 16:59     ` Jon Harrop
2009-01-17 21:22       ` Kuba Ober
2009-01-17 22:17         ` Jon Harrop
2009-01-17 23:29           ` David Teller
2009-01-17 23:49             ` Jon Harrop
2009-01-19 16:22       ` Visitor in OCaml [was Re: [Caml-list] C++/C# inheritance is bad?] Yoann Padioleau
2009-01-19 16:41         ` blue storm
2009-01-19 17:49           ` Richard Jones
2009-01-19 17:52           ` Visitor in OCaml Christophe TROESTLER
2009-01-21 20:09           ` Yoann Padioleau
2009-01-22  4:03             ` [Caml-list] " Yaron Minsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1232196023.4971d1b72fe87@webmail.in-berlin.de \
    --to=oliver@first.in-berlin.de \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).