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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!newscon02.news.prodigy.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada) Date: 14 Mar 2005 19:00:00 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <42309456$1@news.broadpark.no> <4232ab3a$0$26547$9b4e6d93@newsread4.arcor-online.net> <1110825790.396769@athnrd02> <1gf23j59mnsm2.wimnrcdrb09u.dlg@40tude.net> NNTP-Posting-Host: shell01-e.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1110844802 21173 69.38.147.31 (15 Mar 2005 00:00:02 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 15 Mar 2005 00:00:02 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:9413 comp.lang.c++:45715 comp.realtime:1494 comp.software-eng:5061 Date: 2005-03-14T19:00:00-05:00 List-Id: Hyman Rosen writes: > Robert A Duff wrote: > > Because the "<" (or Hash) needs to know the internals of the thing. > > It may be possible to order the objects through information > available from public accessors, so this is false. OK, please let me amend my statement to "...*usually* needs to know...". So "this is false" should be "this is sometimes false". > > In other words, at the point where you declare a type, you have to think > > ahead: this type might want to live inside one of those containers, so > > I'd better define the necessary operations. > > False, as per above. In fact, the ordered containers can be instantiated > with order functions, so there need not be a single unique ordering for > a given type. > > For example, any string type has a public way of delivering up the > characters it contains. That lets you define string containers which > hold their strings in alphabetical order, in case-insensitive order, > or even in pig-latin order if you want. None of this requires the > string implementor to anticipate such ordering requirements. Yes, if the thing has a natural "<" function, or some public information from which that can be garnered, then "<" is not a problem. That's true of character strings. And of course I understand that you can sort backwards by using a different function (as in "<" => ">" in Ada terms). But if you want to hide most of the data of some abstraction, and there's no "natural" meaning of "<", then you have to think ahead, and define some "<" operation just in case somebody wants to put the thing into a container. (Or, of course, go back and add that in to an existing data type when you find it's needed.) The same is true with Hash. For a character string type, you can declare it on the fly, because such a type exposes all the data. But for a type that's "private" in Ada, or has protected/private members in C++, the Hash function, like the "<" function, often needs access to the private data. In Ada, you can use a child (which does not require modifying the original thing). In C++, you can use a friend. Or, in either language, you can just put Hash or "<" in the original thing. One possibility is to have a coding convention: always declare "<" and Hash for every data type, just in case it might be needed for one of these containers. - Bob