From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border2.nntp.dca.giganews.com!nntp.giganews.com!news-in-01.newsfeed.easynews.com!easynews.com!easynews!news.glorb.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Redispatching Date: Wed, 16 Apr 2014 22:53:28 +0300 Organization: Tidorum Ltd Message-ID: References: <7f1c01c5-3563-4b94-9831-152dbbf2ecdc@googlegroups.com> <8bhozh836pyt$.1qctlysud0s2q$.dlg@40tude.net> <1cdsyxjzsfgzm.1synpaujysv21$.dlg@40tude.net> <1aa804jg9qq4o$.wdiq33yo621l.dlg@40tude.net> <1w6eh0aiksmdh$.1h16p7y0b8c6h.dlg@40tude.net> <17twpp4p8u7o$.1idvzaaio4f3t$.dlg@40tude.net> <1wjmcbk375lzk.6o7dpqcp3va3.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: individual.net dji9NiSqlH+llEuzZwcxNgaBIeakqWUmjpzapYyNI5qWXp3oGZ Cancel-Lock: sha1:gsExqFNxNSO5D6FBU4Uuv7Z7zr8= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: X-Received-Bytes: 5526 Xref: number.nntp.dca.giganews.com comp.lang.ada:185770 Date: 2014-04-16T22:53:28+03:00 List-Id: On 14-04-16 12:30 , J-P. Rosen wrote: > Le 16/04/2014 08:32, Niklas Holsti a écrit : >> As I understand them, both Dmitry and Randy would consider the >> class-wide form a better solution, but it works only if you never need >> to override these class-wide operations for any descendant types. >> >> I am seldom sure about that (never needing to override, not even in the >> future), so I prefer to have the operations as primitive rather than >> class-wide, and consequently to use re-dispatch. > > Actually, it's a different use case. Not much discussed in the > litterature, because only Ada has a clear distinction between methods > (primitive operations) and class-wide operations. > > A method is for the case where each type has its own way (method!) of > doing things: you don't paint a button like you paint a text. > > A class-wide operation is usually a combination of (dispatching) calls > to methods, to build higher level services; it's for the case where you > want to make sure that all objects use the same algorithm; I understand this difference (as should have been evident from my previous posts). But you are presenting it as a black-or-white, two-valued choice; in my perception, there are also operations which share features of both extremes. Shades of grey. > for example, > when you move a widget, you want to guarantee that it is erased from its > current position and repainted somewhere else, and that nobody will > redefine move to do something else! It also ensures that should the > algorithm change, the change needs to be done in only one place. But then I derive a widget type which is implemented by a sprite, and this widget can be moved just by changing its (x,y) registers, without "erasing" and "redrawing". The "universal" move operation is not really applicable to this widget, and can be overridden by a special and faster operation. (I know that sprites are no longer used in display HW, but I did not want to invent a more up-to-date example.) > As far as redispatching is concerned: since a method is linked to a > single class, there should be no redispatching. (I think you meant to write "linked to a single type", not "class".) Then you must also be of the opionion that there should be no inheritance of methods, because inheritance makes the same method become linked to different types. Is that your view? Of course I disagree with this. > Feeling a need for > redispatching in a method is often a symptom that a class-wide operation > is a better fit. Except in these intermediate cases where there is an operation which is an almost general, default algorithm, which could be class-wide except that it needs to be overridden for some types in the class. > And yes, chosing between methods and class-wide ops is not trivial and > requires some thoughts; once you have a clear separation between these, > it makes development a lot easier. Of course I disagree with that (becase I do not consider redispatching harmful). But in the absence of empirical research on this question, this is a subjective opinion. > Redispatching is mostly advocated by users of other languages that do > not have class-wide operations, and use methods for what should be > class-wide. In that case, failing to redispatch leads to incorrect > behaviour. I think it is very good that Ada provides a choice, and I don't mind that redispatching is not the default in Ada, even if I use it more often than not. I'm not advocating redispatching in general, but I don't hesitate to use it when it is necessary to give me the behaviour I want. And I refuse to feel ashamed just because C++ or Java users also use redispatching. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .