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,4ac6c27957bfd114 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!news.clara.net!internal00.transit.news.clara.net!pe1.news.blueyonder.co.uk!blueyonder!news-out.ntli.net!newsrout1-gui.ntli.net!ntli.net!newspeer1-win.ntli.net!newsfe5-gui.ntli.net.POSTED!53ab2750!not-for-mail From: chris User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050404) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: What is the point of Private? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sat, 30 Apr 2005 00:49:13 GMT NNTP-Posting-Host: 80.4.70.84 X-Complaints-To: http://www.ntlworld.com/netreport X-Trace: newsfe5-gui.ntli.net 1114822153 80.4.70.84 (Sat, 30 Apr 2005 01:49:13 BST) NNTP-Posting-Date: Sat, 30 Apr 2005 01:49:13 BST Organization: ntl Cablemodem News Service Xref: g2news1.google.com comp.lang.ada:10841 Date: 2005-04-30T00:49:13+00:00 List-Id: Simon Smith wrote: > Hi, > > I am a student at Glasgow uni in the UK and have been writing ada > programs for my first two years of my course. Great uni :) If you do third year CS, have fun on the OS course... C with pthreads. I remember it well. :) Actually it's not that bad, but I have to maintain the fear and dread surrounding it because I too had to endure the dread and Dr Dickman is my project supervisor. ;) > I have used and still do use private, eg > > type Hash_Array is private; > > blah...blah... > > private > > type Hash_Array is array (Integer range 0 .. 25) of Sc.Set; > > end hash.ads; > > however I dont really understand the point of it. It's there for two reasons. It hides the implementation from clients of the code and makes the compilers job easier. The decision seems to be that the compiler should be able to determine how much space something will take at compile time*. This means they had to put the representation in the spec, so the compiler knew what to allocate. The alternatives are to leave everything public or to put the representation in the body. Making everything public means someone can adversely manipulate the contents of your data structures. They can break the rules, and mess up the software. Completely hiding the representation by putting it in the body has a different trade off. On the one hand, you can substitute any representation by changing the body alone, but on the other hand the compiler won't know how big the data structure is and it has to treat all things the same way (by wrapping or boxing them up - which has a cost). It's a trade off. The Ada people chose to put it in the spec because it simplified the compiler, and it best suited their over all goals. Other languages allow you to completely hide the representation in the implementation. e.g. SML, Ocaml. Some make it public. > Why is it there? I am sure I have heard talk that its to stop the client > from seeing exactly how the data is stored/manipulated however if people > really did want to know this wouldn't they just scroll down the ada spec > file and find out for themselves or am I missing something here? Client code can't do that though. This means someone who uses the compiled package can't see how it's implemented, but the maintainer can. Chris *There are probably other reasons too, I don't know what they are though.