comp.lang.ada
 help / color / mirror / Atom feed
From: chris <spamoff.danx@ntlworld.com>
Subject: Re: What is the point of Private?
Date: Sat, 30 Apr 2005 00:49:13 GMT
Date: 2005-04-30T00:49:13+00:00	[thread overview]
Message-ID: <dCAce.1362$%K6.833@newsfe5-gui.ntli.net> (raw)
In-Reply-To: <d4rr3r$n92$1@news.freedom2surf.net>

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.



  parent reply	other threads:[~2005-04-30  0:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-28 23:22 What is the point of Private? Simon Smith
2005-04-28 23:40 ` Ed Falis
2005-04-29  3:14 ` Jeffrey Carter
2005-04-29  9:07   ` Peter Amey
2005-04-30  3:27     ` Jeffrey Carter
2005-04-30  0:49 ` chris [this message]
2005-05-01 22:57   ` Simon Smith
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox