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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id D956BBBCA for ; Wed, 27 Feb 2008 11:26:05 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAE/JxEfAXQInh2dsb2JhbACQZwEBAQgKKYENmyY X-IronPort-AV: E=Sophos;i="4.25,412,1199660400"; d="scan'208";a="7755283" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 27 Feb 2008 11:26:05 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m1RAQ5qp003617 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 27 Feb 2008 11:26:05 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAABTJxEfBL1AZkmdsb2JhbACQZwEBAQEHBAYHIoENmyg X-IronPort-AV: E=Sophos;i="4.25,412,1199660400"; d="scan'208";a="8648521" Received: from gw.exalead.com (HELO exalead.com) ([193.47.80.25]) by mail1-smtp-roc.national.inria.fr with ESMTP; 27 Feb 2008 11:26:05 +0100 Received: from [192.168.204.148] (madpc064.exalead.com [192.168.204.148]) (authenticated bits=0) by exalead.com (8.14.0/8.14.0) with ESMTP id m1RAQ41m015643; Wed, 27 Feb 2008 11:26:04 +0100 Message-ID: <47C53ABC.30202@exalead.com> Date: Wed, 27 Feb 2008 11:26:04 +0100 From: Berke Durak User-Agent: Thunderbird 1.5.0.10 (X11/20070221) MIME-Version: 1.0 To: Dirk Thierbach Cc: Caml-list List Subject: Re: [Caml-list] Objects, dynamic cast, Obj.magic abuse and dragons References: <47C3F96E.4080901@exalead.com> <20080226150711.GB6521@feanor> <47C43D61.7070905@exalead.com> <20080227073726.GA1494@feanor> In-Reply-To: <20080227073726.GA1494@feanor> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 47C53ABD.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; berke:01 durak:01 berke:01 durak:01 gerd:01 stolpmann:01 bug:01 guis:01 subtyping:01 partitioned:01 uniformly:01 statically:01 ocaml:01 dispatching:01 implicated:01 Dirk Thierbach a écrit : >> You are preaching to the choir. > > I'm not preaching here :-) > >> I'm not Gerd Stolpmann and I don't use objects very much because >> every time I try I get seven-page-long errors. > > I, OTOH, use them frequently. I also get seven-page-long errors, > but usually I can find the bug nevertheless :-) Well it's all a question of not losing patience and switching to a non-object representation :) >> However it seems that objects could be actually useful in situations >> where you have a hierarchy of objects with behaviours, such as a graphical >> user interface made of widgets, or, say, a text adventure. > > Yes, they can be very useful in some situations, especially in GUIs. > However, I think they are not useful in the particular situation of > a text adventure. I wouldn't bet on that :) > And I think that the criterion is not having a hierarchy of behaviours > (first, "inheritance is not subtyping", second, as you've seen, you > can run into trouble with static type checking easily), but the criterion > is having substantial state that should be partitioned and decoupled. > > This also applies to the text adventure to some degree, but the actual > state is much simpler: Must items will have no state at all, or > at most a boolean like "open/closed". Their *relationship*, OTOH > (i.e. location, attachment) can be described uniformly and globally. But there is an excellent mapping between containment in the modeled world, and logical containment in the objects. Hence, I'd like to have the contents of an object as part of its state. Properties of an object may change depending on what they contain, where they are contained or what objects they are contained with. For instance, a wooden box containing a bronze statue will be heavy, cheese contained in a hot oven will melt and hydrogen peroxide contained in a bottle also containing acetone will, well, get you in trouble. And most actions in an adventure game involve shifting things around and the occasional state change now and then. > Also, for the actual actions, you need multi-dispatch: The outcome > of the action depends on the verb and multiple items ("tie rope to > railing"). > And all this says that single-dispatch statically typed > objects, like in OCaml, are a bad match for this situation. I'm actually working on a multi-dispatched language and I find it a little bit over-hyped. It helps with dispatching, but once you've dispatched and got the objects with the types you want, you still have to decide what to do and issue individual commands to the implicated objects, and then collect back the results. Provided that you have some representation of the types as values (say as variant tags) you could as well pattern-match on the tuple of types representations and on the verb. This is not very scalable, so you could hack a hand-made dispatch mechanism. And, certainly, the properties you want to dispatch on might not be easily representable in types, so your multiple-dispatch needs guards. -- Berke DURAK