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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b3e32a261c552ef1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-14 15:05:32 PST Path: supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!newsfeed.direct.ca!look.ca!newsfeed1.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3A3946A2.21EC493@acm.org> From: Jeff Carter X-Mailer: Mozilla 4.7 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada OOP question References: <20001209101904.07653.00004016@ng-fy1.aol.com> <3A32A182.54E3D857@acm.org> <91382k$nq1$1@nnrp1.deja.com> <3A35B45D.5F05F171@acm.org> <91b5bi$7qq$1@nnrp1.deja.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 14 Dec 2000 23:05:23 GMT NNTP-Posting-Host: 199.174.143.5 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 976835123 199.174.143.5 (Thu, 14 Dec 2000 15:05:23 PST) NNTP-Posting-Date: Thu, 14 Dec 2000 15:05:23 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: supernews.google.com comp.lang.ada:3147 Date: 2000-12-14T23:05:23+00:00 List-Id: mark_lundquist@my-deja.com wrote: > > I think that this practice should be discouraged. The problem is that > > such a type creates an interface that is difficult to understand. What > > is the difference between > > > > Op (Object, Param1, Param2); > > > > and > > > > Object.Public_Component := Some_Value; > > Op (Object, Param1, Param2); > > > > ? They could be the same; Op could perform differently in the 2nd > case, > > but this be considered valid; or Op could be invalid as a result of > the > > assignment. > > Sure... but this observation is just as valid if you replace the > assignment to the public component with any operation. Since > encapsulation isn't relevant to your observation, the observation isn't > a sound argument for encapsulation in general nor against mixing public > and private components in particular. (Don't get me wrong, I'm all for > encapsulation, this just isn't the argument for it! :-) Your argument > below, viz. coupling to the implementation, is much more to the point... I disagree. If I write the package with no public components, I can easily detect invalid sequences of operations. I can often prevent invalid sequences of operations. This is less easy when one of the operations is direct assignment to components of the type. > True enough, it's the "header file" heritage. In C you often find a > function's documentation comments in the .c file, while the .h file > (ostensibly the "interface") is just "extern blah blah(blah, blah);" on > everything, with no comments. Too frequently there are no comments anywhere. The code is "self documenting". > I wonder if the reason people sometimes use public components instead > of accessors/mutators (or getters/setters or whatever you want to call > them) because they are trying to "optimize performance". Certainly in > C++ it's well known that member functions defined in the class > definition are inlined, but maybe people don't know that you can inline > subprograms in Ada (Rational's compiler does auto-inlining when > optimization is turned on, and its algorithm is quite difficult for a > human programmer to beat in terms of final executable speed and size). > Don't know about inlining in Java... "Performance" is often used as an excuse for bad design. "We have this variable in the package spec for performance reasons." "Really? Where are the performance requirements documented? Where are the results of timing tests without the global variable documented?" "Well, there aren't any. I just know it will be too slow otherwise." Such claims are rarely true. -- Jeff Carter "I waggle my private parts at your aunties." Monty Python & the Holy Grail