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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d1df6bc3799debed X-Google-Attributes: gid103376,public From: "John G. Volan" Subject: Re: Syntax for tagged record types (was Re: Not intended for use in medical,) Date: 1997/05/22 Message-ID: <33850721.49BF@sprintmail.com>#1/1 X-Deja-AN: 243210302 References: <3.0.32.19970423164855.00746db8@mail.4dcomm.com> <33828299.2A3@world.std.com> Reply-To: johnvolan@sprintmail.com Newsgroups: comp.lang.ada Date: 1997-05-22T00:00:00+00:00 List-Id: Robert A Duff wrote: > > In article , > Matthew Heaney wrote: > >I think that using discriminants as "constructor arguments" is a real > >kludge, and obfuscates declarations. ... > > Why? > > - Bob If the hypothetical constructor only took discrete or access-type parameters, then faking those "parameters" as discriminants on a limited type is okay. But if they have to be any other kind of type, you've got a problem. Faking a parameter of type "T" as a discriminant of type "access T" only leaves the programmer with a dilemma: Who is responsible for deallocating the designated T object? The answers might be: (1) The object with the discriminant. (It "owns" the designated T object, so it should deallocate it on Finalize). (2) The client who passed the T into the discriminant. (It may have passed the same T access value as a discriminant to several objects, so it should deallocate the designated T object only once all those other objects are finalized). (3) Nobody. The T object was never allocated on the heap in the first place. It was aliased, and 'Access was passed to the discriminant. This doesn't make for very clean abstractions. Choice (1) might be the most attractive from an abstraction point a view, but it requires that clients be highly circumspect in their behavior towards those access discriminants (they must always do a "new" but never a 'Access, and they must never do Unchecked_Deallocation) but this restriction is not enforceable by the compiler. Another issue with discriminants as constructor parameters is that there is no provision for having multiple overloaded constructors with different sets of parameters. ------------------------------------------------------------------------ Internet.Usenet.Put_Signature (Name => "John G. Volan", Home_Email => "johnvolan@sprintmail.com", Slogan => "Ada95: The World's *FIRST* International-Standard OOPL", Disclaimer => "These opinions were never defined, so using them " & "would be erroneous...or is that just nondeterministic now? :-) "); ------------------------------------------------------------------------