CS 152: Programming Language Paradigms January 29 Class Meeting Department of Computer Science San...

29
CS 152: Programming Language Paradigms January 29 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak www.cs.sjsu.edu /~mak

Transcript of CS 152: Programming Language Paradigms January 29 Class Meeting Department of Computer Science San...

CS 152: Programming Language Paradigms

January 29 Class Meeting

Department of Computer ScienceSan Jose State University

Spring 2014Instructor: Ron Mak

www.cs.sjsu.edu/~mak

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

2

Small Teams

You will learn better by working in small teams.

Form your own teams of 2 or 3 students each.

Choose your team members wisely!

Be sure you’ll be able to meet and communicate with each other and work together well.

No moving to another team.

Each team member will receive the same score on the team assignments.

Email me your team name and the list of team members and email addressesby Monday, February 3 : [email protected]_

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

3

Major Programming Domains

Scientific Large numbers of floating point computations. Use of arrays. Example: FORTRAN

Business Produce reports, use decimal numbers and characters. Example: COBOL

Artificial intelligence Symbols rather than numbers manipulated. Use of linked lists. Example: LISP

_

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

4

Major Programming Domains, cont’d

Systems Need efficiency because of continuous use at a low level. Example: C

Web Markup

Example: HTML Scripting

Example: PHP General-purpose

Example: Java_

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

5

Historic Timelines

Links to more detailed and more recent programming language timelines are posted on the class web page:

http://www.cs.sjsu.edu/~mak/CS152/lectures/Timeline2013.pdf http://www.cs.sjsu.edu/~mak/CS152/lectures/Timeline2004color.pdf

_

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

6

Take roll!

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

7

A Historic Timeline

Programming Languages: Principles and Practice, 3rd ed.Kenneth Louden & Kenneth Lambert(c) 2012 Course Technology. All rights reserved. 978-1-111-52941-3

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

8

FORTRAN

FORTRAN: FORmula TRANslation language Developed by John Backus in the early 1950s. Reflected the architecture of a particular type of machine. Lacked the structured control statements and data structures

of later high-level languages.

Popular with scientists and engineers for its support for algebraic notation and floating-point numbers.

The language has evolved and is still used today. FORTRAN IV FORTRAN 77 FORTRAN 90 FORTRAN 95 FORTRAN 2015 ...

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

9

FORTRAN

DOUBLE PRECISION NUMBER, ROOTC DO 500 I = 1, 3C 5 WRITE (6, 10) 10 FORMAT ('ENTER A NUMBER')C READ (5,100) NUMBER 100 FORMAT (F5.1)C IF (NUMBER .GE. 0.0) GO TO 175 WRITE (6, 150) 150 FORMAT ('*** THE NUMBER MUST NOT BE NEGATIVE.') GOTO 5C 175 ROOT = DSQRT(NUMBER)C WRITE (6,200) NUMBER, ROOT 200 FORMAT ('THE SQUARE ROOT OF ', F5.1, ' IS ', F15.10)C 500 CONTINUEC PAUSE STOP END

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

10

COBOL

Common Business Oriented Language Primary domain is in business, finance, and administrative

systems for companies and governments. Created by a committee of researchers from private industry,

universities, and the U.S. government (specifically, the Department of Defense) in 1959.

Grace Hopper is “the mother of the COBOL language”. Specifications completed in December 1959.

A COBOL program is divided into four divisions: IDENTIFICATION DIVISION ENVIRONMENT DIVISION DATA DIVISION PROCEDURE DIVISION

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

11

COBOL

Key design goals English-like syntax to enable non-programmers (managers and

users) to read and understand the code. A simple language

No pointers No user-defined types No user-defined functions

Highly portable Machine dependencies are limited to the

ENVIRONMENT DIVISION.

FORTRAN (for scientific applications) and COBOL (for business applications) were the most popular programming languages during the 1960s and 1970s.

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

12

COBOL

Example PROCEDURE DIVISION statements:

Is it English-like?

READ StudentFile AT END SET EndOfStudentFile TO TRUE END-READ

PERFORM UNTIL EndOfStudentFile ADD 1 TO StudentCount OF WorkTotals

IF Male ADD 1 TO MaleCount OF WorkTotals ELSE ADD 1 TO FemaleCount OF WorkTotals END-IF

READ StudentFile AT END SET EndOfStudentFile TO TRUE END-READ END-PERFORM

Demo

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

13

A Historic Timeline

Programming Languages: Principles and Practice, 3rd ed.Kenneth Louden & Kenneth Lambert(c) 2012 Course Technology. All rights reserved. 978-1-111-52941-3

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

14

Algol

Algol: Algorithmic Language released in 1960 Provided a standard notation for computer scientists

to publish algorithms in journals. John Backus was a major contributor.

Structured control statements Sequencing (begin-end blocks) Loops (for loop) Selection (if and if-else statements)

Different numeric types Introduced the array structure

Supported procedures Including recursive procedures

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

15

The Algol Family

A large number of high-level languages descended from Algol, including: Pascal: language for teaching programming in the 1980s Ada: for embedded applications of U.S. Dept. of Defense

Algol control structures are present in today’s languages, including Java, C, C++, etc._

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

16

Example Pascal Program

PROGRAM Newton;

CONST epsilon = 1e-6;

VAR number : integer; root, sqroot : real;

BEGIN REPEAT writeln; write('Enter new number (0 to quit): '); read(number);

IF number = 0 THEN BEGIN writeln(number:12, 0.0:12:6); END

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

17

Example Pascal Program, cont’d

ELSE IF number < 0 THEN BEGIN writeln('*** ERROR: number < 0'); END ELSE BEGIN sqroot := sqrt(number); writeln(number:12, sqroot:12:6); writeln;

root := 1; REPEAT root := (number/root + root)/2; writeln(root:24:6, 100*abs(root - sqroot)/sqroot:12:2, '%') UNTIL abs(number/sqr(root) - 1) < epsilon; END UNTIL number = 0END.

Demo

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

18

Ada

The Ada language was developed by the U.S. Department of Defense (DoD). The most extensive and expensive language design effort.

1974: DoD projects used over 450 different languages. 1975: Military services convened to:

Identify requirements for a new DoD language. Evaluate existing languages. Recommend adoption or implementation of a language.

1979: Four language proposals were considered, all based on the Pascal language. The winner was designed by Cii Honeywell/Bull from France. Named Ada after Ada Lovelace, the first computer programmer.

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

19

Example Ada Program

-- Integer calculator program. Takes lines of input consisting of-- <operator> <number>, and applies each one to a display value. The-- display value is printed at each step. The operator is one of =,-- +, -, *, /, or ^, which correspond to assign, add, subtract, multiply-- divide, and raise, respectively. The display value is initially zero.-- The program terminates on a input of q.--with Text_IO;with Gnat.Io; use Gnat.Io;procedure Calc is Op: Character; -- Operation to perform. Disp: Integer := 0; -- Contents of the display. In_Val: Integer; -- Input value used to update the display.begin loop -- Print the display. Put(Disp); New_Line;

-- Promt the user. Put("> ");

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

20

Example Ada Program, cont’d -- Skip leading blanks and read the operation. loop Get(Op); exit when Op /= ' '; end loop;

-- Stop when we're supposed to. exit when Op = 'Q' or Op = 'q';

-- Read the integer value (skips leading blanks) and discard the -- remainder of the line. Get(In_Val); Text_IO.Skip_Line;

-- Apply the correct operation. case Op is when '=' => Disp := In_Val; when '+' => Disp := Disp + In_Val; when '-' => Disp := Disp - In_Val; when '*' => Disp := Disp * In_Val; when '/' => Disp := Disp / In_Val; when '^' => Disp := Disp ** In_Val; when '0'..'9' => Put_Line("Please specify an operation."); when others => Put_Line("What is " & Op & "?"); end case; end loop;end Calc;

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

21

The von Neumann Architecture

Most modern programming languages still retain the von Neumann machine architecture. An area of memory containing both programs and data. A single CPU that sequentially executes

program instructions fetched from memory.

1950-2000: The first five decades of computing. Hardware improvements led us into the Information Age. Moore’s Law: Hardware speeds increase by a factor of 2

every 18 months._

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

22

The von Neumann Architecture, cont’d

Concepts of Programming Languages, 10th ed.Robert W. Sebesta(c) 2012 Pearson. All rights reserved. 978-0-13-139531-2

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

23

Beyond the von Neumann Architecture

But we are now reaching the limits of physics. To increase performance, we now have multicore machines.

Programs are becoming larger and more complex. A model of computation that relies on

changes to the values of variables makes large programs difficult to debug.

What improvements do we need in software?

Programming languages need not be based on a particular model of hardware.

Languages need only to support models of computation suitable for various styles of problem solving.

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

24

Example: The Lambda Calculus

A computational model developed by the mathematician Alonzo Church in the 1930s. Based on the theory of recursive functions. Express computations by variable binding and substitution.

Lisp: A programming language that uses the functional model of computation. Created in the late 1950s by John McCarthy at M.I.T.

and later at Stanford University. Although Lisp runs on a von Neumann architecture,

its computational model does not depend on the von Neumann model._

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

25

Beyond the von Neumann Architecture, cont’d

Other non-von Neumann computational models:

Parallel processing models.

A formal logic model with automatic theorem proving.

A model involving the interaction of objects via message passing._

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

26

The Most Important Concept

What is the most important concept in computer science? Abstraction

Computer science deals with information and with complexity. We make complexity manageable by judiciously reducing it

whenever possible. Computation is the art of carefully throwing away information. Given an overwhelming collection of data, reduce it to a useable

result by discarding most of its content.

Abstraction: Treat something complex as if it were simpler by throwing away detail._

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

27

Programming Language Abstractions

Two types of programming language abstractions: Data abstraction Control abstraction

Data abstractions Simplify the behavior and attributes of data. Examples: numbers, character strings, search trees

Control abstractions Simplify properties of the transfer of control. Examples: loops, conditional statements, procedure calls

_

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

28

Programming Language Abstractions, cont’d

Abstractions can also be categorized by levels. How much information is contained or hidden

in the abstraction? An orthogonal axis to data and control.

Basic abstractions Collect the most localized machine information.

Structured abstractions Collect intermediate information about

the structure of a program.

Unit abstractions Collect large-scale information in a program.

SJSU Dept. of Computer ScienceSpring 2014: January 29

CS 152: Programming Language Paradigms© R. Mak

29

Programming Language Abstractions, cont’d

data control

basic

structured

unit

basic data

structured data

unit data

basic control

structured control

unit control

TYPE

LEV

EL