Week 1 Notes - Chapter 3 - Introduction to Straignt-Line Programs
The Ages of Programming Languages
First, a review of the various "ages" of programming languages:
- The Age of Chaos - These were the bad old days of assembly
language, BASIC, early FORTRAN, and *shudder* COBOL. Variables, statements,
and GOTO-style control structures were scattered higgledy-piggledy through
countless lines of indecipherable spaghetti code. Nobody really misses these
days very much.
- The Age of Structures - A quantum improvement was achieved with
the arrival of structured programming languages like Pascal, C, and
Fortran77. The philosophy here was this: Put your lines of code into
blocks which are prefixed with declarations that describe what the
block does: i.e. if for conditional blocks, while for looping
blocks, for as a label for iterative blocks, and function as a
label for subroutines, etc. This approach was even extended to collections
of data types in the form of structs or records.
- The Age of Objects - A few shortcomings were realized in the
structured approach: While code blocks were now organized, data (i.e.
variables) and functions that acted on that data were still uncoupled.
Moreover, in debugging environments, it was discovered that taking a
procedural view of your programs, rather than a data-centric
view let a lot of bugs slip by. Therefore, meta-structures were invented
which could hold both variables, and functions which acted on those
variables; such structures were given the identifiers class and
package, among others.
Some Notable Object-Oriented Events in History
Bjarne Stroustrup introduced C++ with his extensions to the C compiler
invented by Brian Kernighan and Dennis Ritchie. IBM made waves with their
Smalltalk language that featured a very innovative approach to programming in
an event-driven environment. In recent years, Sun introduced the world
to Java which is a cleaned-up, platform-independant, strictly object-oriented
revamp of C++. Borland has presented us with Delphi, which is a tidied-up and
extended version of Object Pascal. Perl and Python have changed the way we
think about scripting languages, as each of them has some nice OO features all
its own. In 1995, the Ada language was revamped with bright, shiny
object-oriented constructs and hardly anyone cared.
Somewhere along the line, LISP was introduced which has elements of all
(and none) of those various ages.
On to Ada!
Overview of Ada Traits
Nice things about Ada:
- Encourages modular code, which makes it good for large projects
- Hard to shoot yourself in the foot; it doesn't let you do stupid things
- Clean syntax (i.e. pure-block)
- Code is very self-documenting
- Don't have to worry about non-standard versions
- A number of nice individual features: named parameters to functions,
the way they do enums, the list constructor operator, tasks, and others.
Not-so-nice things about Ada:
- Kinda wordy - Plan on doing lots of typing
- Not really any quick-and-dirty shortcuts
- Some things are a little brain-dead (output fmts., strings, files)
- Perhaps just a wee bit over-engineered
- A number of individual features are also a little weird: the way ADTs
are done is a little awkward, i.e.
Basic Syntax items:
- Most basic form of an Ada program p. 33 "hello world" (description follows)
- General form of an Ada program explained on p. 78
- Reserved words: WITH PROCEDURE IS BEGIN END (full list p. 745)
- Not case sensitive (just like Pascal) see p. 69
- Legal identifiers p. 74
- Comments p. 75
- Declaring variables and constants p. 76
- Basic text, float, and integer input / output p. 86-95
Math Operators: (Section 3.6 starting on p. 83)
- Assignment ( := )
- Addition ( + )
- Subtraction ( - )
- Multiplication ( * )
- Division ( / )
- Exponentiation ( ** )
- Modulus (remainder) ( REM )
Formatting Output: (Section 3.7 starting on p. 86)
- Text width
- Integer width
- Floating-point formatting
- Newline formatting
- Remember, just like in Pascal, identifiers PRECEED their type declaration (this
means x: Integer, NOT int x).
- Character - Use single-quotes to declare a literal character ('x')
- Float and his cousin 'NonNegFloat'. See also the chart of valid
and invalid float literals on p. 99.
- Integer and his cousins: 'Positive' (1+) and 'Natural' (0+)
- (In the next chapter, we'll learn how to use the SUBTYPE keyword for
making a "class" of a primitive type.)
- Declarations of variables used in a procedure come between the PROCEDURE
and BEGIN lines for that procedure. (as per example at beginning of sect
Afterword: Some Study Guidelines when Reading the Textbook
When you're reading the book here are some guidelines that will hopefully make
your studying less time-consuming:
- Read the first paragraph of every new section. This includes new
- Look at the example code. If you don't get it, look at the
- Read the stuff in the gray boxes that show up at the end of a
section. Look at the stuff in the white boxes, too.
- Make sure you look at the 'Chapter Review' at the end of each chapter to
get a summary of all the items covered.
Write the classic "hello world" program in Ada. It will simply display the
text "hello world" on the console, followed by a newline. The purpose of this
assignment is to make sure you know how to use the lab server, make sure your
user account works, make sure you know how to use the compiler, etc. This
assignment is due the night of the first midterm, September 26th.