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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Your wish list for Ada 202X Date: Wed, 23 Apr 2014 19:39:47 +0200 Organization: cbb software GmbH Message-ID: References: <7f1c01c5-3563-4b94-9831-152dbbf2ecdc@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: AuYlnUSfTZrfhAkRjyySpQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:19535 Date: 2014-04-23T19:39:47+02:00 List-Id: On Wed, 23 Apr 2014 18:40:33 +0200, J-P. Rosen wrote: > Le 23/04/2014 18:27, Dmitry A. Kazakov a écrit : >>> But that would require every type to have a 'Img. Yes, you said you >>> > wanted that, but there are clearly types where no sensible image could >>> > be provided. >> No, I didn't want that. >> >> Instead I would do two things: >> >> 1. Classes for all types; >> >> 2. An interface named Printable (or whatever else name) with the primitive >> operation Image. >> >> Now, if a type is supposed to have Image, it must implement the interface. >> All scalar types will. >> >> If a record type need to have Image, you inherit to Printable. If Image is >> needed in a generic the formal type inherits to Printable. That's it. > > But why require such a machinery? If you want to express that a formal > type must feature an Image function, you can do it even in '83: > > generic > type T is private; > with function Image (Item : T) return String; > package Foo is... > > What would an attribute bring as benefit? Primitive operation (and an attribute) cannot get lost, become hidden, replaced by another operation. A stray formal function can and easily does. Furthermore, the formal declarations above is nothing but a poor man's description of an interface, ADT + operations (Image, ":=", "=", "/=" etc). Since Ada 95 has proper interfaces (tagged types), we should rather use them. Which is shorter (you don't need to reiterate the list of operations) and *greatly* safer, because proper interfaces are matched nominally, while generic formal interfaces are matched by structure, proper interfaces can be encapsulated in packages and formal interfaces cannot, proper interfaces can be reused in several packages and formal interfaces need cut and paste and so on. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de