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,555956c1cdd22308 X-Google-Attributes: gid103376,public From: Mats Weber Subject: Re: Help - Constructors - ASAP. Date: 1998/08/03 Message-ID: <35C5C534.D773CAA2@elca-matrix.ch>#1/1 X-Deja-AN: 377485142 Content-Transfer-Encoding: 7bit References: <6p75qi$rcj@news.latnet.lv> <6pi4jq$j73$1@nnrp1.dejanews.com> Content-Type: text/plain; charset=us-ascii Organization: ELCA Matrix SA Mime-Version: 1.0 Reply-To: Mats.Weber@elca-matrix.ch Newsgroups: comp.lang.ada Date: 1998-08-03T00:00:00+00:00 List-Id: Matthew Heaney wrote: > You can do this with non-tagged types too. One common mistake I see > programmers make is to do this: > > package P is > > package Bounded_Strings_20 is > new Ada.Strings.Bounded.Generic_Bounded_Length (20); > ... > end P; > > Now every client in the universe has to refer to the string type as > P.Bounded_Strings_20.Bounded_String. Why should a client care? > > Use the transitivity of visibility technique to bring the string type > directly in the scope of P: > > package P is > > package Bounded_Strings_20 is > new Ada.Strings.Bounded.Generic_Bounded_Length (20); > > type Bounded_String is > new Bounded_Strings_20.Bounded_String; > ... > end P; > > Now a client can just refer to P.Bounded_String. This works as long as the package that implements the type exports only one type and only primitive operations of that one type, but that is far from the most common case, at least in my code. Take for instance Sequential_IO: package P is package Implementation is new Sequential_IO(Whatever); type File_Type is new Implementation.File_Type; type File_Mode is ???; -- no clean way of doing this end P; Another problem, which I think is even worse, is when some operations of a type are generics (e.g. iterators), then these will not be derived and you will have to get them from the package that declares them. Not to mention the fact that the rules on type derivation, primitive operations, etc. are one of the obscure areas of the Ada language. Not to me, I know how they work, but I have had to teach quite a few people to overtake code that uses some (really not much) type derivation, and nobody seems to find it natural. E.g. when you see X : P.T; begin P.Op(X); you expect to find a declaration for Op in P, right ?