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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ed4a5cc4016f9101 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!n60g2000hse.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Default value for a record component Date: Mon, 23 Jul 2007 12:17:46 -0700 Organization: http://groups.google.com Message-ID: <1185218266.914312.155690@n60g2000hse.googlegroups.com> References: <1185052757.500324.16860@22g2000hsm.googlegroups.com> <1185133442.532463.301960@r34g2000hsd.googlegroups.com> NNTP-Posting-Host: 85.0.251.175 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1185218267 25460 127.0.0.1 (23 Jul 2007 19:17:47 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 23 Jul 2007 19:17:47 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.5) Gecko/20070713 Firefox/2.0.0.5,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: n60g2000hse.googlegroups.com; posting-host=85.0.251.175; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news1.google.com comp.lang.ada:16563 Date: 2007-07-23T12:17:46-07:00 List-Id: On 22 Lip, 23:44, Robert A Duff wrote: > >> package P is > >> function Get_Default_Value return Integer; > >> type T is record > >> V : Integer := Get_Default_Value; > >> end record; > >> end P; > > > No, this leaks the implementation detail (the Get_Default function) to > > the public view and pollutes it. I don't want my users to even see it. > > I don't see why that's important. You "leak" the name > Get_Default_Value, but why is that a problem? Why not have everything in public view then? This function is not part of the interface. The initial value can be part of the interface, but not the function. From the client's perspective there is no function at all - it's existence is only an artifact of how things are implemented, not something that the users should be bothered with. > You're already leaking the component V. So? Why these should be connected? > The fact that clients can say X.V := ... > seems much worse It doesn't have to be bad at all - after all, Ada allows to have full record definitions in public view for a reason, right? > Why do you want to hide the default value, but expose the component > V itself? I don't want to hide the default value - after all, the value of this default value (hm...) is available to the user after the object is created, so there is nothing to hide. What I want to hide is the mechanics of where this value comes from. Or even how often it is computed (hint: the function can be stateful). > If you want to hide both The point is I don't. The C++ version: class T { public: T() : V(getDefault()) {} int V; private: static int getDefault(); }; (or even I can hide getDefault in the implementation file completely, without even mentioning it in the class definition) > > Ada needs real constructors, not just initial values. > > I don't get it. Please explain. The visibility of a component and the mechanics of computing its initial value are orthogonal and should not depend on one another. I can have completely separate reasons to expose or hide either of them. -- Maciej Sobczak http://www.msobczak.com/