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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,50137bb64a119cfc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-24 10:58:39 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: "access constant" discriminant Date: 24 Feb 2003 10:58:38 -0800 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0302241058.88ca487@posting.google.com> References: <_TO1a.14664$9y2.6601@nwrddc01.gnilink.net> <3CS1a.55972$2H6.1357@sccrnsc04> <3E4E9248.3E71D984@adaworks.com> <1ec946d1.0302201642.66eb93e5@posting.google.com> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1046113118 20679 127.0.0.1 (24 Feb 2003 18:58:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 24 Feb 2003 18:58:38 GMT Xref: archiver1.google.com comp.lang.ada:34527 Date: 2003-02-24T18:58:38+00:00 List-Id: "Randy Brukardt" wrote in message news:... > > Claw doesn't use access discriminants. That's in large part because they > cause limited 'poisoning', as they're restricted to limited types. We > prefered to use Adjust to make assignment work properly. This may simply reflect a philosophical difference about whether types should be limited or non-limited. Certainly I have never agreed with the CLAW decision to make window types non-limited, and to me a non-limited window is completely wacky. > Access discriminants are very powerful. They are very much > underutilized, probably because hardly anybody understands them. I could make this argument about any language feature. For example, when I was using Ada83, my experience was that many Ada programmers never really understood what a private type was. There were many Ada83 programmers who didn't really grok the whole object-oriented programming thing. Another example: I worked on the F22 project for while, at Hughes. No one in the company seemed to know that you could return an unconstrained array from a function: declare S : constant String := Name (File); begin The problem was that Ada83 required the object to be marked as "constant," so when the declaration declare S : String := Name (File); begin didn't compile, everyone assumed that this meant you must return a constrained array. Of course this is incorrect -- but why didn't anyone realize this? I have observed a similar phenomenon among Ada95 programmers. There are many aspects of the Ada95 language with which many programmers are unfamiliar. For example, I gave a talk in London, and declared a private operation that took the tagged type as an access parameter. No one seemed to realize that operations that accept the type as an access parameter are primitive, and therefore dispatch when the parameter has type T'Class. Another of the speakers was talking about the problems he was having with Unchecked_Access. As it turns out, neither he nor anyone else in his company knew that tagged types are passed by reference in Ada95. He was trying to prevent the "slicing" that can occur in C++ (and which he thought would happen in Ada95 too), so he was declaring all the type parameters using a named access type. Of course, this is incorrect, but why didn't anyone realize that tagged types are passed by reference? > Sweeping statements about programming style are not likely to be > helpful. I tend to feel about finalization like Matt apparently does > about access discriminants, but the only time I would say something like > "No serious Ada program can be written without them." is when I'm > looking for fight. Even though I believe that is true, I'm well aware > that there are many, many Ada projects which have an irrational fear of > finalization, and to characterize them as not being "serious" is not > likely to make any friends. Perhaps it was my use of the word "serious" that was confusing. I should have said "essential," with the same sense that Fred Brooks used in his famous paper "Essence and Accidents in Software Engineering." http://atheism.about.com/library/glossary/general/bldef_essence.htm C++ doesn't require you to use classes, but if you don't, it would be a stretch to say that you're programming in "C++." Really, you're using a C++ compiler to compile a C program. This is not necessarily a bad thing -- after all, C++ gives you better compile-time error checking and type-safe linkage. But to not use classes you'd be losing something "essential" to C++ programming. The use of access discriminants in Ada95 is exactly analogous. For example, how would you add controlled-ness to a (tagged) type that is part of type hierarchy that isn't already controlled? The only way I know is to do this: type NT is new T with private; ... private type Control_Type (O : access NT) is new Limited_Controlled with null record; type NT is new T with record Control : Control_Type (NT'Access); ... end record; This is an important Ada95 idiom with which every Ada95 needs to be thoroughly familiar. This idiom and others like it is why I characterize access discriminants as "essential" (again, "per se" vs. "per accidens") to programming in Ada95.