From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id E058EBB84 for ; Sat, 17 Jan 2009 13:40:24 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aj4DAPZfcUnAbSoIgWdsb2JhbACUAwEBFiK4BoVz X-IronPort-AV: E=Sophos;i="4.37,280,1231110000"; d="scan'208";a="33877413" Received: from einhorn.in-berlin.de ([192.109.42.8]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 Jan 2009 13:40:24 +0100 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: Received: from einhorn.in-berlin.de (localhost [127.0.0.1]) by einhorn.in-berlin.de (8.13.6/8.13.6/Debian-1) with ESMTP id n0HCeNiH014450 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sat, 17 Jan 2009 13:40:23 +0100 Received: (from www-data@localhost) by einhorn.in-berlin.de (8.13.6/8.13.6/Submit) id n0HCeNLX014447 for caml-list@yquem.inria.fr; Sat, 17 Jan 2009 13:40:23 +0100 X-Authentication-Warning: einhorn.in-berlin.de: www-data set sender to oliver@first.in-berlin.de using -f Received: from dslb-088-073-126-245.pools.arcor-ip.net (dslb-088-073-126-245.pools.arcor-ip.net [88.73.126.245]) by webmail.in-berlin.de (IMP) with HTTP for ; Sat, 17 Jan 2009 13:40:23 +0100 Message-ID: <1232196023.4971d1b72fe87@webmail.in-berlin.de> Date: Sat, 17 Jan 2009 13:40:23 +0100 From: Oliver Bandel To: caml-list@yquem.inria.fr Subject: Re: On the benefits of OO, Was: [Caml-list] C++/C# inheritance is bad? References: <20090116155805.GA8664@annexia.org> <87d4enfc5b.fsf_-_@fel.cvut.cz> In-Reply-To: <87d4enfc5b.fsf_-_@fel.cvut.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.6 X-Scanned-By: MIMEDefang_at_IN-Berlin_e.V. on 192.109.42.8 X-Spam: no; 0.00; bandel:01 in-berlin:01 elegantly:01 functors:01 variants:01 swapped:01 functors:01 ocaml:01 oliver:01 oliver:01 avoids:01 caml-list:01 functions:01 reuse:01 reuse:01 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. Ciao, Oliver