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=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,d72714427ccb7ed8,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-01-19 23:29:31 PST Path: pad-thai.cam.ov.com!bloom-beacon.mit.edu!news.media.mit.edu!grapevine.lcs.mit.edu!uhog.mit.edu!news.mathworks.com!uunet!fdn.fr!jussieu.fr!univ-lyon1.fr!swidir.switch.ch!epflnews!dinews.epfl.ch!usenet From: Magnus.Kempe@di.epfl.ch (Magnus Kempe) Newsgroups: comp.lang.ada Subject: Ada FAQ: Programming with Ada (part 3 of 3) Followup-To: poster Date: 19 Jan 1995 18:11:09 GMT Organization: None Distribution: world Message-ID: <3fm9vt$a72@disunms.epfl.ch> Reply-To: Magnus.Kempe@di.epfl.ch (Magnus Kempe) NNTP-Posting-Host: lglsun4.epfl.ch Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Summary: Ada Programmer's Frequently Asked Questions (and answers), part 3 of 3. Please read before posting. Keywords: Ada, Computer Language, Programming Date: 1995-01-19T18:11:09+00:00 List-Id: Archive-name: computer-lang/Ada/programming/part3 Comp-lang-ada-archive-name: programming/part3 Posting-Frequency: monthly Last-modified: 19 January 1995 Last-posted: the epoch Ada Programmer'S Frequently Asked Questions (FAQ) This is part 3 of a 3-part posting. Part 2 begins with question 5.7. Parts 1 and 2 should be the previous postings in this thread. 9.6: I keep hearing that Ada is a "strongly typed language", but it seems different from what's meant in C++. Are they different? (Tucker Taft responds) I certainly agree that ANSI C and C++ are statically typed languages, but I would debate the "strength" of their typing. Essentially any support for implicit conversion (implicit "casting," "promotion", "usual" arithmetic conversions, etc.) "weakens" a type system (but also makes it "friendlier" in some ways). C allows implicit conversion between all integer types and all enumeration types. C++ at least cuts off implicit conversion to enumeration types, but retains implicit conversion among all integer (and floating-point) types. Also, in both C and C++, typedefs for pointer/array types are essentially "macros"; all pointer types with the same target type are implicitly interconvertible. Finally C++ allows the user to define a number of their own implicit conversion operators, which basically allows the user to "weaken" the type system as they see fit. Of course, all of this implicit conversion serves a purpose, but it does tend to move C/C++ toward the "weaker" end of the weak vs. strong typing spectrum. Note that the "strong" distinctions between integer types helps dramatically in catching (at compile-time) array indexing errors in Ada programs, by making sure that if you have an array indexed by a count of apples, you don't index into it with a count of oranges (without an *explicit* conversion). The advantages of "strongly" distinguishing enumeration types is even more obvious (and the designers of C++ recognized this). The strong distinctions between access types (pointer types) in Ada also has advantages, allowing access types to be represented as offsets within their storage pool rather than as addresses, and giving more high-level control over storage management. Strong typing can be carried too far, and some amount of implicit conversion is essential to make OOP palatable. But note that in Ada 9X, even with OOP, we don't allow implicit conversions that truncate the extension part of a record (this is a relatively common mistake in C++ when passing parameters by value). Instead, in Ada 9X, the language distinguishes between a specific type T and the class-wide type T'Class, and allows implicit conversions to T'Class from T or any of its derivatives, but not to the specific type T. Conversions to the class-wide type never implicitly truncate the extension part. Conversions to a specific type can truncate, and hence must be explicit. Note also that in Ada there are three distinct kinds of conversions, implicit ones, explicit ones, and unchecked ones. Only the unchecked ones are potentially unsafe. The explicit ones are safe, with either compile-time or run-time checks to ensure that. In C there are only implicit and explicit/unchecked conversions. C++ has recently added a checked, explicit "dynamic" cast, but still it will be common to use "normal" explicit casts for both checked and unchecked conversions, thereby making it more difficult to identify places where the type system might be compromised. Hence, the bottom line is that the type checking is (objectively) "stronger" in Ada than C/C++, though that doesn't necessarily mean "better" -- whether one is "better" for a particular style of programming than the other is a "religious" issue IMHO. I know my religion currently favors the stronger checking of Ada in most cases [except perhaps for multiply/divide, where I personally believe the checking should either be weaker, or directly support the concept of "units"/"dimensions"]. 9.7: I'm told Ada does all sorts of static type checking, but can't you get the same effect using a tool like "lint" with C? No, here are a few reasons why (this list is by no means complete): (Submitted by Norm Cohen) * Running both Lint and a C compiler requires the program text to be parsed and semantically analyzed twice. The results of an Ada compiler's parse and semantic analysis are used directly in performing consistency checks. * The rules of Ada provide the opportunity for stronger consistency checks than are possible with C. For example, an Ada programmer can declare distinct integer types to represent distinct abstractions. An Ada compiler will catch an inadvertent intermixing of these two types, but there is no way a corresponding distinction can be made in C, so there is no way for Lint to perform a corresponding check. Similarly, in C, a pointer to an object of type T is indistinguishable from an array of objects of type T. * The rules of the Ada language ensure that the program text provides information allowing PRECISE consistency checks. For example, the expression in an Ada case statement can be written to have a static subtype, allowing the compiler to ascertain that all possible values have been covered without resorting to a default (when others) arm. * With lack of precise information, Lint has no choice but to be overly pessimistic or, with different settings for a complicated set of options, overly optimistic. When it is overly pessimistic, the user sees too many "false alarms" and may end up ignoring valid warnings. When it is overly optimistic, Lint overlooks certain errors. * It is impossible to forget to run consistency checks when using an Ada compiler. (Of course a C programming environment could be set up so that the C compiler could only be invoked from a script that also invokes Lint.) * A compilation that fails Ada consistency checks is rejected. A compilation that fails Lint consistency checks may still be compiled, and its object file used (intentionally or accidently) in building the system. (One cannot automate the rejection of programs that fail Lint unless one is certain that there will never be any false warnings.) * Ada enforces consistency among separately compiled units. Of course even stronger arguments can be made about Ada's RUN-TIME checks (which can be used with little additional overhead because the information contained in an Ada program and the knowledge that the program has passed compile-time consistency checks make it possible to optimize away the majority of the checks). These checks, which are absent in C, tend to smoke out errors early by detecting internal inconsistencies that might not otherwise be detected during testing. This reduces the likelihood of fielding a system that appears to work well during testing but fails in operational use. 9.8: Does Ada have something like the Standard Template Library (STL) in C++, or components like you find in Smalltalk environments? Yes, but it isn't part of the ISO standard. Still, Ada 95 has an expanded set of predefined library units, covering e.g. strings of varying- or dynamic-length, elementary numerical functions, random number generators, complex numbers, and more; in addition, the Special Needs Annexes standardize many advanced services which have commonly been provided by separate components in the past. There is also an upcoming release of the Booch Components for Ada that will be released under the GNU Library General Public License (LGPL). This will give you the ability to freely include the library components in your application without any cost or obligation. Contact dweller@neosoft.com for more details. 9.9: Where can I find the equivalent of "printf" in Ada? While the standard package Text_IO provides many features, the request for a printf-like function is not unusual. (solution based on a suggestion by Tucker Taft) It is possible to produce a printf-like capability by overloading the "&" operator to take an object of type Format and an object of some type and return the Format, properly advanced, after having performed the appropriate output. The remaining format can be converted back to a string--e.g. to examine what is left at the end of the format string-- or simply printed to display whatever remains at the end. For example: with Text_IO; package Formatted_Output is type Format is limited private; function Fmt (Str : String) return Format; function "&" (Left : Format; Right : Integer) return Format; function "&" (Left : Format; Right : Float) return Format; function "&" (Left : Format; Right : String) return Format; ... -- other overloadings of "&" procedure Print (Fmt : Format); function To_String (Fmt : Format) return String; private ... end Formatted_Output; with Formatted_Output; use Formatted_Output; procedure Test is X, Y : Float; begin Print (Fmt("%d * %d = %d\n") & X & Y & X*Y); end Test; The private part and body of Formatted_Output are left as an exercise for the reader ;-). A "File : File_Type" parameter could be added to an overloading of Fmt if desired (to create something analagous to fprintf). This capability is analogous to that provided by the "<<" stream operator of C++. _________________________________________________________________ 10: Interfacing with Ada 10.1: I am writing software that used the Distributed Interactive Simulation (DIS) interface, does an interface exist in Ada? Yes. DIS is a standard for communications between simulators using an Internet Protocol network (IP). DIS provides a unified virtual environment for multiple simulator users on a network. It is used mostly in the DoD simulations business, but it is applicable to ANY simulation. It is an industry initiative involving military training and procurement organisations, simulator vendors and universities mostly in the US, but the technology is unclassified. The Institute of Simulation and Training, URL http://www.tiig.ist.ucf.edu/ is a center at the University of Central Florida (UCF) which serves as the support contractor for the Simulation and Training Command (STRICOM). Current (published) standards can be found there, as are BBS's for the DIS working groups who are attempting to push those standards forward. The BBS contains an Ada binding for DIS. Note that the above provides a thin binding to C code. It may be worthwhile to take the time to make high level DIS bindings. Someone reports having done it in over 2 man-months using an experienced Ada engineer, and that it was well worth it. Many bugs were found in the C DIS code of the machine they were networked with. "A strongly-typed interface is the network programmer's best friend." At TRI-Ada'94 there was a demonstration by Coleman Research Corporation (CRC); here's their short pitch: "CRC presents Ada VR-Link, the first commercially available DIS NIV. It provides all of the facilities necessary to jump start your DIS compliant simulation development efforts. For more information call (205) 922-6000." Also, the AJPO sponsored an Ada Technology Insertion Program (ATIP) relating to this, FY93 ATIP project 17, titled "Ada Distributed Interactive Simulation (ADIS)". According to its charter, "The primary purpose of the ADIS project will be the creation of Ada interface bindings to allow an Ada simulation application to use the DIS protocols." As with any other AJPO-related work, contact the Ada Information Clearinghouse for more information. There are several sources of information available on DIS itself. The IEEE version of the DIS standard is available (and only available) through IEEE (IEEE standard number is ??). Draft versions of the standard are available from the Institute for Simulation and Training at the University of Central Florida. They take orders at (407) 855-0881, and questions (about ordering) at (407) 658-5054. 10.2: Is there any support for Common Object Request Broker Architecture (CORBA) for Ada 9X? (from Bill Beckwith, Bill.Beckwith@ois.com) Objective Interface Systems, Inc. (OIS), MITRE, and DISA have been working on a mapping from CORBA IDL to Ada 95 for about six months. I will send a recent copy of the mapping document to any interested parties. OC Systems, Rational, and OIS are planning on selling CORBA products for Ada. Note that CORBA IDL to Ada 95 mapping specifies a mapping, not a binding. This will put Ada 95 on equal footing with the C++ and Smalltalk products. (except, of course, the Ada mapping is cleaner ;-) _________________________________________________________________ 11: Finding Additional Information 11.1: Where can I find Ada books? Try the comp.lang.ada FAQ, or the Ada WWW homepage (http://lglwww.epfl.ch/Ada/). Michael Feldman maintains the "Annotated Sampling of Ada-Oriented Textbooks", if you don't have access to WWW, drop him a note at mfeldman@seas.gwu.edu 11.2: Are there other Ada-related FAQs? Yes. They all appear in comp.lang.ada at regular intervals: comp.lang.ada FAQ, public Ada library FAQ, and Ada WWW server FAQ. All these are permanently available in hypertext format from the Ada WWW Server (see below) and in ASCII format from ftp://lglftp.epfl.ch/Ada/FAQ 11.3: What is the "Ada WWW Server"? The Ada WWW Server is alive and heavily used. It is a hypertext, multimedia information server for the Ada programming language. The URL of the Ada WWW Server is http://lglwww.epfl.ch/Ada/ [don't forget the trailing '/'.] The Ada WWW Server provides Ada-related information and hypertext access in areas including: * Historical notes on Ada * References * Ada FAQs * State of Ada 9X revision process * Standards * Bindings * Tools and Components * Intellectual Ammunition * Introductory Material * Resources * CS Technical Reports * FTP and WWW Sites--including mirror sites * Calendar of Ada-related events * Ada Today * Frequently Asked Questions--with Answers (from comp.lang.ada) For instance, you will find a list of schools using Ada in CS1 or CS2, an article on commercial success stories, information about software components, as well as hypertext versions of the Ada reference manual (both 83 and draft 9X). The Ada WWW Server keeps growing. All comments, ideas, and requests for additions or corrections, are welcome (e-mail to Magnus.Kempe@di.epfl.ch). _________________________________________________________________ 12: Pretty-printing Ada Source Code 12.1: Is there software that generates a pretty PostScript file from Ada source code? Pretty Ada code in PostScript means that e.g. reserved words are in bold and comments are in italics. This is a separate issue from re-formatting and automatic indenting. If you use the new Ada Mode for GNU Emacs (available from ftp://cs.nyu.edu/pub/gnat), go and get the package ps-print.el from any emacs archive (e.g. in directory ftp://archive.cis.ohio-state.edu/pub/gnu/emacs/elisp-archive). With this package you can print your code as you see it on the screen, say with bold keywords and italic comments. Another possibility is to feed the source to "vgrind" (see below), then pipe the result through "pscat" (to get PostScript) or "lpr -t" (to print), e.g.: vgrind -d -lada -o1- -t -w $* | lpr -t 12.2: I use vgrind to do "pretty printing" of my source. Is there a vgrind definition for Ada? # Ada! ada|Ada:\ :pb=(^\d?(procedure|function|package|package body))\d\p:\ :bb=if|case|begin|loop:be=end:\ :cb=--:ce=$:\ :sb=":se=":\ :lb=':le=':\ :id=_.:\ :oc:\ :kw=abort abs abstract accept access aliased all and array at\ begin body case constant declare delay delta digits do else\ elsif end entry exception exit for function generic goto if in is\ limited loop mod new not null of or others out package pragma\ private procedure protected raise range record rem renames requeue\ return reverse select separate subtype tagged task terminate then\ type until use when while with xor: Note that the above has a problem with attributes, because the "lb" and "le" terms make two-attributes-20-lines-apart look like one "string literal." Ada 95 keywords are recognized. Here is another definition, which "fixes" this problem (not perfect, but probably better). Only Ada 83 keywords are recognized. # In order to get the ticks to work, we are assuming that there will be # whitespace before a literal (like '"') and *not* when used for an # attribute (like 'Length). # For sb/se, we are ALSO assuming that literals have whitespace before/after. Ada|ada:\ :pb=^\d?(procedure|function|package|package\dbody)\d\p:\ :bb=begin:be=end:\ :cb=--:ce=$:\ :sb=( |\t|\()":se="( |\t|;|,|\)):\ :lb=(>| |\t)':le='(\)| |\t|;):\ :tl:\ :oc:\ :kw=abort abs accept access all and array at begin body case constant\ declare delay delta digits do else elsif end entry exception exit for\ function generic goto if in is limited loop mod new not null of or\ others out package pragma private procedure raise range record rem\ renames return reverse select separate subtype task terminate then\ type use when while with xor: 12.3: How about a source code reformatter? If you can run a Perl script (Perl is freely available for almost every OS in the world), you can use the program aimap, written by Tom Quiggle of SGI. It can be found (where ???). _________________________________________________________________ 13: Common Confusions 13.1: Wasn't Ada designed by some committee? What kind of a language could you possibly get from that kind of approach? (Tucker Taft, the principal designer of Ada 95, responds) I believe most reviewers of Ada 9X (and Ada 83 for that matter) will assure you that it was most certainly not designed by committee ;-). In fact, with respect to MI, the situation was just the opposite. There were several reviewers who pushed hard for building in a particular approach to MI. The principle designer (;-) was unconvinced that the benefits of building in a particular MI approach outweighed the costs as far as complexity. There was no clear winner to use as a model in the outside world; even Sather and Eiffel couldn't agree exactly on how to resolve the intricacies of MI, despite their strong similarities in other areas. 13.2: I've heard the DoD is dropping all Military standards to reduce costs, doesn't that mean the mandate to use Ada goes away too? The following memo explains how that decision affects the Ada mandate: OFFICE OF THE SECRETARY OF DEFENSE Washington, DC 20301-1000 August 26, 1994 MEMORANDUM FOR SECRETARIES OF THE MILITARY DEPARTMENTS CHAIRMAN OF THE JOINT CHIEFS OF STAFF UNDER SECRETARY OF DEFENSE (PERSONNEL AND READINESS) UNDER SECRETARY OF DEFENSE (POLICY) COMPTROLLER OF THE DEPARTMENT OF DEFENSE GENERAL COUNSEL OF THE DEPARTMENT OF DEFENSE INSPECTOR GENERAL OF THE DEPARTMENT OF DEFENSE DIRECTOR OF OPERATIONAL TEST AND EVALUATION DIRECTORS OF THE DEFENSE AGENCIES SUBJECT: Use of Ada The purpose of this memorandum is to reiterate the Department of Defense (DoD) commitment to the use of Ada. It is DoD policy to use commercial off-the-shelf (COTS) software whenever it meets our requirements. However, when COTS software is not available to satisfy requirements and the DoD must develop unique software to meet its needs, that software must be written in the Ada programming language in accordance with DoD Directive 3405.1 and DoD Instruction 5000.2. Secretary Perry's June 29, 1994 memorandum, "Specification & Standards -- A New Way of Doing Business," states that military standards will only be used "as a last resort, with an appropriate waiver." This direction has caused some confusion regarding the Ada requirement since most references to Ada cite its MIL-STD nomenclature, MIL-STD-1815A. Ada is also a Federal Information Processing Standard (FIPS 119), an American National Standards Institute (ANSI) standard (ANSI-1815A-1983), and an International Standards Organization (ISO) standard (ISO 8652-1987). Any of these alternative references may be utilized in place of the MIL- STD reference in request for proposals, contracts, and other similar documents. Thus, the Ada requirement does not conflict with the Secretary's direction, and compliance with both policies can be achieved simultaneously. Use of other programming languages can be considered if proposed by a contractor as part of his best practices since waivers to the use of Ada can be granted, where cost-effective, in accordance with procedures established in the policy referenced above. However, such proposals require strong justification to prove that the overall life-cycle cost will be less than the use of Ada will provide. Secretary Perry's memorandum encourages practices that satisfy the Department's need to build high quality systems that meet requirements at affordable costs an in a timely manner. This includes practices which support the development of Defense Software. Ada is not only a facilitator of software engineering best practice, but also has inherent features which uniquely support both real-time systems and safety-critical systems. Use of Ada also facilitates software reuse and has demonstrated reduced support costs. Accordingly, Ada is a foundation for sound software engineering practice. /signed/ /signed/ Noel Longuemare Emmett Paige, Jr. Under Secretary of Defense Assistant Secretary of Defense (Acquisition and Technology) (Command, Control, (Acting) Communications, and Intelligence) cc: DDR&E _________________________________________________________________ 14: Credits The following persons have contributed (directly or indirectly, intentionally or unintentionally, through e.g. comp.lang.ada) to the information gathered in this FAQ: Tucker�Taft, Dave�Weller, Bill�Beckwith, Chip�Bennett, Bevin�Brett, Norm�Cohen, Theodore�E.�Dennison, Robert�Dewar, Bob�Duff, Robert�Eachus, Rolf�Ebert, Laurent�Guerby, Jeffrey�L.�Grover, Richard�G.�Hash, Job�Honig, Jean�D.�Ichbiah, Nasser�Kettani, Wayne�R.�Lawton, Robert�Martin, Robb�Nebbe, Jonathan�Parker, Bruce�Petrick, Paul�Pukite, Richard�Riehle, David�Shochat, Fraser�Wilson, and the maintainer has simply :-) organized, polished, or added some information for your satisfaction. The general HTML structure of this FAQ was inspired by the WWW FAQ. _________________________________________________________________ 15: Copying this FAQ This FAQ is Copyright 1994, 1995 by Magnus Kempe. It may be freely redistributed as long as it is completely unmodified and that no attempt is made to restrict any recipient from redistributing it on the same terms. It may not be sold or incorporated into commercial documents without the explicit written permission of the copyright holder. Permission is granted for this document to be made available under the same conditions for file transfer from sites offering unrestricted file transfer on the Internet and from Forums on e.g. Compuserve and Bix. This document is provided as is, without any warranty.