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,a64004e5f547b1ed,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-17 03:27:42 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!pd9e1fc33.dip.t-dialin.NET!not-for-mail From: Immanuel Scholz Newsgroups: comp.lang.ada Subject: more to ada paper critic Date: Mon, 17 Jun 2002 12:28:56 +0200 Message-ID: NNTP-Posting-Host: pd9e1fc33.dip.t-dialin.net (217.225.252.51) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: fu-berlin.de 1024309659 8151942 217.225.252.51 (16 [100557]) User-Agent: KNode/0.6.1 Xref: archiver1.google.com comp.lang.ada:26135 Date: 2002-06-17T12:28:56+02:00 List-Id: 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)