CSE 305
Programming Languages
Lecture Notes
Stuart C. Shapiro
The Program Level
It is interesting to compare programming languages on the
characteristics of:
What is the top-level structure of a program?
Is a compiler required, optional, or not used?
What happens when the program is run?
Is an interactive shell provided?
If provided, does the interactive shell process input like the program is run?
What is the top-level structure of a program?
(Ignoring compiler directives.)
bash: a sequence of commands.
C: a sequence of function definitions.
C#: a sequence of class definitions.
C++: a sequence of definitions of functions and classes.
Common Lisp: a sequence of expressions, including those that define
functions, macros, classes, etc.
Erlang: a module definition consisting of a sequence of functions definitions.
Fortran: a sequence of definitions of the PROGRAM,
SUBROUTINEs, and FUNCTIONs.
Haskell: a sequence of function definitions.
Java: a sequence of class definitions.
Perl: a sequence of statements, including those that define subroutines.
Prolog: a sequence of clauses, which can be relation (procedure) definitions
and queries (calls).
Python: a sequence of expressions and statements, including those that
define methods and classes.
Ruby: a sequence of expressions, including those that define methods and
classes.
Is a compiler required, optional, or not used?
Required: C, C#, C++, Erlang, Fortran, Java, Perl
Optional: Common Lisp, Haskell, Prolog, Python
Not used: bash, Ruby (There are some Ruby compilers available.)
What happens when the program is run?
Fortran: control is given to the PROGRAM module.
C, C++, Haskell, Java: control is given to the function named main.
C#: control is given to the function named Main.
Erlang: control is given to the function named on the command line.
bash, Common Lisp, Perl, Python, Ruby: the commands/statements/expressions
are executed/evaluated in order.
Prolog: procedures are defined and queries are run in order.
Is an interactive shell provided?
Yes: bash, Common Lisp, Haskell, Erlang, Perl, Prolog, Python, Ruby.
Available (not part of standard release): C, C#, C++, Java
No: Fortran
If provided, does the interactive shell process input like the
program is run?
Yes: bash, Common Lisp, Perl, Python, Ruby. (These could be called
scripting languages.)
No:
Erlang: Only expressions are allowed. Functions must be loaded.
Prolog: Only queries (calls) are allowed. Relations (procedure) must be
loaded (consulted).
Haskell: The interactive shell "accepts only a highly restricted subset of
Haskell...the syntax it uses for defining functions is not the same as we
use in a Haskell source file.=-" [B. O'Sullivan, J. Goerzen &
D. Stewart, Real World Haskell, O'Reilly Media, Sebastopol,
CA, 2009, p. 27.]