Chapter Two: Genealogy of Common Languages Lesson 03.

40
Chapter Two: Genealogy of Common Languages Lesson 03

Transcript of Chapter Two: Genealogy of Common Languages Lesson 03.

Page 1: Chapter Two: Genealogy of Common Languages Lesson 03.

Chapter Two: Genealogy of Common Languages

Lesson 03

Page 2: Chapter Two: Genealogy of Common Languages Lesson 03.

Charles Babbage Babbage is credited with

inventing the first mechanical computer that eventually led to more complex designs.

In Babbage’s time, numerical tables were calculated by humans who were called ‘computers’, meaning "one who computes”

At Cambridge, he saw the high error-rate of this human-driven process and started his life’s work of trying to calculate the tables mechanically.

04/19/232 Genealogy of Common Languages

Page 3: Chapter Two: Genealogy of Common Languages Lesson 03.

Analytic Engine

04/19/23Genealogy of Common Languages3

Babbage’s analytic engine Programmed with punch “cards” First binary code (hole/no hole)

Page 4: Chapter Two: Genealogy of Common Languages Lesson 03.

Genealogy of Common Languages

Genealogy of Common Languages1-4

This chapter essentially a history lesson

Will examine the evolution of high-level compiled programming languages

What drove the adoption of what features

04/19/23

Page 5: Chapter Two: Genealogy of Common Languages Lesson 03.

IBM 704 and Fortran

Genealogy of Common Languages1-5

------------------1957------------------ Designed by IBM for the IBM 704 The IBM Mathematical FORmula

TRANslating System: FORTRAN First commercially available

compiled programming language

04/19/23

Page 6: Chapter Two: Genealogy of Common Languages Lesson 03.

Why a compiled high-level language?

04/19/23Genealogy of Common Languages6

Hardware now had floating point hardware

Previously required software to perform: “pseudocodes” Interpreted languages

(interpreter did the floating point calculations)

Environment of development Applications were scientific Machine efficiency was the most

important concern Still used today Mostly by scientific community

Page 7: Chapter Two: Genealogy of Common Languages Lesson 03.

Early versions…

04/19/23Genealogy of Common Languages7

No dynamic storage Strong array handling and

counting loops No string handling or flexible

input/output Difficult to output formatted

reports to a printer First letter of variable

determined type(strongly typed)

Compiled into one big program(no linking)

Highly optimizing compilers

John Backus: FORTRAN project

leader

Page 8: Chapter Two: Genealogy of Common Languages Lesson 03.

04/19/23Genealogy of Common Languages8

lacked

Page 9: Chapter Two: Genealogy of Common Languages Lesson 03.

Functional Programming: LISP

04/19/23Genealogy of Common Languages1-9

LISt Processing (LISP) language 1959 Designed at MIT by McCarthy

AI research needed a language to Process data in lists (rather than arrays) Symbolic computation (rather than numeric)

Represents the lists(A B C D)(A (B C) D (E (F G)))

Page 10: Chapter Two: Genealogy of Common Languages Lesson 03.

Example

04/19/23Genealogy of Common Languages10

Factorial mathematical definition

In LISP

0 if )1(*

0 if 1)(

nnfn

nnf

(DEFINE (factorial n) (IF (= n 0) 1 (* n (factorial (- n 1)))))

Page 11: Chapter Two: Genealogy of Common Languages Lesson 03.

Another example A function to determine if two lists are equal

cons Constructs a cell of two pointers, first to data, second to

next cell car and cdr (pronounced car and cudder)

car extracts contents of first pointer cdr extracts contents of second

in the case of a list, the rest of the list

04/19/23Genealogy of Common Languages11

(DEFINE (equal lis1 lis2) (COND ((NOT (LIST? lis1))(EQ? lis1 lis2)) ((NOT (LIST? lis2)) #F) ((NULL? lis1) (NULL? lis2)) ((NULL? lis2) #F) ((equal (CAR lis1) (CAR lis2)) (equal (CDR lis1) (CDR lis2)))

;a different dialect, pure LISP(DEFUN (equal_lists lis1 lis2) (COND ((ATOM lis1)(EQ lis1 lis2)) ((ATOM lis2) NIL) ((equal_lists (CAR lis1) (CAR lis2)) (equal_lists (CDR lis1) (CDR lis2))) (T NIL) ))

;a different dialect, pure LISP(DEFUN (equal_lists lis1 lis2) (COND ((ATOM lis1)(EQ lis1 lis2)) ((ATOM lis2) NIL) ((equal_lists (CAR lis1) (CAR lis2)) (equal_lists (CDR lis1) (CDR lis2))) (T NIL) ))

Page 12: Chapter Two: Genealogy of Common Languages Lesson 03.

Scheme

04/19/23Genealogy of Common Languages1-12

Common LISP and Scheme are modern dialects ML, Miranda, and Haskell are related languages Developed at MIT in mid 1970s

Page 13: Chapter Two: Genealogy of Common Languages Lesson 03.

No universal language

04/19/23Genealogy of Common Languages1-13

Many languages were being developed All for specific machines (UNIVAC, IBM, etc.) No portable language All were machine-dependent

Users rebelled, they petitioned for the design of a machine independent programming language The Association for Computing Machinery (ACM) GAMM (German acronym for Society for Applied Mathematics

and Mechanics)

Page 14: Chapter Two: Genealogy of Common Languages Lesson 03.

Design by committee

04/19/23Genealogy of Common Languages1-14

ACM and GAMM met for four days for design (May 27 to June 1, 1958)

Goals of the language Close to mathematical notation Good for describing algorithms in

publications Must be translatable to machine

code Result: a language called ALGOL

ALGOrithmic Language

// the main program, calculate the mean of// some numbers begin integer N; Read Int(N);

begin real array Data[1:N]; real sum, avg; integer i; sum:=0;

for i:=1 step 1 until N do begin real val; Read Real(val); Data[i]:=if val<0 then -val else val end;

for i:=1 step 1 until N do sum:=sum Data[i]; avg:=sum/N; Print Real(avg) endend

// the main program, calculate the mean of// some numbers begin integer N; Read Int(N);

begin real array Data[1:N]; real sum, avg; integer i; sum:=0;

for i:=1 step 1 until N do begin real val; Read Real(val); Data[i]:=if val<0 then -val else val end;

for i:=1 step 1 until N do sum:=sum Data[i]; avg:=sum/N; Print Real(avg) endend

Page 15: Chapter Two: Genealogy of Common Languages Lesson 03.

Never took-off

04/19/23Genealogy of Common Languages15

IBM didn’t back Lot of different

implementations but not standard

Much of the design was difficult to understand

But a lot of important contributions Generated a simple and elegant

means of syntax description Backus–Naur Form (BNF)

Could be argued that all subsequent imperative languages are based on it (including Pascal and C)

Page 16: Chapter Two: Genealogy of Common Languages Lesson 03.

The business of business

04/19/23Genealogy of Common Languages16

Business community and Pentagon unhappy Languages of the time were

science-dominant DoD sponsored the design and

development of a Common Business Language (first called CBL) “Records” based vs. array based

Arrays have all same data type Records can be mixed

Strong I/O capability (printed reports)

Decimal math (dollars and cents)

Page 17: Chapter Two: Genealogy of Common Languages Lesson 03.

Result: COBOL

04/19/23Genealogy of Common Languages17

1960 COmmon Business Oriented Language Use mandated by DoD

Hugely popular (in the business community) There is still, possibly, more code in use in

COBOL than any other

What do COBOL programmers think when they get on The Internets and read that Java is the New COBOL?

What do COBOL programmers think when they get on The Internets and read that Java is the New COBOL?

Page 18: Chapter Two: Genealogy of Common Languages Lesson 03.

A Teaching Programming Language

04/19/23Genealogy of Common Languages1-18

BASIC: Early 60’s Designed by Kemeny & Kurtz

at Dartmouth Design Goals:

Easy to learn and use for non-science students Interactive systems proliferating Utilized these time-sharing

(synonym for interactive) systems for easy editing and compiling

Must be “pleasant and friendly”

Fast turnaround for homework Free and private access User time is more important

than computer time Current popular dialect:

Visual BASIC

Page 19: Chapter Two: Genealogy of Common Languages Lesson 03.

The first object oriented language

04/19/23Genealogy of Common Languages1-19

SIMULA 67 (1967) Designed doing

simulations Based on ALGOL 60 Introduced modern

abstraction techniques Classes Objects Inheritance

Page 20: Chapter Two: Genealogy of Common Languages Lesson 03.

Another teaching language

04/19/23Genealogy of Common Languages1-20

Pascal – 1971 Developed by Wirth

(pronounced “Virt”: a former member of the ALGOL 68 committee)

Designed for teaching structured programming

Small, simple, nothing really new

Largest impact was on teaching programming From mid-1970s until the late

1990s, it was the most widely used language for teaching programming

Blaise Pascal was a French mathematician, physicist, and religious philosopher. He made important contributions to the construction of mechanical calculators, and ultimately, was an inspiration for Babbage

Blaise Pascal was a French mathematician, physicist, and religious philosopher. He made important contributions to the construction of mechanical calculators, and ultimately, was an inspiration for Babbage

Page 21: Chapter Two: Genealogy of Common Languages Lesson 03.

A programming language for writing operating systems and systems programs

04/19/23Genealogy of Common Languages1-21

C – 1972 at Bell Labs (Dennis Richie)

Evolved primarily from BCLP, B, but also ALGOL 68

Initially spread through UNIX Compiler came with Unix Essentially free

Free form Fortran and COBOL had

columnar (indenting) requirements

Not C Very powerful (and some would

say), therefore, very dangerous

Page 22: Chapter Two: Genealogy of Common Languages Lesson 03.

Programming Based on Logic

04/19/23Genealogy of Common Languages1-22

PROgramming LOGic (Prolog): 1973 Based on formal logic Non-procedural Based on predicate calculus

if a is true then b must be true Inference process

Infer truth of a statement Is b true? It must be because a is true

Example Rule: it can be deduced that X is the

grandparent of Z if it is true that X is the parent of Y and Y is the parent of Z Grandparent(X,Z) :- parent(X,Y), parent(Y,Z)

Can query a database of fact statements and rules Like Y is the parent of Z Looking for relationships that satisfy

rule statements like grandparent relationship

Page 23: Chapter Two: Genealogy of Common Languages Lesson 03.

DoD gets behind another language

04/19/23Genealogy of Common Languages1-23

Ada: 1983 Every system

purchased had its own language

Not enough reuse of code

History’s Largest Design Effort Competitive bidding

processAugusta Ada Byron (Augusta Ada King, Countess of Lovelace), mathematician, and daughter of poet Lord Byron. Generally recognized as being the world’s first programmer. Worked with Charles Babbage on his mechanical computers writing programs for several numerical processes.

Augusta Ada Byron (Augusta Ada King, Countess of Lovelace), mathematician, and daughter of poet Lord Byron. Generally recognized as being the world’s first programmer. Worked with Charles Babbage on his mechanical computers writing programs for several numerical processes.

Page 24: Chapter Two: Genealogy of Common Languages Lesson 03.

Ada popularity

04/19/23Genealogy of Common Languages1-24

Estimated that Ada represents the second most prevalent programming language (behind COBOL) Based upon lines of code in actively used

programs(Hook et al., 1995).

Popularity never reached desired heights SW industry grew exponentially DoD no longer as big a percentage Mandate effectively dropped in 1997 C++ grew in popularity eclipsing Ada

Page 25: Chapter Two: Genealogy of Common Languages Lesson 03.

Object-orientation comes of age

04/19/23Genealogy of Common Languages1-25

Smalltalk: 1980 Developed at the Xerox Palo

Alto Research Center (PARC) First full implementation of

an object-oriented language (data abstraction, inheritance, and dynamic binding)

Pioneered the graphical user interface design

Promoted OOP The August 1981 issue of Byte magazine was entirely on Smalltalk

Page 26: Chapter Two: Genealogy of Common Languages Lesson 03.

Taking C Object Oriented

04/19/23Genealogy of Common Languages1-26

Developed at Bell Labs: 1980 Evolved from C and SIMULA 67 Rapidly grew in popularity,

along with OOP

Page 27: Chapter Two: Genealogy of Common Languages Lesson 03.

Microsoft’s C

04/19/23Genealogy of Common Languages1-27

C# (C sharp) (2000) Part of the .NET development platform Based on C++ and Java Provides a language for component-based

software development All .NET languages use Common Type System

(CTS), which provides a common class library

Page 28: Chapter Two: Genealogy of Common Languages Lesson 03.

Platform independence

04/19/23Genealogy of Common Languages1-28

Java developed at Sun in the early 1990s Originally designed for embedded

electronic devices, though never really caught-on

Web was its big boost: applets and locally run programs (launched from browser) that were safe

Based on C++ but simplified Pure OOP: everything is an object All objects are references

Interpreted by a Virtual Machine

Page 29: Chapter Two: Genealogy of Common Languages Lesson 03.

Scripting languages

04/19/23Genealogy of Common Languages29

Interpreted So called because often used to

perform management tasks on servers in lieu of shell “scripts”

Also because often used as CGI “scripts” on Web servers

Great for ad hoc programming projects

Page 30: Chapter Two: Genealogy of Common Languages Lesson 03.

Web Scripting Languages (client-side)

04/19/23Genealogy of Common Languages1-30

User side: JavaScript Embedded in HTML

making it client-side Great for embedding

controls (like buttons and fields) Forms

Related to Java only through similar syntax Developed by Netscape

Page 31: Chapter Two: Genealogy of Common Languages Lesson 03.

Web Scripting Languages (server-side)

04/19/23Genealogy of Common Languages31

Similar to CGI but web page itself is the script Must have .asp, .php, or .jsp extension Still must “output” information that the browser will

see

PHP Used to be PHP: Hypertext Preprocessor, designed by Rasmus

Lerdorf Usually found on Linux/Unix Web Servers (Apache, etc.)

ASP Active Server Page Microsoft product used mostly on Windows Web

Servers JSP

Java Server Page Sun Microsystems

Page 32: Chapter Two: Genealogy of Common Languages Lesson 03.

Language Categories Imperative

Central features are variables, assignment statements, and iteration

Include languages that support object-oriented programming Include scripting languages Include the visual languages Examples: C, Java, Perl, JavaScript, Visual BASIC .NET, C++

Functional Main means of making computations is by applying functions to

given parameters Examples: LISP, Scheme

Logic Rule-based (rules are specified in no particular order) Example: Prolog

Markup/programming hybrid Markup languages extended to support some programming Examples: JST, ASP, PHP

04/19/23Genealogy of Common Languages32

Page 33: Chapter Two: Genealogy of Common Languages Lesson 03.

04/19/2333 Genealogy of Common Languages

Page 34: Chapter Two: Genealogy of Common Languages Lesson 03.

Fortran still used Since Fortran has been in use for more than fifty

years, there is a vast body of Fortran in daily use throughout the scientific and engineering communities. It is the primary language for some of the most intensive supercomputing tasks, such as weather and climate modeling, computational fluid dynamics, computational chemistry, computational economics, and computational physics. Even today, half a century later, many of the floating-point benchmarks to gauge the performance of new computer processors are still written in Fortran (e.g., CFP2006, the floating-point component of the SPEC CPU2006 benchmarks).

04/19/2334 Genealogy of Common Languages

return

Page 35: Chapter Two: Genealogy of Common Languages Lesson 03.

Dynamic binding Related to polymorphism Example

Collection of employee objects Manager, hourly, admin are all subclasses Inherit from employee What if each subclass had a method called

calcBonus Wouldn’t know which type of object (at compile

time) was in collection, so wouldn’t know which method to invoke

Wikipedia Polymorphism is a programming language feature

that allows values of different data types to be handled using a uniform interface.

04/19/2335 Genealogy of Common Languages

Page 36: Chapter Two: Genealogy of Common Languages Lesson 03.

References and pointers

04/19/23Genealogy of Common Languages36

In C++, if pass an object as an argument it makes a copy of that object and passes it to the method Changes to the object happen only locally (within the

method) After return, the changes are gone because they

happened to the copy If pass the address of (pointer to) the object

instead… Now not making a copy Takes less space (assuming the object is larger than

the address that points to it) If make changes in the method, they are “permanent”

Page 37: Chapter Two: Genealogy of Common Languages Lesson 03.

Reference

04/19/23Genealogy of Common Languages37

C++ allows a function’s arguments to be defined so that they will be “passed by reference”

When invoke the method, simply pass the object

Instead of making a copy of the object, the compiler does all the work of ensuring that just the address (reference) is passed

At the other end (inside the method) can treat as a normal object (not a pointer to the object)

All changes are permanent

Page 38: Chapter Two: Genealogy of Common Languages Lesson 03.

Why pass by reference

04/19/23Genealogy of Common Languages38

Pointers are dangerous Must allocate memory for the object (with the

“new” command) Set the pointer to the address of the allocated

memory Remember to de-allocate memory when done Might forget to do one or more of the above

Forgetting to de-allocate can cause memory leaks Incorrectly allocating memory (and setting pointer)

might overwrite a portion of your program or data and be difficult to troubleshoot

Page 39: Chapter Two: Genealogy of Common Languages Lesson 03.

Java and references

04/19/23Genealogy of Common Languages39

Many, many hours of programming time have been spent troubleshooting pointer problems

Passing by reference allows for much of the power of a pointer (making changes to an object in a method to which it has been passed), but without the mess

In Java, all objects are actually references (no pointers) Have to invoke “new” for every object Have to work to create a memory leak Compiler takes care of all the messy stuff (allocation, de-

allocation, etc.) Would never have a pointer pointing to the wrong

location or at nothing If set two references equal to one another still have to

separate objects; with pointers, both would point to same location in memory

Page 40: Chapter Two: Genealogy of Common Languages Lesson 03.

CGI

04/19/23Genealogy of Common Languages40

Common Gateway Interface WIKI

The Common Gateway Interface (CGI) is a standard protocol that defines how webserver software can delegate the generation of webpages to a console application. Such applications are known as CGI scripts; they can be written in any programming language, although scripting languages are often used. Perl Ruby Java

Return

It is a defined interface between a webserver and server-side scripts such that if a user opens a link to such a script the server will execute that script

It is a defined interface between a webserver and server-side scripts such that if a user opens a link to such a script the server will execute that script