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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a714625b3763f46e X-Google-Attributes: gid103376,public From: jvl@ocsystems.com (Joel VanLaven) Subject: Re: Modest proposal, 3 of 3 Date: 1996/11/26 Message-ID: <1996Nov26.170524.19023@ocsystems.com>#1/1 X-Deja-AN: 200882893 references: <575aq0$t4j@netline-fddi.jpl.nasa.gov> organization: OC Systems, Inc. newsgroups: comp.lang.ada Date: 1996-11-26T00:00:00+00:00 List-Id: Van Snyder (vsnyder@math.jpl.nasa.gov) wrote: [Background snipped] : PROPOSAL for next standardization of Ada : Get rid of ".all". When an access type appears, dereference it : automatically. This requires some way to copy "pointers." PL/1 and : Fortran 90 had the right idea: Use a different syntax for "pointer : assignment." This is OK, because there are only two things you can : do with pointers (in a sane language): dereference them and copy them. : Both Fortran 90 and PL/1 use "a => b" to mean "change a so it points : where b points" and "a = b" to mean copy the data where b points into : the place where a points." The latter in Ada requires "a.all := b.all". : If one has a datum, say "A: T", and one later decides it's necessary to : allocate it from the free store, the type of A changes from T to "access : T". That's not too bad. But all the references change from "A" to : "A.ALL". That's bad. [snip] Indeed. That is bad. However, declaring "A" to be of type "access T" is the problem, no the ".all" notation. The Ada way to solve this problem is to declare the object "A" to be aliased. So, "A : T" becomes "A : aliased T" and can be accessed used as both an accessable object and in the way it was before. If you want the object pointed to by "A" to stay around after "A" is gone then you are opening up another can of worms. In order to have a changeless transition from "T" to "access T" then the memory will have to be deallocated automatically and in a safe manner. So, you seem to be advocating required, sophisticated garbage collection. Irrespective of whether your "problem" is indeed a problem at all, you have given no reason why there is anything wrong with ".all" at all. Your problem can be as easily solved by making dereferencing automatic and keeping ".all" The case you talk about is changing from "T" to "access T" so there are no ".all" constructs involved at all. Note that in most cases this is already done. Ada does have automatic dereferencing. "A.foo" is the same if "A" is of type "T" or type "access T" and access types are most often used with records. The final point I want to make is a judgment call but is my opinion of the way Ada should be, expecially given what I understand to be the design goals of Ada. Access types are dangerous. Making something an access type we make things more complex and start to run into problems of shared access and memory allocation/deallocation etc. It is generally not that hard for a good programmer to deal with access types correctly, but it still remains that many nasty errors are due to accessing the wrong memory or some such. To blindly change an object to access to that object is asking for trouble. If it must be done, better to have the compiler reject the program at the points where there might be trouble than simply allow it to compile into an incorrect program (like mixing access and non-access types). It might be that the language should be more restrictive in some way so that access type and "regular" types aren't assigned in the same way, but your suggestion of making de-referencing automatic doesn't seem to be the way. -- -- Joel VanLaven