Professional Documents
Culture Documents
CMSC 330 2
British mathematician & mechanical engineer Babbage described plans for an Analytical Engine
• Digital, programmable using punch cards
Invented concept of a programmable computer
• Included branching, looping, arithmetic, and storage
• Partially built a Difference Engine
• Memory would store 1000 numbers w/ 500 digits each
¾ A mechanical calculator for • Language similar to assembly language
computing polynomials
¾ Uses finite difference
• Powered by steam engine
method to avoid Partially constructed by 1910
multiplication & division
¾ Never completely finished
• Used to compute a list of multiples of π
¾ Model built in 1991 at the If built, would have been 1st Turing-complete
London Science Museum computation device
CMSC 330 5 CMSC 330 6
1
Ada Lovelace (1815-52) Alonzo Church (1903–95)
British mathematician Mathematician at Princeton University
• Corresponded with Babbage from 1833 on
• In 1843, translated Italian mathematician L. Menabrea's Key contributions
memoir on Babbage’s proposed Analytical Engine
• Lambda calculus (lectures in 1936, published 1941)
• Appended notes on how to program the Analytical
Engine to calculate Bernoulli numbers • Church’s Thesis
¾ All effective computation is expressed by recursive
• Recognized by historians as 1st published program (decidable) functions
• Making her world’s 1st programmer • Church’s Theorem
Ada programming language (1983) ¾ First order logic is undecidable
• Imperative, object-oriented language based on Pascal
• Named in her honor
CMSC 330 7 CMSC 330 8
2
Pseudocodes (Assembly Interpreter) FORTRAN (1954–1957)
Short Code (1949) FORmula TRANslator
• John Mauchly Developed at IBM by John Backus et al
• Interpreted instructions • Aimed at scientific computation
¾ E.g., X0 = sqrt(abs(Y0)) becomes 00 X0 03 20 06 Y0
• Computers slow, small, unreliable
• 06 = abs, 20 = sqrt, 03 = assignment
¾ So FORTRAN needed to produce efficient code
• But needed to translate by hand
Features (FORTRAN I)
A-0 Compiler (1951; Grace Murray Hopper) • Variable names (up to 6 chars)
• Translated symbolic code into machine code • Loops and Arithmetic Conditionals
¾ Sounds like an assembler...
¾ IF (ICOUNT-1) 100, 200, 300
• Assigned numbers to routines stored on tape • Formatted I/O
¾ Which would then be retrieved and put in memory
• Subroutines
CMSC 330 13 CMSC 330 14
3
FORTRAN Today COBOL (1959)
Success of FORTRAN led to modern compilers COmmon Business Oriented Language
Up to FORTRAN 95
• Project led by Hopper (again!)
• Modern version of the original language
• Includes pointers, recursion, more type checking, dynamic allocation, Design goals
modules, etc. • Look like simple English (but doesn’t read like it!)
Only (?) major language with column-major arrays
• Easy to use for a broad base
Still popular for scientific computing applications
• FORTRAN compilers produce good code • Notice: not aimed at scientific computing
• Language has an efficient array structure ¾ Aimed at business computing instead, very successfully
¾ C has pointers, which can hurt optimization Key features
• FORTRAN has arrays, but compiler can assume that if x and • Macros
y are arrays then x and y are unaliased
¾ Java interpreted or JIT’d, and uses dynamic dispatch heavily
• Records
• Long names (up to 30 chars), with hyphen
CMSC 330 19 CMSC 330 20
4
LISP (1958) LISP Code
LISt Processing Scheme looks like LISP
Developed by John McCarthy at MIT (defun factorial (n)
(cond ((zerop n) 1)
• Designed for AI research (t (times n (factorial (sub1 n)))))
Implemented on IBM 704 machine
Key ideas: • Machine word was 36 bits
• Symbolic expressions instead of numbers ¾ Two 15-bit parts, “address” and “decrement,” distinguished
• Lists, lists, lists ¾ car = “Contents of the Address part of Register”
• Functions, functions, functions ¾ cdr = “Contents of the Decrement part of Register”
¾ Compose simpler functions to form more complex functions Invented maplist function
¾ Recursion • Same as map function in OCaml
• Garbage collection Used lambda notation of Church for functions
CMSC 330 25 CMSC 330 26
5
Algol (1958) Example Code
procedure Absmax(a) Size:(n, m) Result:(y)
ALGOrithmic Language Subscripts:(i, k);
value n, m; array a;
• Designed to be a universal language
integer n, m, i, k; real y;
• For scientific computations comment The absolute greatest element of the
Never that popular, but extremely important matrix a, of size n by m is transferred to y, and
the subscripts of this element to i and k;
• Led to Pascal, C, C++, and Java begin integer p, q;
¾ “Algol-like” languages y := 0; i := k := 1;
• Had formal grammar (Backus-Naur Form or BNF) for p:=1 step 1 until n do
for q:=1 step 1 until m do
• Algol 60 added block structures for scoping and if abs(a[p, q]) > y then
conditionals begin y := abs(a[p, q]);
• Imperative language with recursive functions i := p; k := q
end Source: http://en.wikipedia.org/wiki/ALGOL
end Absmax
CMSC 330 31 CMSC 330 32
6
APL Example PL/I (1964)
One language to replace FORTRAN and COBOL
(~ R ∊ R o.× R) / R←1↓ιR • Went along with System/360, one mainframe to replace
Source: http://en.wikipedia.org/wiki/APL_programming_language
mainframes for science, business
• Syntax based on ALGOL
Finds prime numbers from 1 to R Famous parsing problems
• ιR creates vector containing 1..R IF THEN THEN THEN = ELSE; ELSE ELSE = THEN
• 1↓ drops first element • No reserved words. Keywords could be used as variable names
• R← assigns result to R In the end, not that successful
• R o.× R computes (outer) product 2..R × 2..R • Compilers hard to write
• R ∊ produces vector the same size as R with 1 in position i if i is ¾ Not just because of parsing; language is complex
in R o.× R ¾ Inconsistency. 1/3+10 is an illegal expression. (Overflow!)
¾ I.e., if there is a product of two numbers equal to i • Looked down on by both camps (science, business)
• ~ negates the resulting vector; call it S
• / returns a vector of items in R that have 1’s in same pos in S
CMSC 330 37 CMSC 330 38
Variables
BASIC (1964) Applesoft BASIC Example
10 INPUT "What is your name: "; U$
Beginner’s All purpose Symbolic Instruction Code Lines 20 PRINT "Hello "; U$
25 REM Comment
• John Kemeny and Thomas Kurtz (Dartmouth) numbered
30 INPUT "How many stars do you want: "; N
¾ Kemeny’s PhD advised by Church 35 S$ = ""
¾ Kemeny also developed the first time sharing system 40 FOR I = 1 TO N
50 S$ = S$ + "*”
• Multiple users could access shared mainframe as if they Loop
55 NEXT I
were the only user 60 PRINT S$ Goto
65 REM common
Goals of BASIC: 70 INPUT "Do you want more stars? "; A$
• Easy to use for beginners 80 IF LEN(A$) = 0 THEN GOTO 70
90 A$ = LEFT$(A$, 1)
• Stepping-stone to more powerful languages 100 IF (A$ = "Y") OR (A$ = "y") THEN GOTO 30
• User time is more important than computer time 110 PRINT "Goodbye ";
120 FOR I = 1 TO 200
• First program run May 1, 1964 at 4:00 am 130 PRINT U$; " ";
140 NEXT I
CMSC 330 39 CMSC 330
150 PRINT Source: http://en.wikipedia.org/wiki/BASIC_programming_language
40
7
Pascal (1971) Interesting Pascal Features
Developed by Niklaus Wirth Enumeration and subrange types
• A response to complaints about Algol 68 type day = (Sun, Mon, Tue, Wed, Thu, Fri, Sat);
Teaching tool; not meant for wide adoption type weekday = Mon..Fri;
type day_of_month = 1..31;
• Was popular for about 20 years
• Best features of COBOL, FORTRAN, and ALGOL • Key features:
¾ Safe; values will always be within range (compare to C)
• And used lowercase!
• May require dynamic checks
¾ Lowercase not introduced into ASCII until 1967
¾ Even into 80’s some mainframes were 6-bit, no lowercase Array types with arbitrary ranges
Pointers improved var hours : array[Mon..Fri] of 0..24;
Case statement var M : array[Mon..Fri] of array[char] of real;
for day := Mon to Fri do
Type declarations M[day][‘e’] := 0.0001;
Source: http://www.augustana.ca/~mohrj/courses/common/csc370/lecture_notes/pascal.html
CMSC 330 43 CMSC 330 44
8
Simula Example Parameter types Smalltalk (Early 1970s)
class Point(x,y); real x,y; Developed by Alan Kay et al at Xerox PARC
null pointer
begin
boolean procedure equals(p); ref(Point) p; • Goal: Build a small, portable computer
Return if p =/= none then Field access ¾ Remember, computers required separate rooms then
value equals := abs(x - p.x) + abs(y - p.y) < 0.00001
real procedure distance(p); ref(Point) p;
if p == none then error else
Key ideas
distance := sqrt((x - p.x)**2 + (y - p.y)**2); • Object oriented programming ideas from simula
end ***Point*** • Everything is an object
p :- new Point(1.0, 2.5);
• Intended for non-experts, especially children
q :- new Point(2.0, 3.5); • Language and language editing environment
if p.distance(q) > 2 then ... integrated into operating system
Pointer assignment Source: http://www.stanford.edu/class/cs242/slides/2004/simula-smalltalk.pdf
9
Stroustrup’s Technical Rules STL – Standard Template Library (1994)
No implicit violations of the static type system C++ library of
Provide as good support for user-defined types • Container classes, algorithms, iterators
as for built-in types • Inspired Java class libraries
Locality is good A generic library
• Abstraction and modularity • Components are parameterized using templates
Avoid order dependencies • Java didn’t get generics until 1.5 (2004)
If in doubt, pick the variant of a feature that is Example
easiest to teach vector<int> v(3); // vector of 3 int elements
v[0] = 7; // overloading [ ] operator
Syntax matters (often in perverse ways)
Preprocessor usage should be eliminated
CMSC 330 55 CMSC 330 56
10
TIOBE (Web Hits) TIOBE (Web Hits)
Top 20 languages as of April 2008
Rank Language Ratings Rank Language Ratings
1 Java 20.529% 11 JavaScript 2.434% Java
2 C 14.684% 12 D 1.169% C
3 11.699% 13 0.608% VBasic
(Visual) Basic PL/SQL
PHP
4 PHP 10.328% 14 SAS 0.572%
C++
5 C++ 9.945% 15 Pascal 0.513%
Perl
6 Perl 5.934% 16 Lisp/Scheme 0.476%
Python
7 Python 4.534% 17 FoxPro/xBase 0.459%
C#
8 C# 3.834% 18 COBOL 0.409% Ruby
9 Ruby 2.855% 19 Ada 0.393% Delphi
10 Delphi 2.665% 20 ColdFusion 0.384%
CMSC 330 61 CMSC 330 62
11