Spider | Previous | Next | Table of Contents | Index | Program List | Copyright
This book's first edition (1992) was one of the first CS1-oriented works to use Ada as the language of discourse and is currently a best-seller in its field. It was inspired by, and borrowed much material from, the successful books by Elliot Koffman using Modula-2 and Pascal, the latter now in its fifth edition.
This second edition uses Ada 95 as its language of discourse. The Ada 95 language standard was adopted early in 1995 by the International Standards Organization and the American National Standards Institute; the language governed by the standard is very similar to the 1983 original but contains a number of very interesting extensions. For our purposes, these extensions are mainly in the newly added standard libraries and the language features giving fuller support to object-oriented programming.
As with the first edition, no previous programming experience is assumed or required here; this book can genuinely be used by students who are real novices. Indeed, the first edition has been used with success in a large number of CS1-level courses. While the book is generally oriented to the first-term student of programming, there is more material here than is usually covered in a first course. Chapters 10 through 16 focus on abstract data types, generics, recursion, dynamic data structures, inheritance-oriented programming, and concurrency. They can be used selectively in a fairly advanced first course or as part of a second-level course.
In addition to making the obvious changes to conform to the Ada 95 standard, we have added new material on stacks and queues, object-oriented programming, and concurrent programming; reorganized many examples, and removed some redundant ones. Finally, we have included a continuing project, "spider graphics," as a recurring theme throughout the book. The spider is introduced first in Chapter 3 and reappears as appropriate in a number of later chapters.
Readers acquainted with the Koffman works will find some familiar themes in this book. These are not at all related to the language of discourse of the book, but are rather general teaching devices that have met with success:
A particular advantage of Ada as a teaching language is that the strong standard ensures that program behavior will be nearly independent of the particular compiler or computer being used. The programs in this book are intended to be entirely portable, to be compiled and executed on any validated Ada 95 compiler. Testing with several different suppliers' implementations on different computers has convinced us that no portability problems will be encountered with these programs.
As with the first edition, the complete set of approximately 200 programs and packages will be made readily available in various electronic forms and over the Internet. It is intended that teachers using the text make the programs available to their students, so that they do not waste time keying them in again.
The order of presentation is designed to do justice both to modern programming concepts and to the power of Ada. Each chapter presents a balanced mixture of a number of important language and computing issues. These are organized in a number of rubrics; most chapter section headings give the main rubric of the section as well as the specific topic, to orient teacher and student alike to the flow of material in a given rubric from chapter to chapter. The rubrics are as follows:
We present top-down design or refinement of a program right from the start, but make only rare use of top-down implementation through procedure stubs and the like. It is crucial to foster habits of design for reusability very early, and this argues for early emphasis of packages and the reusable functions and procedures they provide.
Functions are presented very early: They are used in
Chapter 3 and written in Chapter 4. Procedure calls are
introduced early in Chapter 2 because input/output in Ada requires
them, but procedures are not written until Chapter 6. We
believe functions are more intuitive than procedures, and, in Ada,
cannot have IN OUT
("variable") parameters. Since
functions in Ada are not restricted in their result type--arrays and
records as well as scalars can be returned--this early exposure to
functions will pay off later in encouraging students to use
functional notation where possible. Introducing functions early
allows us to introduce the writing of packages early (again in
Chapter 4).
Enumeration types are introduced very early (Chapter 3).
Enumerations are a useful structure for representing a set of values
without regard to their internal representation. Students of other
languages have a hard time seeing the utility of enumerations because
they are so hard to read and display. In Ada, the input/output
library provides a generic package for reading and displaying
enumeration values. Furthermore, enumerations serve as a useful
vehicle for motivating generic instantiation (for
Enumeration_IO
) and attributes (Pos
,
Val
, Succ
, Pred
) very early in
the game.
Records and arrays are presented together in Chapter 8, with records first. Other books have introduced arrays of scalars early, with arrays of records as an "advanced" topic. We prefer to allow arrays of records to be as natural as arrays of integers.
Design of abstract data types (ADTs) is introduced
systematically beginning in Chapter 10. Ada.Calendar
is
seen as an ADT, and the discussion continues with ADTs for calendar
dates, monetary quantities, employee records, and multiple spiders.
Unconstrained array types are treated along with
generics in Chapter 11; multi-dimensional arrays and
variant records are introduced in Chapter 12. Chapter 13
presents an introduction to recursion. Dynamic data
structures, in the form of one-way linked lists and binary trees,
as well as subunits and LIMITED PRIVATE
types, are
introduced in Chapter 14, with applications to stacks and queues.
Tagged records are introduced in Chapter 15; these are are
seen to be supportive of the type extension (inheritance) now seen as
essential to full object-oriented programming. Finally, Chapter 16
introduces the important concept of concurrent programming,
introducing Ada's task types and protected types as
language-provided constructs for concurrency.
Concepts of object-oriented programming (OOP) are introduced throughout the book as appropriate. While it is true that type extension and dynamic polymorphism are now seen as necessary to "full" OOP, it is essential for the student to understand that these are not sufficient. Ada's strong support for packages, generics, exceptions, private types, and subprogram overloading--like their equivalents in other languages--play important roles as well. The idea of an object as having state (value) and behavior (appropriate operations) is introduced beginning in Chapter 2, and "object thinking" is pervasive in the book. Type extension per se is an advanced topic that cannot be understood without a good grounding in the other topics, and so it is deferred until Chapter 15.
Assertions are introduced in Chapter 6 as structured comments and used consistently thereafter to document loop invariants and pre- and post-conditions for subprograms. We encourage the development of programs from their documentation; in case studies, the steps of the algorithm and the various assertions are written before the program is developed, and become comments as the program is refined.
We encourage appropriate use of comments but do not get carried away with them; the programs and the book would be far too long if we used industrial-strength comment conventions. Furthermore, students often respond with overkill to teachers' demands for comments, writing foolishness like
Count := Count + 1; -- add 1 to Count
It is important in introducing Ada to beginners (and we assume no previous programming experience, in any language, in this book) to introduce them, step by step, to the power of this rich language without overwhelming them. Here is a list of a number of Ada capabilities and how we have handled them:
We have avoided the use of new and derived numeric types because the compatibility issues that arise from their use create more problems than they solve for beginners. It is range checking that is important to them, not the esoterica of type compatibility.
Furthermore,using new or derived numeric types for simple beginning-level numerical problems gives completely counterintuitive results: attempting to use types for distance, rate, and time, for example, to compute the old
Distance := Rate * Time;
formula leads to type-compatibility grief that no novice should have to endure.
Ada.Text_IO
. In Chapter 3, students learn how to
use some of the capabilities of Calendar
, which has a
richness not often explored even by advanced Ada texts.
Ada.Calendar
is a recurring theme in this book, and
is discussed in the absract data type material of Chapter 10,
since Time
and the various Time
and
Duration
operations from Calendar
serve as a particularly nice predefined example of a private ADT.
Also, all students understand times and dates intuitively; there
is nothing esoteric about them.
Also in Chapter 3, use of a simple
screen-control package is introduced. Students will need to
compile this before they use it, since it is provided with the
book and is not part of most compiler distributions. Thus they
will learn how to compile a package and understand specifications
very early on, even if they don't yet understand the details of
the package body, which are discussed at some length in Chapter 7.
Screen
is used in a number of examples in the book,
especially for menu handling, plotting, and the s pider examples.
By Chapter 4, students are writing simple packages; by Chapter 5 they are learning about overloaded function and procedure names. Private types and operator overloading appear in Chapter 10.
Many packages appear in the book. Many packages (modules, units) introduced in the earlier Koffman works are no longer necessary because they focus on reading and writing enumerations, an onerous task that comes "free" with Ada! Ada 95 child packages are used in a number of cases where they are deemed appropriate.
USE
clause: This is introduced in
Chapter 7. Current Ada industry practice avoids the USE
clause for a number of good reasons. We avoid it here, in
general, because qualifying all references to package resources
helps the student really understand which resources are provided
by which libraries.
USE
and especially its Ada 95 variant USE
TYPE
can be useful in taking advantage of the overloading
of infix operators; this is discussed in Chapter 10. USE
is a better solution for novices than the industry-favored
device of renaming declarations.
Ada.Text_IO.Integer_Text_IO
and
Ada.Text_IO.Float_Text_IO
. This obviates the need for
the student to pre-instantiate a My_Int_IO
and
My_Flt_IO
, as was required in the first edition. The
new "pre-instantiations" are introduced in Chapter 2 and are used
consistently throughout. In Chapter 3 the student learns to
instantiate Ada.Text_IO.Enumeration_IO
for the
desired enumeration type. The student instantiates
Ada.Numerics.Discrete_Random
beginning in
Chapter 7.
Only one statement appears per line. We believe this makes for more modifiable code and this is a good habit for students to develop. Similarly, each variable and constant is declared in a separate declaration on its own line.
X: Float := 57.0;
contributes to program readability. However, an initialization such as
X: Float := 3.0 + Sqrt(Y);
is permitted but should not be used, because an exception
raised if Y
is negative will propagate unexpectedly.
Instead of artificially limiting initializations to static
expressions, we have simply chosen not to use them at all.
In later chapters attention is paid to those situations--especially in the use of dynamic data structures--in which assignment and equality test can indeed be used misleadingly, for example, to copy just the headers of lists. The potential for abuse of these operations provides useful justification for limited private types, for objects of which assignment and equality test are prohibited.
This book's first edition incorporated a great deal of new material intended to introduce the beginning programmer to the power of Ada, while building on the successful pedagogy of the earlier Koffman works. We believed at the time, and still believe, that the completely redesigned presentation order and the kind of new material we have introduced do justice to first courses in computing using Ada. The first edition's success among teachers of Ada--in a number of cases, even serving as critical "ammunition" in moving Pascal-based courses to Ada--confirms the soundness of the approach
The present edition builds on the success of the first, reorganizing original material and adding much new Ada 95 material. Our intention is that this book serve as an important aid to teachers ready to introduce students to Ada 95.
It is intended that teachers make the full set of about 200 programs and packages available to their students, so that they need not waste time keying them in. Programs are available on the Addison-Wesley electronic servers, on various Ada-related servers and CD-ROMs, and on the ftp server at The George Washington University. The archive files at GW are
ftp://ftp.gwu.edu/pub/ada/courses/cs1code.tar.Z
for UNIX users, and
ftp://ftp.gwu.edu/pub/ada/courses/cs1code.zip
for DOS users. The program files are named according to GNAT conventions for the respective operating systems.
Many of the programs in this book are direct adaptations of their counterparts in the first edition, which have been thoroughly tested using a number of Ada 83 compilers. The Ada 95 versions of these, and all the new programs, have been tested using the GNU-NYU Ada 95 Translator (GNAT), running on an IBM-compatible computer under MS-DOS, an Apple Macintosh under MachTen, and a Sun-SPARC computer under Solaris, and using Intermetrics AdaMagic under Solaris. The authors acknowledge the School of Engineering and Applied Science Computing Facility at The George Washington University for having provided the Solaris computing resources.
The authors are indebted to the following educators who served as
formal reviewers: Kevin Bowyer, Fred Ives, Trudy Levine, Jaime Nino,
S. Ron Oliver, Larry F. Sells, and Robert A. Willis Jr. Robert Dewar
and Ed Schonberg also offered helpful suggestions, and John Dalbey
provided the original Spider
package.
The editorial and production staff, including Lynne Doran Cote, Patsy DuMoulin, Diane Freed, Katherine Harutunian, Amanda Sylvester, Bob Woodbury, and Nancy Young, deserve hearty thanks for their expert and always good-natured assistance. Also to be thanked are Don Reifer and Charles Engle of the Ada Joint Program Office and Arra Avakian, Kathleen Mahoney, Mike Ryer, Dennis Struble, and Tucker Taft of Intermetrics, for funding and overseeing much of the revision project.
Finally, Ruth, Ben, and Keith Feldman have done it again, cheering from the sidelines, always there with logistical help, patience and loving care.
Bethesda, Maryland |
Michael B. Feldman |
Philadelphia, Pennsylvania |
Elliot B. Koffman |
Copyright ©1996 by Addison-Wesley Publishing Company, Inc.