comp.lang.ada
 help / color / mirror / Atom feed
* Re: more to ada paper critic
@ 2002-06-17 11:33 Grein, Christoph
  0 siblings, 0 replies; 15+ messages in thread
From: Grein, Christoph @ 2002-06-17 11:33 UTC (permalink / raw)


> >       -- Define the number of cards in a standard deck.
> >    subtype Deck_Index is integer range 1..52;
> 
> AFAIK this means a Deck_Index IS A integer, right? So maybe I would prefer
> "type Deck_Index is new integer range 1..52;", because an index is not
> normaly an integer. What do you say?

or even better:
    type Deck_Index is range 1..52;

> 
> > Note that this package specification defines the types Card and Deck
> > as private types. This allows another compilation unit to know that
> > there are types called Card and Deck, but not to know their
> > structure. The Ada package provides encapsulation and namespace.
> 
> Hm, but the other programmers still SEE the current structure.

No, they don't see it. Visibility is a technical term defined in the RM, and to 
be able to see something (i.e. something being visible) does not mean that you 
(as a human) can read the declaration in the Ada specification. It comes after 
the keyword private, so its invisible.

> IMHO if the
> structure should be hidden, it would be better to only declare the names of
> the types so that even other _coders_ does not know the structure.
> Like C/C++ 's header-declaration approach (if you do it right in C).

If you want to do this, you have to use access types.

> > The definitions are placed in a separate
> > file called the package body.
> 
> HAS they to be in a seperate file? I think not so. (But it is good, that
> they CAN ;-)

Depends on you compiler. E.g. Gnat wants them in separate files, Aonix doesn't.

> Are there any swap - template (or "generic" ;-) in the standard-library?

No, it's so simple.

> The difference between procedure and function seem to be, that procedure has
> in/out modifiers while function has a return-value, right? What is the
> default for functions? Are the parameter all "in" or "in out" ?

Default mod (if omitted) is in. Function can only have in.

> > Variable initialization is performed during an elaboration step
> > which is performed before normal program execution begins. This
> > ensures that the All_Decks variable is properly initialized with
> > no race conditions.
> 
> Oh come. Arent there race conditions when initializing more than these
> "before the main"s. This solution seems quite similar to C++'s problem of
> initializing global statics. Example: (forgive any syntax-errors I havent
> got GNAT to run until now ;-)
> 
> 
> function Prob1 return integer is
> begin
>   return Var2;
> end Prob1;
> 
> function Prob2 return integer is
> begin
>   return Var1;
> end Prob2;
> 
> Var1 : constant integer := Prob1;  -- Var2 unitialized, will return
                                     -- unspecified value
> Var2 : constant integer := Prob2;  -- ditto

Elaboration is done sequentially, no race condition.

> >       Cards.Deal(The_Card => This_Card, From => My_Deck);
> 
> looks funny :)

Admittedly in this case, named notation is not very useful. If you get used to 
Ada, you'll find places where it helps:

Drive (My_Car, True);

does not say you what it True. If you used named notation:

Drive (My_Car, Restricted_Use => True);

> What happens if you do not catch the exception? Will then some kind of
> terminate() be called (similar to C++?) or just reported and step on (like
> Java)?
> 
> Can I declare exceptions, so that user of my functions MUST catch the
> exception?

You need not handle the exception. If you don't your program (more exactly, the 
actual task) will die.

> > You can also see another feature of Ada syntax in this example. That is
> > the ability to pass parameters to functions and procedures by name. You
> > also see instances where they are passed by position.
> 
> Yes. But this is really only sugar and does not improve calling security.
> The most important thing about order of Parameters is, when a library
> supporter has to decide to swap Parameters of functions. Since he cannot
> decide this safely (because there might be callings without naming) it is
> almost useless to know, that user of libraries MIGHT call with secure
> naming...
> 
> The only advantage comes from more readible code.

This is more than sugar, think of arctan (y, x) versus arctan (x => y, y => x)

Confused?
 
> Or are there possibilities to force the parameter-naming? This would be
> great!

No



^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: more to ada paper critic
@ 2002-06-17 15:26 Gautier direct_replies_not_read
  2002-06-18 13:30 ` Immanuel Scholz
  0 siblings, 1 reply; 15+ messages in thread
From: Gautier direct_replies_not_read @ 2002-06-17 15:26 UTC (permalink / raw)


Immanuel Scholz:

# I havent got GNAT to run until now ;-)

Tsss! What went wrong ?
It's (say on Windows): download it, install, click furiously on every
"okay", "I agree", "I'm happy" and so on until it is finished,
eventually download AdaGIDE, install, "Yes", "I have read", etc.
Nice, isn't it ?
You can do the same with ObjectAda, a long download (~77) but
a very sexy programming environment...

________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, address on the Web site!


_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: more to ada paper critic
@ 2002-06-17 15:16 Gautier direct_replies_not_read
  0 siblings, 0 replies; 15+ messages in thread
From: Gautier direct_replies_not_read @ 2002-06-17 15:16 UTC (permalink / raw)


Immanuel Scholz:

>Oh come. Arent there race conditions when initializing more than these
>"before the main"s. This solution seems quite similar to C++'s problem
>of initializing global statics. Example: (forgive any syntax-errors I
>havent got GNAT to run until now ;-)

>function Prob1 return integer is
>begin
>   return Var2;
>end Prob1;
>
>function Prob2 return integer is
>begin
>   return Var1;
>end Prob2;
>
>Var1 : constant integer := Prob1;
>Var2 : constant integer := Prob2;

This obviously don't pass the compilation,
since Var1 and Var2 are undefined: this is the
one-pass design of Ada (like Pascal, unlike C or Fortran)

Anyway it is interesting to try.

-- -- -- -- -- -- -- -- --
procedure kiki1 is

  function Prob1 return integer is
  begin
    return Var2;
  end Prob1;

  function Prob2 return integer is
  begin
    return Var1;
  end Prob2;

  Var1 : constant integer := Prob1;
  Var2 : constant integer := Prob2;

begin
  null;
end;
-- -- -- -- -- -- -- -- --
GNAT says:
kiki1.adb:5:12: "Var2" is undefined
kiki1.adb:10:12: "Var1" is undefined

If I push a bit more and "forward" the definition of Prob1, Prob2:
-- -- -- -- -- -- -- -- --
procedure kiki2 is

  function Prob1 return integer;
  function Prob2 return integer;

  Var1 : constant integer := Prob1;
  Var2 : constant integer := Prob2;

  function Prob1 return integer is
  begin
    return Var2;
  end Prob1;

  function Prob2 return integer is
  begin
    return Var1;
  end Prob2;

begin
  null;
end;
-- -- -- -- -- -- -- -- --
GNAT compiles, but says:
kiki2.adb:6:30: warning: cannot call "Prob1" before body seen
kiki2.adb:6:30: warning: Program_Error will be raised at run time
kiki2.adb:7:30: warning: cannot call "Prob2" before body seen
kiki2.adb:7:30: warning: Program_Error will be raised at run time

Running kiki2 produces:
raised PROGRAM_ERROR : kiki2.adb:6

____________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/index.htm#Ada

NB: For a direct answer, address on the Web site!


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx




^ permalink raw reply	[flat|nested] 15+ messages in thread
* more to ada paper critic
@ 2002-06-17 10:28 Immanuel Scholz
  2002-06-17 17:23 ` Ted Dennison
  0 siblings, 1 reply; 15+ messages in thread
From: Immanuel Scholz @ 2002-06-17 10:28 UTC (permalink / raw)


Hi,

here a (permitted) post from an email with Jim Rogers. Maybe any of you 
find this interesting ;-) 



On Sun, Jun 16, 2002 at 10:34:15PM -0600, Jim Rogers wrote:
> Immanuel Scholz,
>
> I was thinking about some of your questions about Ada.
> I suspect you will be able to more accurately write your paper
> if you are familiar with Ada. Towards that end I have decided
> to share a small Ada programming example with you, including some
> explanations of the syntax.

Err, maybe I should not have highlighted the "paper" so much.. Actually it
is more some kind of report for my superior. I have already done this, but
unhappily I do not expect him to choose Ada as language for the project he
is planning. I think it will come up to the end with Java (except I can
persuade him that this is too slow, which will probable mean C++ - the world
is bad, 'cause you have to do things knowing they have no influence in the
last :-( ).

But personally I think I will look at Ada more closely (and maybe if I
convince one or two more members of my coding stuff to be aware of Ada, our
next project will be one ;-)

It simple looked very unprofessional, if I report a collection of languages
where Ada, likely even not known to my chief, get the best price and C got
worsest. (But I think I have prevented the worst two things: C and VB ;-)


...
>    type Card is private;
...
>    type Deck is private;

So private is not the default? Is there a default (to public?)


>       -- Define the number of cards in a standard deck.
>    subtype Deck_Index is integer range 1..52;

AFAIK this means a Deck_Index IS A integer, right? So maybe I would prefer
"type Deck_Index is new integer range 1..52;", because an index is not
normaly an integer. What do you say?


>          Deal_Next  : Deck_Index := Deck_Index'First;

I like these auto-attributes very much (like in Java the .length of array)
:-)


> Note that this package specification defines the types Card and Deck
> as private types. This allows another compilation unit to know that
> there are types called Card and Deck, but not to know their
> structure. The Ada package provides encapsulation and namespace.

Hm, but the other programmers still SEE the current structure. IMHO if the
structure should be hidden, it would be better to only declare the names of
the types so that even other _coders_ does not know the structure.
Like C/C++ 's header-declaration approach (if you do it right in C).


> The types defined in this specification are not declared to
> be "tagged" types. This prohibits any subclassing of these
> types.

Which may be a pain in future. Better had done tagged as default and needed
a "final" or something similar to forbid subclassing? Normally a class isn't
sensitive to subclassing. This is juse the exception.


> Note that none of the subprograms (functions and procedures) is yet
> defined. The package specification acts as an interface definition
> for the entire package. The definitions are placed in a separate
> file called the package body.

HAS they to be in a seperate file? I think not so. (But it is good, that
they CAN ;-)


>    ------------
>    -- Procedure Swap
>    -- Exchange two Deck_Index values
>    --------------
>    procedure Swap(Left, Right : in out Deck_Index) is
>       Temp : Deck_Index := Left;
>    begin
>       Left := Right;
>       Right := Temp;
>    end Swap;

Are there any swap - template (or "generic" ;-) in the standard-library?


>       Max_Search : Deck_Index := Deck_Index'Pred(Deck_Index'Last);

What will happen if the deck was empty?


>    procedure Deal(The_Card : out Card; From : in out Deck) is
>    function Cards_Left(In_Deck : Deck) return Natural is

The difference between procedure and function seem to be, that procedure has
in/out modifiers while function has a return-value, right? What is the
default for functions? Are the parameter all "in" or "in out" ?


> Variable initialization is performed during an elaboration step
> which is performed before normal program execution begins. This
> ensures that the All_Decks variable is properly initialized with
> no race conditions.

Oh come. Arent there race conditions when initializing more than these
"before the main"s. This solution seems quite similar to C++'s problem of
initializing global statics. Example: (forgive any syntax-errors I havent
got GNAT to run until now ;-)


function Prob1 return integer is
begin
  return Var2;
end Prob1;

function Prob2 return integer is
begin
  return Var1;
end Prob2;

Var1 : constant integer := Prob1;
Var2 : constant integer := Prob2;



>       Cards.Deal(The_Card => This_Card, From => My_Deck);

looks funny :)


> When I attempt to deal from an empty deck above I expect to encounter
> the Deck_Empty exception I defined for the Cards package. I
> execute the erroneous deal attempt within an unnamed block so that
> I can specify an exception handler for the expected exception.
> Ada exceptions are identified by name.

What happens if you do not catch the exception? Will then some kind of
terminate() be called (similar to C++?) or just reported and step on (like
Java)?

Can I declare exceptions, so that user of my functions MUST catch the
exception?


> You can also see another feature of Ada syntax in this example. That is
> the ability to pass parameters to functions and procedures by name. You
> also see instances where they are passed by position.

Yes. But this is really only sugar and does not improve calling security.
The most important thing about order of Parameters is, when a library
supporter has to decide to swap Parameters of functions. Since he cannot
decide this safely (because there might be callings without naming) it is
almost useless to know, that user of libraries MIGHT call with secure
naming...

The only advantage comes from more readible code.

Or are there possibilities to force the parameter-naming? This would be
great!


--
Immanuel Scholz,   PGP: (Work 0x9216F1E7, Home 0x3B5DC02D)




^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2002-06-20 19:39 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-17 11:33 more to ada paper critic Grein, Christoph
  -- strict thread matches above, loose matches on Subject: below --
2002-06-17 15:26 Gautier direct_replies_not_read
2002-06-18 13:30 ` Immanuel Scholz
2002-06-18 13:35   ` Steve O'Neill
2002-06-18 17:59   ` Christoph Schlegel
2002-06-19 20:41     ` Immanuel Scholz
2002-06-20 19:39       ` Christoph Schlegel
2002-06-19 16:05   ` Britt Snodgrass
2002-06-17 15:16 Gautier direct_replies_not_read
2002-06-17 10:28 Immanuel Scholz
2002-06-17 17:23 ` Ted Dennison
2002-06-17 18:07   ` Hyman Rosen
2002-06-18  1:50     ` Ted Dennison
2002-06-18  5:38       ` Eric G. Miller
2002-06-18 13:42     ` Immanuel Scholz

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