comp.lang.ada
 help / color / mirror / Atom feed
From: Immanuel Scholz <news@kutzsche.net>
Subject: more to ada paper critic
Date: Mon, 17 Jun 2002 12:28:56 +0200
Date: 2002-06-17T12:28:56+02:00	[thread overview]
Message-ID: <aekdir$7oos6$1@ID-100557.news.dfncis.de> (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)




             reply	other threads:[~2002-06-17 10:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-17 10:28 Immanuel Scholz [this message]
2002-06-17 17:23 ` more to ada paper critic 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
  -- strict thread matches above, loose matches on Subject: below --
2002-06-17 11:33 Grein, Christoph
2002-06-17 15:16 Gautier direct_replies_not_read
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
replies disabled

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