2. Programming languages are designed to satisfy two objectives. 2.1. People need to be able to write instructions that implement computational procedures and algorithms in a programming language. 2.2. Programming languages need to express mathematical concepts and mathematical notation. The development of programming languages has been influenced by the development of the electronic hardware that executes computer programs. Some developers of programming languages have attempted to define a language that can be used to define an algorithm without exactly specifying the sequence of instructions for the algorithm. 2.1. Early : The First Programmer 2.1.1. John von Neumann (1940 1950) Before the advent of John von Neumann results were computed using telephone switchboard machinery. If one desired a different computation, one rearranged the switchboard. John von Neumann conceived the idea that instructions and data should be stored in memory. A central processing unit should execute instructions fetched from memory. Thus the von Neumann bottleneck was born. Execution was limited by the pathway from memory to the CPU. Instructions could not be executed any faster than they could be fetched from memory. Figure 1. Von Neumann Architecture 2.1.2. Charles Babbage and Ada Lovelace (1830 1840) Charles Babbage conceived the idea of a difference engine implemented entirely using mechanical parts. He failed in his goal because sufficiently accurate machining was not available in his era. However, the concept was proven by the London Science Museum. 1
Based on Babbage's original plans, the London Science Museum constructed a working Difference Engine No. 2 from 1989 to 1991, under Doron Swade, the then Curator of Computing. Ada Lovelace developed algorithms for the difference engine and, later, for the analytical engine. It is clear from her notes that she understood both the concept of programs and the essential symbolic nature of programs. Figure 2. The Difference Engine constructed by the London Science Museum 2.2. The 1950s: The First Programming Languages 2.2.1. Machine language Machine language is the language accepted by the central processing unit (CPU) or, in the example below, a virtual machine interpreter. It consists entirely of 0s and 1s. 8 8 16 opcode operand 1 operand 2 0 7 8 15 16 31 Figure 3. Anatomy of a P-Code Instruction iaddr P-Code Operand 1 Operand 2 Comment 0 02 00 0005 Start procedure addlocal Allocate storage for variable i and the stack mark 1 02 01 0003 Reserve 3 elements for the computation stack 2 29 00 0005 Load the address of variable i in preparation to store a value. 3 2F 00 0005 Load the value of variable i 4 2A 04 0001 Load an integer constant 1. 5 0B Add the two integers on top of the stack. 6 32 04 0000 Assign the sum to variable i. 7 04 00 0000 Return to the caller 8 02 00 0004 Start program locals Allocate storage for the stack mark 2
9 02 01 0005 Reserve 5 elements for the computation stack Figure 3. Annotated Machine P-Code listing of program locals iaddr P-Code Operand 1 Operand 2 Comment A 03 0 0000 Allocate storage for procedure addlocals stack mark B 00 00 0000 Call procedure addlocal. C 04 00 0000 Return to the caller D 03 00 0000 Execution starts here. Create program main's stack mark. D 00 00 0008 Call program local F 28 00 0000 Stop Figure 3. Annotated Machine P-Code listing of program locals 2.2.2. Assembly language Assembly language is a symbolic form of machine language. Mnemonics are assigned to operations, registers, and other values. Variables are referenced by their relative address. iaddr P-Code Operand 1 Operand 2 Comment 0 ent sp 5 Start procedure addlocal Allocate storage for variable i and the stack mark 1 ent ep 3 Reserve 3 elements for the computation stack 2 lda 0 5 Load the address of variable i in preparation to store a value. 3 lvi 0 5 Load the value of variable i 4 ldc i 1 Load an integer constant 1. 5 adi Add the two integers on top of the stack. 6 sti i Assign the sum to variable i. 7 rtn p Return to the caller 8 ent sp 4 Start program locals Allocate storage for the stack mark 9 ent ep 5 Reserve 5 elements for the computation stack A mst 0 Allocate storage for procedure addlocals stack mark B cup 0 0 Call procedure addlocal. C rtn p Return to the caller D mst 0 Execution starts here. Create program main's stack mark. D cup 0 8 Call program local F stp Stop Figure 4. Annotated Assembly P-Code listing of program locals 3
program locals; procedure addlocal; var i:integer; begin{addlocal} i:=i+1 end{addlocal}; begin{locals} addlocal end{locals}. Figure 5. Program local. 2.2.3. FORTRAN First High Level Programming Language FORTRAN FORmula TRANslation John Backus 1954 1957 Scientific and computational programming Efficiency Storage allocation is not stack-based but statically allocated by the compiler for efficiency. FORTRAN II, FORTRAN IV, FORTRAN66, FORTRAN77, FORTRAN90 ******ERRORS INDUCED BY ARITHMETIC OPERATONS ON SAMLL NUMBERS REAL SUM6,SUM7,SUM8,DIF6,DIF7,DIF8,SUMINF * OPEN(6,FILE='PRN') SUM6=.9*(1.-0.1**6)/0.9 SUM7=.9*(1.-0.1**7)/0.9 SUM8=.9*(1.-0.1**8)/0.9 ******COMPUTER SUM OF INFINITE TERMS SUMINF=0.9/(1.0-0.1) ******COMPUTE DIFFERENCES BETWEEN FINITE & INFINITE SUMS DIF6 = SUMINF - SUM6 DIF7 = SUMINF - SUM7 DIF8 = SUMINF - SUM8 WRITE(6,*) 'INFINITE SUM = ', SUMINF WRITE(6,*) 'SUM6 = ', SUM6, ' INFINITE SUM - SUM6 = ', DIF6 WRITE(6,*) 'SUM7 = ', SUM7, ' INFINITE SUM - SUM7 = ', DIF7 WRITE(6,*) 'SUM8 = ', SUM8, ' INFINITE SUM - SUM8 = ', DIF8 STOP END Figure 6. A Fortran program 4
2.2.4. COBOL COmmon Business-Oriented Language U. S. Department of Defense (1959 1960) and Admiral Grace Hopper Large-scale record-keeping and other business applications A goal of the language designers was for coded programs to be easily read and understood (a failure). Business schools often offer courses on COBOL programming, but computer science departments generally do not.) The language is extremely wordy Sophisticated algorithms are difficult to program in COBOL Innovations include the record structure and separation of data declarations from executable portions of the program "The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense" - Edsger Dijkstra 1975 IDENTIFICATION DIVISION. Program-Id. Hello-World. * ENVIRONMENT DIVISION. * DATA DIVISION. * PROCEDURE DIVISION. Para1. DISPLAY "Hello, world.". * Stop Run. Figure 7. A COBOL Program 2.2.5. ALGOL60 Developed by an international Committee chaired by W. L. van der Poel including John Backus, Edsger Dijkstra, Peter Naur, and A. van Wijngaarden An Historic Event Grammar Backus Naur Form (BNF) Descendents include Pascal, C, Modula-2, and Ada Introduced many concepts including o free-format o structured statements o begin-end blocks o type declarations o recursion o pass by-value parameters o stack-based runtime environment for block-structured languages 5
begin integer i, n, b, c; real t, p, q, m, s; n:= read; c:=0; p:=0; q:=0; for i:=1 step 1 until n do begin t:=read; b:=read; p:=p+t; q:=q+t^2; if t>=7 and b>=1 then c:=c+1 end; m:=p/n; s:=sqrt(q/n-m^2); print(c); print(m); print(s) end Figure 8. An Algol Program 2.2.6. LISP Developed at MIT in the late 1950s by John McCarthy Functional programming Artificial intelligence Variants include MacLisp, Franz Lisp, Common LISP, and Scheme Based on a uniform data structure, the S-expression Introduced garbage collection Conceptually different than the von Neumann architecture and inherently inefficient. Special purpose architectures have been developed to execute Lisp programs Recursion (defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1))))) Figure 9. A Lisp Function 6
2.2.7. APL A Programming Language Ken Iverson at Harvard IBM in the late 1950s and early 1960s A language for programming mathematical computations, particularly those involving arrays and matrices APL included a large number of operators that allow most iterations to be performed completely automatically. Drawbacks include no structuring, and its use of the Greek alphabet. APL was extremely difficult to read Special IBM character set keyboard The following program finds all prime numbers from 1 to R (presuming an index origin of 1). In both time and space, the calculation is O(R 2 ). From right to left, this means: 1. creates a vector containing integers from 1 to R (if R = 6 at the beginning of the program, is 1 2 3 4 5 6) 2. Drop first element of this vector ( function), i.e. 1. So is 2 3 4 5 6 3. Set R to the vector (, assignment primitive) 4. Generate outer product of R multiplied by R, i.e. a matrix which is the multiplication table of R by R ( function) 5. Build a vector the same length as R with 1 in each place where the corresponding number in R is in the outer product matrix (, set inclusion function), i.e. 0 0 1 0 1 6. Logically negate the values in the vector (change zeros to ones and ones to zeros) (, negation function), i.e. 1 1 0 1 0 7. Select the items in R for which the corresponding element is 1 ( function), i.e. 2 3 5 2.3. The 1960s: An Explosion in Programming Languages 2.3.1. Special-purpose languages Special-purpose languages for graphics, communications, report generation, etc. Jean Sammett 2.3.2. PL/I A language to end all languages everything for everybody IBM A combination of FORTRAN, COBOL, and Algol60. concurrency exceptional handling Vienna Design Language (VDL) General Motors First failed example of a corporation that tried to make money from a programming language 7
2.3.3. Algol68 1963 1968 A more expressive and theoretically completely consistent structure. Features o general type system o expression orientation without arbitrary restrictions o completely orthogonal language 2.3.4. SNOBOL StriNg Oriented symbolic Language R. Griswold at Bell Labs early 1960s String processing language Sophisticated and powerful pattern matching facilities 2.3.5. Simula67 Created by Kristen Nygaard and OleJohan Dahl at the Norwegian Computing Center during the period 1965 1967 Designed originally for simulations Introduced the class concept First object-oriented language 2.3.6. BASIC Beginners All-purpose Symbolic Instruction Code Designed in 1964 by John Kemeny and Thomas Kurtz at Dartmouth College A simple programming language for time-sharing systems Introduced contextual type declarations 2.4. The 1970s: Simplicity, Abstraction, Study 2.4.1. Algol-W (Niklaus Wirth & C. A. R Hoare) A response to the complexity of Algol68 Simplicity and consistency 2.4.2. Pascal (Niklaus Wirth 1971) Refined and distilled the simplicity and consistency drafted in Algol-W Purpose: teaching programming Highly successful Omitted o separate compilation o adequate string handling o expandable input-output 2.4.3. C (Dennis Ritchie, 1972, Bell Labs) Goal: simplicity retaining and restricting the expression orientation reducing the complexity of the type system reducing the complexity of t he run-time system Success of C is due in part to the Unix operating system that is implemented in C. 2.4.4. CLU (Barbara Liskov, 1974 1977, MIT) Goal: a consistent approach to abstraction mechanisms including o data abstraction o control abstraction o exception handling cluster: a mechanism similar to the class construct in Simula iterator: very general control construct 2.4.5. Euclid (University of Toronto, 1976 1977) Goal: formal verification of programs 8
2.4.6. Mesa (Xerox Palo Alto Research Center, 1976 1979) Pascal-like but with the following additions o modules o exception handling o concurrency o parallel programming 2.5. The 1980s: New Directions and the Rise of Object-Orientation 2.5.1. Procedural languages 2.5.1.1. Ada (Jean Ichbiah, designed 1980, accepted 1983) o Goal: common language to implement Department of Defense embedded computer programs o Features included Pascal base package: abstract data type mechanism task: concurrency or parallel programming exception handling o Large and complex in the advent of the PC revolution o Initially no object-oriented features o Required a large infrastructure that did not exist 2.5.1.2. Modula-2 (Niklaus Wirth, 1985, 1988) Pascal successor Goal: construct operating systems module: a mechanism similar but more restricted than an Ada package. coroutine: concurrency suitable for systems programming on a singleprocessor system limited support for Abstract Data Types (ADTs) restrictive type system Ada and Modula-2 are dominated by the thought that a strongly typed language will reduce the amount of time in testing because most of the errors will be discovered in compilation as a result of type mismatches. 2.5.2. Object-oriented languages 2.5.2.1. Smalltalk (Alan Kay, Dan Ingalls, Xerox Palo Alto Research Center, 1972 1980) Purest example of an object-oriented language Developed in conjunction with a personal computer, windowing system, mouse, a graphical user interface and the Ethernet 2.5.2.2. C++ (Bjarne Stroustrup, Bell Labs, 1980 - ) Originally C with classes efficient added inheritance, polymorphism, templates, and operator overloading added libraries ported to nearly every platform An ISO standard was established in 1998 (Almost no compiler completely complies with the standard) Object-oriented languages attempt to solve the costly problem of testing by use of inheritance and layering. Once a layer has been tested it remains totally unchanged retaining the value of its tests. Creating a new program amounts to selecting the beginning layer and adding to that. Modifying a working layer invalidates the tests. 2.5.3. Functional programming languages 2.5.3.1. Scheme, ML, and Common Lisp Scheme, a more uniform Lisp developed from 1975 1978 by Gerald J. Sussman and Guy L. Steele, Jr. at MIT 9
o resembles the Lambda Calculus 2.5.3.2. ML and Miranda ML (Metalanguage) Robin Milner at Edinburgh University beginning in 1978. Syntax related to Pascal more flexible and powerful 2.5.4. Prolog (A. Colmerauer, Marseille beginning in 1972) Logic programming Based on first-order predicate calculus 2.6. The 1990s: Consolidation, the Internet, Libraries, and Scripting 2.6.1. Object-oriented programming languages 2.6.1.1. Java Developed by James Gosling at Sun Microsystems in 1995 Goal: a programming language designed to implement embedded consumer-electronic applications Most often Interpreted making it easy to port Used to implement many internet-related applications Owned by Sun Microsystem and, therefore, unlikely to have an ISO or ANSI standard Widely used in universities 2.6.2. Functional programming languages 2.6.2.1. Haskell Purely functional language similar to ML and Miranda 2.6.3. Libraries Historically, a secondary importance API (Application Programming Interface) introduced in Java 2.6.4. Scripting languages 2.6.4.1. AWK, Perl, Tcl, Javascript, Rexx, Python Definition: A scripting language is a language that ties together utilities, library components and operating system commands into complete programs. programs are often short, for example in AWK {print NR, $0} Prints any text file wit h line numbers or Tcl/Tk button.b text Hello! font {Times 16} command {puts hello} Creates a button on the screen labeled Hello! and when pressed prints the message hello to the standard output 2.6.4.2. Visual Basic 2.7. The Future 2.7.1. Escape the detailed specification of the sequence of actions that accomplish an objective. 10