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-Thread: 103376,ed4a5cc4016f9101 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!newscon02.news.prodigy.net!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Default value for a record component Date: Sun, 22 Jul 2007 17:44:38 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1185052757.500324.16860@22g2000hsm.googlegroups.com> <1185133442.532463.301960@r34g2000hsd.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1185140679 18806 192.74.137.71 (22 Jul 2007 21:44:39 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 22 Jul 2007 21:44:39 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:qwcHL0+vkRtwEGmb21b8VFkwC30= Xref: g2news1.google.com comp.lang.ada:16538 Date: 2007-07-22T17:44:38-04:00 List-Id: Maciej Sobczak writes: > On 22 Lip, 10:08, "Dmitry A. Kazakov" > >> > I would like extend it and do this: >> >> > package P is >> > type T is record >> > V : Integer := Get_Default_Value; >> > end record; >> > private >> > function Get_Default_Value return Integer; >> > end P; >> >> > without losing any of the properties of the original solution and >> > without "leaking" any implementation detail to the public view. > >> Yes: >> >> 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? You're already leaking the component V. The fact that clients can say X.V := ... seems much worse than the fact that they can say Mumble : Integer := Get_Default_Value. Why do you want to hide the default value, but expose the component V itself? If you want to hide both, then make the type private, and then you can hide Get_Default_Value also. Usually a good idea. > Ada needs real constructors, not just initial values. I don't get it. Please explain. - Bob