CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby (...

123
CPS 506 Comparative Programming L Languages Winter 2010 Winter 2010 Ryerson University Ryerson University

Transcript of CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby (...

Page 1: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

CPS 506Comparative Programming

LLanguagesWinter 2010Winter 2010

Ryerson UniversityRyerson University

Page 2: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Course OutlineCourse Outlined• Introduction

• Syntax and Semantic Specificationy p• Type Systems, Semantics and Data Types• Names Scope Expression• Names, Scope, Expression• Control Structures

b d P P i• Sub-program and Parameter Passing• Exception Handlingp g• Abstract Data Type and Encapsulation

2

Page 3: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Course Outline (con’t)Course Outline (con t)P i L P di• Programming Language Paradigms–Imperative (C Pascal …)Imperative (C, Pascal,…)–Object-Oriented (C++, C#, Java,…)

L i (P l M )–Logic (Prolog, Mercury)–Functional (ML, Scheme, Haskell,…)( , m , , )–Even-driven (Visual Basic, Java,…)

C t P ll l (SR Li d )–Concurrent or Parallel (SR, Linda,…)–Multi-Paradigm (Ruby, Python, Perl,…)g ( y y )

3

Page 4: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Course Outline (con’t)Course Outline (con t)L S• Languages Survey–ML (Meta Language) (1990s)( g g ) ( )

• Functional language–Ruby (1993)Ruby (1993)

• A balanced functional and imperative languageslanguages

–Python (1991)• Object-Oriented functional and • Object-Oriented, functional and

imperative language

4

Page 5: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

TextbookTextbookC t f P i L • Concepts of Programming Languages, 9th Edition

B R b W b– By Robert W. Sebestahttp://www.coursesmart.com/0136073476

• Programming Languages: Principles d P di 2 d Edi ig g g g p

and Paradigms, 2nd Edition– By Allen Tucker and Robert Noonany

http://www.mhhe.com/engcs/compsci/tucker/• …

5

Page 6: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

EvaluationEvaluationA i (20%)• Assignments (20%)

• Midterm (30%)Midterm (30%)• Final Exam (50%)

Optional Project (10%)• Optional Project (10%)–Programming language surveyg g g g y–Paradigm survey

6

Page 7: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Contact InformationContact Information b P• Course Web Page

www.scs.ryerson.ca/~ssamet/y(check every three days)

• Contact Email• Contact [email protected]

Offi H• Office HoursTBA

• Teaching AssistantTBA

7

Page 8: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Why programming Languages?Why programming Languages?

F ilit t i f id d • Facilitate expression of ideas and communication– The more expressive power of the language

, the deeper thought– Awareness of the programming languages

increases range of software development th ht thought processes

• Ability to choose appropriate language– understanding main features of the

languages8

Page 9: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Why programming Languages? y p g g g g(con’t)

I s bilit t l d d si • Increase ability to learn and design new languages

Understanding fundamental concepts– Understanding fundamental concepts• Better usage of the languages

L i k d d t f th – Learning unknown and unused parts of the languages

• Overall advancement of computing• Overall advancement of computing– Most popular languages are not always the

best onesbest ones– ALGOL 60 and Fortran

9

Page 10: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Introduction (con’t)Introduction (con t)Diff t f t l l• Different from natural languages– Narrower expressive domain

(Al ith i id )(Algorithmic ideas)– Communication between human and

tcomputer

• Future programming languages– Understand features, strengths and n r tan f atur , tr ngth an

weaknesses– New application needspp

10

Page 11: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Language QualitiesProgramming Language Qualities• Criteria• Criteria

–Readability• Ease of reading and understanding a • Ease of reading and understanding a

program• Before 1970s

Effi i d M hi d bilit–Efficiency and Machine readability–Design from the point of view of

computer1970 d f

p• 1970s and after

–Software life-cycle concept–MaintenanceMaintenance–Machine orientation -> Human orientation

• Consider in the context of the domain11

Page 12: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Language QualitiesProgramming Language Qualities

C it i ( ’t)• Criteria (con’t)–WritabilityWritability

• How easily a language can be used• Tough relation with readability • Tough relation with readability • Consider in the context of the domaindomain

–VB for GUIC for system programs–C for system programs

12

Page 13: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Language QualitiesProgramming Language Qualities

C it i ( ’t)• Criteria (con’t)–ReliabilityReliability

• Performs according to the specifications under all conditionsspecifications under all conditions

• Crucial criterion for embedded, scientific real-time and human scientific, real time and human related systems

13

Page 14: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Language QualitiesProgramming Language Qualities

Characteristics• Characteristics–Simplicity and Clarityp y y

• How easily a program is written and readK l d diff f th d • Knowledge difference of author and reader

Bindin–Binding• Language definition, implementation time program writing time compile time, program writing time, compile time, run time

14

Page 15: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Language Qualities (con’t)

h ( ’ )

Programming Language Qualities (con t)

• Characteristics (con’t)– Orthogonality

• Small set of primitive constructs can be combined in a small number of ways to define the components of a languagelanguage

• Not too many ways for doing the same thing• A symbol or reserve word always have the same meaning

– Type checking• Testing for type errors

E i i i• Expensive in run-time• Original C language had no parameter type checking

15

Page 16: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Language Qualities (con’t)

h ( )

Programming Language Qualities (con t)

• Characteristics (con’t)– Exception handlingE p g

• Ability to intercept run-time errors• Prevent system crashPrevent system crash

– Aliasing• Same memory two or more names• Same memory, two or more names• Side-effect• Difficult program verification• Difficult program verification

– Applicability f h l d• Support for the application domain

16

Page 17: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Language Qualities (con’t)Programming Language Qualities (con t)

• Characteristics (con’t)Abstraction–Abstraction• Complex s structures without pspecifying the detail implementation

Effi i t Im l m t ti–Efficient Implementation• Problems like in early r m n r yimplementation of Java and Ada

17

Page 18: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Language Qualities (con’t)Programming Language Qualities (con t)

• Cost– Training, Writing, Compiling, Executing, g, W g, mp g, E g,

Maintenance, Implementation environment • Portability• Portability

– One program on different platforms• Generality

– Applicability to wide range of application Applicability to wide range of application domain

18

Page 19: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Quality Trade offsQuality Trade-offsR li bilit s W it bilit• Reliability vs. Writability– C: Pointers are flexible and powerfulR li bilit E ti C t• Reliability vs. Execution Cost– Java: Array index checking

b l d b l• Writability vs. Readability– APL: Many new symbols and complex

t ticomputations• Example: Find all prime numbers from 1 to R:( R R ×R)/R 1↓ R (From Wikipedia)(~R R .×R)/R←1↓⍳R (From Wikipedia)

19

Page 20: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Influence on Language DesignInfluence on Language DesignC t A hit t• Computer Architecture– Many languages are designed according

t th l t hit t V to the prevalent architecture, Van NeumannI ti l– Imperative languages

– Both data and program in the same memory

– CPU is separate from memory– Data and instructions piped to CPU– Results moved back to memoryy

20

Page 21: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Influence on Language Design g g g(con’t)

• Van Neumann ArchitectureMemory

ControlAlgorithmic Logic UnitControl 

UnitLogic UnitAccumulator

Input InputInput Input21

Page 22: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Influence on Language Design g g g(con’t)

C t A hit t ( ’t)• Computer Architecture (con’t)–Variables model memory celly–Assignments statements based on

piping operationp p g p–Iterative form of repetition:

efficient way to implement loops efficient way to implement loops (instructions stored in adjacent cells))

–Fetch-Execute cycle

22

Page 23: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Influence on Language Design g g g(con’t)

• Software Development MethodologiesMethodologies–New paradigm, new languagesp gm, g g

23

Page 24: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming methodologies influencesProgramming methodologies influences

d l l • 1950s and early 1960s: Simple applications; machine efficiency problempp y p

Late 1960s: Efficiency became important; • Late 1960s: Efficiency became important; readability; better control structures– structured programming– top-down designtop own s gn

24

Page 25: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming methodologies influences (con’t)

• Late 1970s: Process-oriented to data-orientedoriented– data abstraction

• Mid 1980s: Object-oriented • Mid 1980s: Object-oriented programming– Data abstraction; inheritance; dynamic

method binding (polymorphism)g (p y p )25

Page 26: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Implementation MethodsImplementation MethodsC il• Compiler–Translation of the program to p g

machine code–Examples: C, Pascal, Haskell, MLmp , , ,

Interpreter• Interpreter–Program is interpreted by a software

ig p y

program, interpreter–Examples: Cobol, APL, LISPp , ,

26

Page 27: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Implementation Methods (con’t)Implementation Methods (con t)H b id impl m nt ti n• Hybrid implementation– Partially translated to detect errors

Translate to an intermediate language for easier – Translate to an intermediate language for easier interpretation

– Example: Perl, initial implementation of Javap p

• Just-In-Time– Translate to intermediate language– Compile the methods that are called

E l J N t l– Example: Java, .Net languages

27

Page 28: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

L d Vi f C mputLayered View of ComputerThe operating The operating system and language language implementation are layered are layered over machine interface of a computer

28

Page 29: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

CompilationCompilation

• Translate high-level program (source language) into machine code (source language) into machine code (machine language)

• Slow translation, fast execution

29

Page 30: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

The Compilation ProcessThe Compilation Process• Compilation process phases:

– lexical analysis: converts characters in the source program into lexical units

– IdentifiersIdentifiers– Special words– Operators– Punctuation symbols

– syntax analysis: transforms lexical units into parse trees which represent units into parse trees which represent the syntactic structure of program

– Semantics analysis: generate intermediate code

– code generation: machine code is generatedgenerated

30

Page 31: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Additional Compilation TerminologiesAdditional Compilation Terminologies

• Load module (executable image): the user and system code togetherthe user and system code together

• Linking and loading: the process of collecting system program units and linking them to a user programlinking them to a user program

31

Page 32: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Von Neumann BottleneckVon Neumann BottleneckC d b ’ • Connection speed between a computer’s memory and its processor determines the speed of a

tcomputer• Program instructions often can be executed much

f t th th d f th ti th faster than the speed of the connection; the connection speed thus results in a bottleneckK th N b ttl k it i th • Known as the von Neumann bottleneck; it is the primary limiting factor in the speed of computersM i i f h d d l f • Motivation for research and development of parallel computers

32

Page 33: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Pure InterpretationPure InterpretationN t l ti• No translation

• Works as a software simulation of a machine• Easier implementation of programs (run-time

errors can easily and immediately be di l d)displayed)

• Slower execution (10 to 100 times slower th il d )than compiled programs)– Decoding high-level language statements

St t t d d d ti t d– Statements are decoded every time executed– Bottleneck is statement decoding and not the

communication between memory and processorcommunication between memory and processor33

Page 34: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Pure Interpretation (con’t)Pure Interpretation (con t)Oft n r quir s m r sp c• Often requires more space– In addition of source, symbol table has to be present

during interpretationg p– Storing source program in a form for easy access and

modification and not in minimal size• Pure interpreters (1960s)Pure interpreters (1960s)

– APL, SNOBOL, LISP• Rarely used in high-level languages (by the

1 0 )y g g g ( y

1980s)• Significant comeback with some Web scripting

languageslanguages– JavaScript– PHP

34

Page 35: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Pure Interpretation ProcessPure Interpretation Process

35

Page 36: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Hybrid Implementation SystemsHybrid Implementation Systems

• A compromise between compilers and pure interpretersp

• A high-level language program is translated t i t di t l th t ll to an intermediate language that allows easy interpretation– Faster than pure interpretation– Source statements are decoded only onceSource statements are decoded only once

36

Page 37: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Hybrid Implementation SystemsHybrid Implementation SystemsE l• Examples– Perl programs are partially compiled to

• Detect errors before interpretation• Detect errors before interpretation• Simplify the interpreter

– Initial implementations of Java were hybrid; the mp m f y ;intermediate form, byte code, provides portability to any machine that has

B t d i t t• Byte code interpreter• Associated run-time system • Together, these are called Java Virtual Machineg , J V u M n

– New versions translate Java byte code into machine code for faster execution

37

Page 38: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Hybrid Implementation ProcessHybrid Implementation Process

38

Page 39: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Just-in-Time Implementation SystemsJust-in-Time Implementation Systems

ll l d • Initially translate programs to an intermediate language

• Then compile the intermediate language of the subprograms into machine code when they are

ll d called • Machine code version is kept for subsequent calls• JIT systems are widely used for Java programs• .NET languages are implemented with a JIT p

system

39

Page 40: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

PreprocessorsPreprocessors• Preprocessor macros (instructions) are Preprocessor macros (instructions) are

commonly used to specify that code from another file is to be includedf

• A preprocessor processes a program immediately before the program is compiled mm y f p g m mpto expand embedded preprocessor macros

• A well-known example: C preprocessormp p p– expands #include, #define, and similar

macros• Possible side effect

40

Page 41: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Principles of language designPrinciples of language designB si b l t ss l • Basic vocabulary to express language structures, meaning, …, borrowed from

Linguistics– Linguistics– MathematicsP in ipl s t i s• Principles categories– Syntax

T S t d S ti– Type Systems and Semantics– Memory Management

E ti H dli– Exception Handling

41

Page 42: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Syntax (form)Syntax (form)G f i i • Grammar for writing programs

• Basic vocabulary of• Basic vocabulary of–Keywordsy–SymbolsC bi ti f k d d • Combinations of keywords and symbols forming a syntactically symbols forming a syntactically correct program

42

Page 43: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Syntax (con’t)Syntax (con t)P l C• Pascal

program sample;var

• Cmain() {

int a b;vara,b:integer;

begin

int a,b;a = 1;b = a+1;

a := 1;b := a+1;If ( b = a ) then

if ( b == a ){

a++;( )begin

a := a+1; b := 0;

a++;b = 0;

}b := 0;end;

end.

}

43

Page 44: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Type Systems and SemanticsType Systems and SemanticsT p f l s• Type of values

• Meaning of the programsF m l pp h t und st nd ff ts f• Formal approach to understand effects of– Statements

Sequence of steps– Sequence of steps– Loops– Conditional statementsConditional statements– …

• Abstract definition (independent of machine ( por OS architectures)

44

Page 45: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Type Systems and Semantics yp y(con’t)

Diff t h t isti s f d t bj t• Different characteristics of data object– Location

N– Name– Value

T– Type• Primitive, Composite and Recursive data

t p stypes• Type Binding

T Ch k• Type Checking• Type Conversionyp

45

Page 46: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Memory ManagementMemory ManagementM i f l d • Mapping of values, data structures and program structures, and program structures to the memory

• Static memory (Stack)• Dynamic memory (Heap)• Dynamic memory (Heap)• Objects lifetimeObjects lifetime• Garbage collection

46

Page 47: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Exception HandlingException Handling

• Unexpected input errorU t d di i i b • Unexpected division by zero

• Unexpected unsuccessful space • Unexpected unsuccessful space allocation in the heapp

• A fundamental feature in modern languages

47

Page 48: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming ParadigmsProgramming ParadigmsI i• Imperative– Series of steps

• CalculateCalculate• Retrieve input• Produce output

– Procedural Abstraction• Assignments• LoopsLoops• Sequences• Conditional Statements

E l– Examples• Cobol, Fortran, C, C++

48

Page 49: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Paradigms (con’t)Programming Paradigms (con t)

d• Object Oriented– Collection of objects interact with each j

other– Building blocksBuilding blocks

• Object modeling• Classification• Classification• Inheritance

E l– Examples• Java, Smalltalk, C++, C#, Ruby, Ada 95

49

Page 50: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Paradigms (con’t)Programming Paradigms (con t)

• Logic– Collection of declarative rules– “What outcome” instead of “How

accomplish”accomplish– Natural vehicle for expressing non-

determinismdeterminism– A series of possible solutions to a problem– Examples

• Prolog

50

Page 51: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Paradigms (con’t)Programming Paradigms (con t)

l• Functional– Collection of mathematical functions– One input (domain) and one result (range)

Functions interacts using– Functions interacts using• Composition

C diti l• Conditionals• Recursion

– Examples• Lisp, Scheme, ML, Haskell

51

Page 52: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Paradigms (con’t)Programming Paradigms (con t)

• Event-drivenContinuous loop that responds to –Continuous loop that responds to events

–Events could be in various ordersl• Keystroke, mouse click, …

–Examples–Examples• Visual Basic, Java

52

Page 53: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Paradigms (con’t)Programming Paradigms (con t)

C t• Concurrent– Collection of parallel processes or p p

treads– Sharing informationSharing information– Processes could be executed

asynchronouslyasynchronously– Parallelism in one process– Examples

• SR, Linda, High Performance Fortrang53

Page 54: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Paradigms (con’t)Programming Paradigms (con t)

M lti P di• Multi-Paradigm– Support more than one programming

dparadigm– Frameworks providing a variety of styles

f for programmer to use a mix constructs from various paradigmsId Th i i l di l – Idea: There is no single paradigm to solve the problems efficiently and easilyE l– Examples• Oz, Ruby, Python, Perl, …

54

Page 55: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Application DomainsApplication Domains

• ScientificComplex calculations–Complex calculations

–Fast processp–Accurate results

I ti d ll l di–Imperative and parallel paradigms–Fortran 90, C, High Performance F 9 , , g f m

Fortran

55

Page 56: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Application Domains (con’t)Application Domains (con t)

• Management Information Systems (MIS)Systems (MIS)–Business and commercial systemsmm y m–Database management–Imperative, Declarative and

event-driven paradigmsevent-driven paradigms–Cobol, RPG, SQL, Java, Tcl/Tk, , Q , ,

56

Page 57: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Application Domains (con’t)Application Domains (con t)

• Artificial Intelligence (AI)Modelin human intelli ent bahavior–Modeling human intelligent bahavior

–Logical deductionLogical deduction–Cognition–Functional and logic paradigms

P l CLP–Prolog, CLP

57

Page 58: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Application Domains (con’t)Application Domains (con t)

• SystemsOperating systems–Operating systems

–Network software–Compilers

I ti t d i d –Imperative, event-driven, and parallel paradigms

–C

58

Page 59: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Application Domains (con’t)Application Domains (con t)

• Web-centricE Commerce–E-Commerce

–E-GovernmentE Government–Event-driven, and Object-

Oriented paradigmsPerl Tcl/Tk Visual Basic Java–Perl, Tcl/Tk, Visual Basic, Java

59

Page 60: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

60

Page 61: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Zuse’s Plankalkül (Plan Calculus)Zuse s Plankalkül (Plan Calculus)

• Designed in 1945, but not published until 1972until 1972

• First compiler in 1998• Engineering Purpose• Never implemented• Never implemented• Advanced data structures

–floating point, arrays, records

61

Page 62: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Plankalkül SyntaxPlankalkül Syntax

• An assignment statement to assign the expression A[4] + 1 assign the expression A[4] + 1 to A[5] [ ]

| A + 1 => AV | 4 5 (subscripts)S | 1.n 1.n (data types)

62

Page 63: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Minimal Hardware Programming: P d dPseudocodes

Wh i h i • What was wrong with using machine code?machine code?–Poor readabilityy–Poor modifiabilityE i di t di–Expression coding was tediousMachine deficiencies no –Machine deficiencies--no indexing or floating point

63

Page 64: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Pseudocodes: Short Code Pseudocodes: Short Code h d d l d b hl 1 4 f • Short Code developed by Mauchly in 1949 for

BINAC computers – Expressions were coded, left to right– Example of operations:Example of operations

X0 = SQRT(ABS(Y0))00 X0 03 20 06 Y000 X0 03 20 06 Y0

01 – 06 abs value 1n (n+2)nd power02 ) 07 + 2n (n+2)nd root02 ) 07 + 2n (n+2)nd root03 = 08 pause 4n if <= n04 / 09 ( 58 print and tab

64

Page 65: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Pseudocodes: SpeedcodingPseudocodes: Speedcodingd d d l d b B k 1 4 f • Speedcoding developed by Backus in 1954 for

IBM 701– Pseudo ops for arithmetic and math

functions– Conditional and unconditional branching– Auto-increment registers for array access– Auto-increment registers for array access– Slow!

O l 700 d l f f – Only 700 words left for user program

65

Page 66: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

IBM 704 and FortranIBM 704 and FortranF t 0 1954 t i l t d• Fortran 0: 1954 - not implemented

• Fortran I:1957– Designed for the new IBM 704, which had index registers and Des gned for the new IBM 704, wh ch had ndex reg sters and

floating point hardware- This led to the idea of compiled programming languages, because there was no place to hide the cost of interpretationbecause there was no place to hide the cost of interpretation

– Environment of development• Computers had small memories, slow and unreliable• Applications were scientific• No programming methodology or tools• No programming methodology or tools• Machine efficiency was the most important concern

66

Page 67: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Design Process of FortranDesign Process of Fortran• Impact of environment on design of

Fortran IFortran I–No need for dynamic storage–Need good array handling and

counting loopscounting loops–No string handling, decimal

h f l / arithmetic, or powerful input/output (for business software)(for bus ness software)

67

Page 68: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Fortran I OverviewFortran I Overview l d f • First implemented version of Fortran

– Names could have up to six charactersNames could have up to six characters– Post-test counting loop (DO)

F d /– Formatted I/O– User-defined subprogramsUser defined subprograms– Three-way selection statement

(arithmetic IF)(arithmetic IF)– No data typing statements

68

Page 69: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Fortran I Overview (con’t)Fortran I Overview (con t)F l d f F • First implemented version of FORTRAN – No separate compilationp p– Compiler released in April 1957, after 18

worker-years of effortworker years of effort– Programs larger than 400 lines rarely

compiled correctly mainly due to poor compiled correctly, mainly due to poor reliability of 704Code was very fast– Code was very fast

– Quickly became widely used

69

Page 70: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Fortran IIFortran II

• Distributed in 1958I d d t il ti–Independent compilationFixed the bugs–Fixed the bugs

70

Page 71: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Fortran IVFortran IV

• Evolved during 1960-62E li it t d l ti–Explicit type declarationsLogical selection statement–Logical selection statement

–Subprogram names could be Subprogram names could be parameters

–ANSI standard in 196671

Page 72: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Fortran 77Fortran 77

• Became the new standard in 19781978–Character string handlingCharacter string handling–Logical loop control statementg p–IF-THEN-ELSE statement

72

Page 73: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Fortran 90Fortran 90 f h f • Most significant changes from Fortran

77– Modules

Dynamic arrays– Dynamic arrays– Pointers– Recursion

CASE statement– CASE statement– Parameter type checkingyp g

73

Page 74: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Latest versions of FortranLatest versions of Fortran

• Fortran 95 – relatively minor additions plus some deletionsadditions, plus some deletions

• Fortran 2003 - dittoFortran 2003 ditto

74

Page 75: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Fortran EvaluationFortran Evaluationhl l ( ll • Highly optimizing compilers (all versions

before 90))– Types and storage of all variables are

fixed before run timefixed before run time• Dramatically changed forever the way

dcomputers are used• Characterized as the lingua franca of the Character zed as the l ngua franca of the

computing world

75

Page 76: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Functional Programming: g gLISP

P l• LISt Processing language– Designed at MIT by McCarthyg y y

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

numeric)numeric)• Only two data types: atoms and lists• Syntax is based on lambda calculus

76

Page 77: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Representation of Two LISP Lists

Representing the lists (A B C D)and (A (B C) D (E (F G)))

77

Page 78: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

LISP EvaluationLISP EvaluationP d f l • Pioneered functional programming– No need for variables or assignmentg– Control via recursion and conditional

expressionsexpressions• Still the dominant language for AI

COMMON LISP and Scheme are • COMMON LISP and Scheme are contemporary dialects of LISPML Mi d d H k ll l d • ML, Miranda, and Haskell are related languages

78

Page 79: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

SchemeScheme• Developed at MIT in mid 1970s• Small• Small• Extensive use of static scopingExtensive use of static scoping• Functions as first-class entities• Simple syntax (and small size)

make it ideal for educational make it ideal for educational applicationspp

79

Page 80: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

COMMON LISPCOMMON LISP

• An effort to combine features of several dialects of LISP into of several dialects of LISP into a single languageg g g

• Large, complex

80

Page 81: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

The First Step Toward Sophistication: ALGOL 60ALGOL 60

E f d l• Environment of development– FORTRAN had (barely) arrived for IBM 70x– Many other languages were being developed, all

for specific machines– No portable language; all were machine-

dependent– No universal language for communicating

algorithmsLG L 60 h l f ff d • ALGOL 60 was the result of efforts to design a

universal language

81

Page 82: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Early Design ProcessEarly Design ProcessACM d GAMM t f f d • ACM and GAMM met for four days for design (May 27 to June 1, 1958)g y

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

Must be translatable to machine –Must be translatable to machine code

82

Page 83: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

ALGOL 58ALGOL 58C f f li d• Concept of type was formalized

• Names could be any lengthA s c uld h n numb f subsc ipts• Arrays could have any number of subscripts

• Parameters were separated by mode (in & out)• Subscripts were placed in brackets• Subscripts were placed in brackets• Compound statements (begin ... end)• Semicolon as a statement separatorSemicolon as a statement separator• Assignment operator was :=• if had an else-if clausef f• No I/O - “would make it machine dependent”

83

Page 84: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

ALGOL 58 ImplementationALGOL 58 Implementation

• Not meant to be implemented, but variations of it were (MAD but variations of it were (MAD, JOVIAL))

• Although IBM was initially enthusiastic, all support was dropped by mid 1959dropped by mid 1959

84

Page 85: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

ALGOL 60 OverviewALGOL 60 Overviewd f d G 6 d P• Modified ALGOL 58 at 6-day meeting in Paris

• New features– Block structure (local scope)– Two parameter passing methods– Two parameter passing methods– Subprogram recursion

k d i – Stack-dynamic arrays

– Still no I/O and no string handling

85

Page 86: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

ALGOL 60 EvaluationALGOL 60 EvaluationS• Successes–It was the standard way to publish It was the standard way to publish

algorithms for over 20 yearsAll subsequent imperative languages –All subsequent imperative languages are based on it

–First machine-independent language–First language whose syntax was First language whose syntax was

formally defined (BNF)

86

Page 87: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

ALGOL 60 Evaluation (con’t)ALGOL 60 Evaluation (con t)F l• Failure– Never widely used, especially in U.S.– Reasons

• Lack of I/O and the character set made programs non-portable

• Too flexible--hard to implement• Entrenchment of Fortran• Formal syntax descriptiony p• Lack of support from IBM

87

Page 88: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Computerizing Business Records: COBOLComputerizing Business Records: COBOL

• Environment of developmentUNIVAC b i i t –UNIVAC was beginning to use FLOW-MATICFLOW MATIC

–USAF was beginning to use g gAIMACO

–IBM was developing COMTRAN

88

Page 89: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

COBOL Historical BackgroundCOBOL Historical BackgroundB d F• Based on FLOW-MATIC

• FLOW-MATIC features– Names up to 12 characters, with embedded

hyphenshyphens– English names for arithmetic operators (no

arithmetic expressions)arithmetic expressions)– Data and code were completely separate

Th fi d i – The first word in every statement was a verb

89

Page 90: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

COBOL Design ProcessCOBOL Design ProcessFi D i M i (P ) M 1959• First Design Meeting (Pentagon) - May 1959

• Design goalsMust l k lik simpl En lish– Must look like simple English

– Must be easy to use, even if that means it will be less powerfulpowerful

– Must broaden the base of computer users– Must not be biased by current compiler problemsy p p

• Design committee members were all from computer manufacturers and DoD branches

• Design Problems: arithmetic expressions? subscripts? Fights among manufacturers

90

Page 91: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

COBOL EvaluationCOBOL Evaluation• Contributions

– First macro facility in a high-level First macro facility in a high level languageHierarchical data structures (records)– Hierarchical data structures (records)

– Nested selection statements– Long names (up to 30 characters), with

hyphenshyphens– Separate data division

91

Page 92: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

COBOL: DoD InfluenceCOBOL: DoD Influence

• First language required by DoDld h f il d ith t D D–would have failed without DoD

• Still the most widely used • Still the most widely used business applications languagepp g g

92

Page 93: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Th B i i f Ti h i BASICThe Beginning of Timesharing: BASIC

D d b K & K D h• Designed by Kemeny & Kurtz at Dartmouth• Design Goals:

– Easy to learn and use for non-science students– Must be “pleasant and friendly”– Fast turnaround for homework– Free and private accessp– User time is more important than computer time

• Current popular dialect: Visual BASIC Current popular dialect Visual BASIC • First widely used language with time sharing

93

Page 94: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Everything for Everybody: y g y yPL/I

D d b BM d H RE• Designed by IBM and SHARE• Computing situation in 1964 (IBM's point of view)

– Scientific computing• IBM 1620 and 7090 computers• FORTRAN• SHARE user groupg p

– Business computing• IBM 1401, 7080 computersIBM 1401, 7080 computers• COBOL• GUIDE user groupGUIDE user group

94

Page 95: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

PL/I: BackgroundPL/I: BackgroundB 1963 • By 1963 – Scientific users began to need more elaborate I/O, like

COBOL had; business users began to need floating COBOL had; business users began to need floating point and arrays for MIS

– It looked like many shops would begin to need two kinds y p gof computers, languages, and support staff--too costly

• The obvious solution– Build a new computer to do both kinds of applications– Design a new language to do both kinds of applications

95

Page 96: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

PL/I: Design ProcessPL/I: Design ProcessD d f h b h • Designed in five months by the 3 X 3 Committee– Three members from IBM, three members

from SHARE• Initial concept

– An extension of Fortran IV– An extension of Fortran IV• Initially called NPL (New Programming

Language)Language)• Name changed to PL/I in 1965

96

Page 97: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

PL/I: EvaluationPL/I: EvaluationPL/ b• PL/I contributions– First unit-level concurrency– First exception handling– Switch-selectable recursion– First pointer data type– First array cross sectionsy

• Concerns– Many new features were poorly designedMany new features were poorly designed– Too large and too complex

97

Page 98: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Two Early Dynamic Languages: APL and SNOBOL

• Characterized by dynamic typing and dynamic storage allocationand dynamic storage allocation

• Variables are untypedyp–A variable acquires a type when

it i i d lit is assigned a value• Storage is allocated to a variable • Storage is allocated to a variable

when it is assigned a value98

Page 99: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

APL: A Programming g gLanguage

d h d d • Designed as a hardware description language at IBM by Ken Iverson around g g y1960– Highly expressive (many operators for – Highly expressive (many operators, for

both scalars and arrays of various dimensions)dimensions)

– Programs are very difficult to readg y• Still in use; minimal changes

99

Page 100: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

SNOBOLSNOBOLD d l l • Designed as a string manipulation language at Bell Labs by Farber, Griswold, and Polensky in 19641964

• Powerful operators for string pattern p g pmatching

• Slower than alternative languages (and thus Slower than alternative languages (and thus no longer used for writing editors)

• Still used for certain text processing tasks• Still used for certain text processing tasks

100

Page 101: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

The Beginning of Data Abstraction: SIMULA 67

d l f • Designed primarily for system simulation in Norway by Nygaard and y y ygDahl

• Based on ALGOL 60 and SIMULA I• Based on ALGOL 60 and SIMULA I• Primary Contributions

– Coroutines - a kind of subprogram– Classes objects and inheritance– Classes, objects, and inheritance

101

Page 102: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Orthogonal Design: ALGOL 68Orthogonal Design: ALGOL 68

F h d d l f G • From the continued development of ALGOL 60 but not a superset of that language

• Source of several new ideas (even though the language itself never achieved widespread g g puse)

• Design is based on the concept of Design is based on the concept of orthogonality– A few basic concepts plus a few combining – A few basic concepts, plus a few combining

mechanisms

102

Page 103: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

ALGOL 68 EvaluationALGOL 68 EvaluationC b• Contributions– User-defined data structures– Reference types– Dynamic arrays (called flex arrays)

• Comments– Less usage than ALGOL 60– Had strong influence on subsequent languages, Had strong influence on subsequent languages,

especially Pascal, C, and Ada

103

Page 104: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Pascal 1971Pascal - 1971D l d b h ( f b f h • Developed by Wirth (a former member of the ALGOL 68 committee)

• Designed for teaching structured programmingp g g

• Small, simple, nothing really new• Largest impact was on teaching programming• Largest impact was on teaching programming

– From mid-1970s until the late 1990s, it was the most widely used language for teaching the most widely used language for teaching programming

104

Page 105: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

C 1972C - 1972d f ( • Designed for systems programming (at

Bell Labs by Dennis Richie)y )• Evolved primarily from BCLP, B, but also

ALGOL 68ALGOL 68• Powerful set of operators, but poor type

h kichecking• Initially spread through UNIXIn t ally spread through UNIX• Many areas of application

105

Page 106: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Programming Based on Logic: g g gProlog

D l d b d l • Developed, by Comerauer and Roussel (University of Aix-Marseille), with help from

l k ( f Ed b h)Kowalski ( University of Edinburgh)• Based on formal logicg• Non-procedural• Can be summarized as being an intelligent • Can be summarized as being an intelligent

database system that uses an inferencing process to infer the truth of given queriesprocess to infer the truth of given queries

• Highly inefficient, small application areas

106

Page 107: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

History’s Largest Design y g gEffort: Ada

H d ff l h d d f • Huge design effort, involving hundreds of people, much money, and about eight years– Strawman requirements (April 1975)– Woodman requirements (August 1975)Woodman requirements (August 1975)– Tinman requirements (1976)

Ironman equipments (1977)– Ironman equipments (1977)– Steelman requirements (1978)

• Named Ada after Augusta Ada Byron, the first programmerp g

107

Page 108: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Ada EvaluationAda EvaluationC t ib ti• Contributions– Packages - support for data abstraction– Exception handling - elaborate Except on handl ng elaborate – Generic program units– Concurrency - through the tasking model

• Comments– Competitive design– Included all that was then known about software engineering Included all that was then known about software engineering

and language design– First compilers were very difficult; the first really usable

compiler came nearly five years after the language design was compiler came nearly five years after the language design was completed

108

Page 109: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Ada 95Ada 95d (b 1 )• Ada 95 (began in 1988)

– Support for OOP through type derivationpp g yp– Better control mechanisms for shared data– New concurrency features– New concurrency features– More flexible libraries

P l i ff d b h D D • Popularity suffered because the DoD no longer requires its use but also because of

l i f Cpopularity of C++

109

Page 110: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Object-Oriented Programming: S ll lkSmalltalk

• Developed at Xerox PARC, initially by Alan Kay, later by Adele Goldbergy, y g

• First full implementation of an object-i t d l (d t b t ti oriented language (data abstraction,

inheritance, and dynamic binding)• Pioneered the graphical user interface design

P t d OOP• Promoted OOP

110

Page 111: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Combining Imperative and Object-O i t d P i COriented Programming: C++

D l d t B ll L b b St t i 1980• Developed at Bell Labs by Stroustrup in 1980• Evolved from C and SIMULA 67 • Facilities for object-oriented programming taken partially from Facilities for object oriented programming, taken partially from

SIMULA 67• Provides exception handling• A large and complex language, in part because it supports both

procedural and OO programming• Rapidly grew in popularity along with OOPRapidly grew in popularity, along with OOP• ANSI standard approved in November 1997• Microsoft’s version (released with .NET in 2002): Managed C++

– delegates, interfaces, no multiple inheritance

111

Page 112: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Related OOP LanguagesRelated OOP Languagesl ( )• Eiffel (designed by Bertrand Meyer - 1992)

– Not directly derived from any other languagey y g g– Smaller and simpler than C++, but still has most

of the powerof the power– Lacked popularity of C++ because many C++

enthusiasts were already C programmersenthusiasts were already C programmers• Delphi (Borland)

– Pascal plus features to support OOP– More elegant and safer than C++g

112

Page 113: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

An Imperative-Based Object-Oriented L JLanguage: Java

D l d i h l 1990• Developed at Sun in the early 1990s– C and C++ were not satisfactory for embedded

l t i d i selectronic devices• Based on C++

Si ifi tl i lifi d (d t i l d t t – Significantly simplified (does not include struct, union, enum, pointer arithmetic, and half of the assignment coercions of C++) assignment coercions of C++)

– Supports only OOP– Has references but not pointers– Has references, but not pointers– Includes support for applets and a form of

concurrencyconcurrency113

Page 114: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Java EvaluationJava Evaluation• Eliminated many unsafe features of C++• Supports concurrencypp y• Libraries for applets, GUIs, database access

P bl J Vi l M hi JIT • Portable: Java Virtual Machine concept, JIT compilers

• Widely used for Web programming• Use increased faster than any previous language• Use increased faster than any previous language• Most recent version, 5.0, released in 2004

114

Page 115: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Scripting Languages for the p g g gWeb

P l• Perl– Designed by Larry Wall—first released in 1987

V i bl s st tic ll t p d but implicitl d cl d– Variables are statically typed but implicitly declared– Three distinctive namespaces, denoted by the first

character of a character of a variable’s name

– Powerful, but somewhat dangerous, g– Gained widespread use for CGI programming on the

Web– Also used for a replacement for UNIX system

administration language

115

Page 116: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Scripting Languages for the p g g gWeb

• JavaScript– Began at Netscape, but later became a joint g p , m j

venture of Netscape and Sun MicrosystemsA client side HTML embedded scripting – A client-side HTML-embedded scripting language, often used to create dynamic HTML ddocuments

– Purely interpretedy p– Related to Java only through similar syntax

116

Page 117: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Scripting Languages for the p g g gWeb

• PHP– PHP: Hypertext Preprocessor designed by PHP: Hypertext Preprocessor, designed by

Rasmus Lerdorf– A server-side HTML-embedded scripting

language, often used for form processing g g , p gand database access through the WebP l i t t d– Purely interpreted

117

Page 118: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Scripting Languages for the p g g gWeb

• Python– An OO interpreted scripting languageAn OO interpreted scripting language– Type checked but dynamically typed– Used for CGI programming and form

processingprocessing– Dynamically typed, but type checked– Supports lists, tuples, and hashes

118

Page 119: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Scripting Languages for the p g g gWeb

• Lua– An OO interpreted scripting language– Type checked but dynamically typed– Used for CGI programming and form processingp g g p g– Dynamically typed, but type checked– Supports lists tuples and hashes all with its Supports lists, tuples, and hashes, all with its

single data structure, the tablethe table

– Easily extendable

119

Page 120: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Scripting Languages for the p g g gWeb

• Ruby– Designed in Japan by Yukihiro Matsumoto g p y

(a.k.a, “Matz”)– Began as a replacement for Perl and PythonBegan as a replacement for Perl and Python– A pure object-oriented scripting language

All d t bj t- All data are objects– Most operators are implemented as methods,

which can be redefined by user code– Purely interpretedy p

120

Page 121: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

A C-Based Language for the New Mill i C#Millennium: C#

• Part of the .NET development platform (2000)( )

• Based on C++ , Java, and Delphi• Provides a language for component-based

software developmentp• All .NET languages use Common Type System

(CTS) hi h id l lib(CTS), which provides a common class library

121

Page 122: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Markup/Programming Hybrid LanguagesMarkup/Programming Hybrid Languages

• XSLT– eXtensible Markup Language (XML): a eXtensible Markup Language (XML): a

metamarkup language– eXtensible Stylesheet Language

Transformation (XSTL) transforms XML ( )documents for displayP i t t ( l i )– Programming constructs (e.g., looping)

122

Page 123: CPS 506 Comparative Programming Languagesssamet/cps506/CPS 506 (Winter 2010 Ryerson... · –Ruby ( 1993 ) • A balanced functional and imperative languages –Python (1991) •

Markup/Programming Hybrid LanguagesMarkup/Programming Hybrid Languages

• JSP– Java Server Pages: a collection of technologies g g

to support dynamic Web documents– servlet: a Java program that resides on a Web servlet a Java program that resides on a Web

server and is enacted when called by a requested HTML document; a servlet’s output requested HTML document; a servlet s output is displayed by the browserJSTL includes programming constructs in the – JSTL includes programming constructs in the form of HTML elements

123