CS 152 Programming Language Paradigms January 29 Class

  • Slides: 29
Download presentation
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 Science San Jose State University Spring 2014 Instructor: Ron Mak www. cs. sjsu. edu/~mak

Small Teams o You will learn better by working in small teams. o Form

Small Teams o You will learn better by working in small teams. o Form your own teams of 2 or 3 students each. n Choose your team members wisely! o o Be sure you’ll be able to meet and communicate with each other and work together well. No moving to another team. n Each team member will receive the same score on the team assignments. n Email me your team name and the list of team members and email addresses by Monday, February 3 : ron. mak@sjsu. edu _ SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 2

Major Programming Domains o Scientific n n n o Business n n o Large

Major Programming Domains o Scientific n n n o Business n n o Large numbers of floating point computations. Use of arrays. Example: FORTRAN Produce reports, use decimal numbers and characters. Example: COBOL Artificial intelligence n n n Symbols rather than numbers manipulated. Use of linked lists. Example: LISP _ SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 3

Major Programming Domains, cont’d o Systems n n o Need efficiency because of continuous

Major Programming Domains, cont’d o Systems n n o Need efficiency because of continuous use at a low level. Example: C Web n Markup o n Scripting o n Example: HTML Example: PHP General-purpose o Example: Java _ SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 4

Historic Timelines o Links to more detailed and more recent programming language timelines are

Historic Timelines o Links to more detailed and more recent programming language timelines are posted on the class web page: n http: //www. cs. sjsu. edu/~mak/CS 152/lectures/Timeline 2013. pdf n http: //www. cs. sjsu. edu/~mak/CS 152/lectures/Timeline 2004 color. pdf _ SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 5

Take roll! SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming

Take roll! SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 6

A Historic Timeline SJSU Dept. of Computer Science Spring 2014: January 29 Programming Languages:

A Historic Timeline SJSU Dept. of Computer Science Spring 2014: January 29 Programming Languages: Language Principles and Practice, 3 rd ed. CS 152: Programming Paradigms Kenneth Louden & Kenneth Lambert © R. Mak (c) 2012 Course Technology. All rights reserved. 978 -1 -111 -52941 -3 7

FORTRAN o FORTRAN: FORmula TRANslation language n n n Developed by John Backus in

FORTRAN o FORTRAN: FORmula TRANslation language n n n Developed by John Backus in the early 1950 s. Reflected the architecture of a particular type of machine. Lacked the structured control statements and data structures of later high-level languages. o Popular with scientists and engineers for its support for algebraic notation and floating-point numbers. o The language has evolved and is still used today. n n n FORTRAN IV FORTRAN 77 FORTRAN 90 FORTRAN 95 FORTRAN 2015. . . SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 8

FORTRAN DOUBLE PRECISION NUMBER, ROOT C DO 500 I = 1, 3 C 5

FORTRAN DOUBLE PRECISION NUMBER, ROOT C DO 500 I = 1, 3 C 5 WRITE (6, 10) 10 FORMAT ('ENTER A NUMBER') C READ (5, 100) NUMBER 100 FORMAT (F 5. 1) C IF (NUMBER. GE. 0. 0) GO TO 175 WRITE (6, 150) 150 FORMAT ('*** THE NUMBER MUST NOT BE NEGATIVE. ') GOTO 5 C 175 ROOT = DSQRT(NUMBER) C WRITE (6, 200) NUMBER, ROOT 200 FORMAT ('THE SQUARE ROOT OF ', F 5. 1, ' IS ', F 15. 10) C 500 CONTINUE C PAUSE SJSU Dept. of Computer Science STOP Spring 2014: January 29 END CS 152: Programming Language Paradigms © R. Mak 9

COBOL o Common Business Oriented Language n n o Primary domain is in business,

COBOL o Common Business Oriented Language n n o 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: n n IDENTIFICATION DIVISION ENVIRONMENT DIVISION DATA DIVISION PROCEDURE DIVISION SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 10

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

COBOL o Key design goals n n English-like syntax to enable non-programmers (managers and users) to read and understand the code. A simple language o o o n Highly portable o o No pointers No user-defined types No user-defined functions 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 1960 s and 1970 s. SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 11

COBOL o Example PROCEDURE DIVISION statements: READ Student. File AT END SET End. Of.

COBOL o Example PROCEDURE DIVISION statements: READ Student. File AT END SET End. Of. Student. File TO TRUE END-READ PERFORM UNTIL End. Of. Student. File ADD 1 TO Student. Count OF Work. Totals IF Male ADD 1 TO Male. Count OF Work. Totals ELSE ADD 1 TO Female. Count OF Work. Totals END-IF READ Student. File AT END SET End. Of. Student. File TO TRUE END-READ END-PERFORM n Is it English-like? SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak Demo 12

A Historic Timeline SJSU Dept. of Computer Science Spring 2014: January 29 Programming Languages:

A Historic Timeline SJSU Dept. of Computer Science Spring 2014: January 29 Programming Languages: Language Principles and Practice, 3 rd ed. CS 152: Programming Paradigms Kenneth Louden & Kenneth Lambert © R. Mak (c) 2012 Course Technology. All rights reserved. 978 -1 -111 -52941 -3 13

Algol o Algol: Algorithmic Language released in 1960 n n o Provided a standard

Algol o Algol: Algorithmic Language released in 1960 n n o Provided a standard notation for computer scientists to publish algorithms in journals. John Backus was a major contributor. Structured control statements n n n Sequencing (begin-end blocks) Loops (for loop) Selection (if and if-else statements) o Different numeric types Introduced the array structure o Supported procedures o n Including recursive procedures SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 14

The Algol Family o A large number of high-level languages descended from Algol, including:

The Algol Family o A large number of high-level languages descended from Algol, including: n n o Pascal: language for teaching programming in the 1980 s 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 Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 15

Example Pascal Program PROGRAM Newton; CONST epsilon = 1 e-6; VAR number : integer;

Example Pascal Program PROGRAM Newton; CONST epsilon = 1 e-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 Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 16

Example Pascal Program, cont’d ELSE IF number < 0 THEN BEGIN writeln('*** ERROR: number

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 = 0 END. SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak Demo 17

Ada o The Ada language was developed by the U. S. Department of Defense

Ada o The Ada language was developed by the U. S. Department of Defense (Do. D). n o o 1974: Do. D projects used over 450 different languages. 1975: Military services convened to: n n n o The most extensive and expensive language design effort. Identify requirements for a new Do. D language. Evaluate existing languages. Recommend adoption or implementation of a language. 1979: Four language proposals were considered, all based on the Pascal language. n n The winner was designed by Cii Honeywell/Bull from France. Named Ada after Ada Lovelace, the first computer programmer. SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 18

Example Ada Program -- Integer calculator program. Takes lines of input consisting of --

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 Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 19

Example Ada Program, cont’d -- Skip leading blanks and read the operation. loop Get(Op);

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; SJSU Dept. of Computer Science CS 152: Programming Language Paradigms 20 end loop; Spring 2014: January 29 © R. Mak end Calc;

The von Neumann Architecture o Most modern programming languages still retain the von Neumann

The von Neumann Architecture o Most modern programming languages still retain the von Neumann machine architecture. n n o 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. n n 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 Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 21

The von Neumann Architecture, cont’d Concepts of Programming Languages, 10 th ed. Robert W.

The von Neumann Architecture, cont’d Concepts of Programming Languages, 10 th ed. Robert W. Sebesta (c) 2012 Pearson. All rights reserved. 978 -0 -13 -139531 -2 SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 22

Beyond the von Neumann Architecture o But we are now reaching the limits of

Beyond the von Neumann Architecture o But we are now reaching the limits of physics. n o To increase performance, we now have multicore machines. Programs are becoming larger and more complex. n n 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? o Programming languages need not be based on a particular model of hardware. o Languages need only to support models of computation suitable for various styles of problem solving. SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 23

Example: The Lambda Calculus o A computational model developed by the mathematician Alonzo Church

Example: The Lambda Calculus o A computational model developed by the mathematician Alonzo Church in the 1930 s. n n o Based on theory of recursive functions. Express computations by variable binding and substitution. Lisp: A programming language that uses the functional model of computation. n n Created in the late 1950 s by John Mc. Carthy 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 Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 24

Beyond the von Neumann Architecture, cont’d o Other non-von Neumann computational models: n Parallel

Beyond the von Neumann Architecture, cont’d o Other non-von Neumann computational models: n Parallel processing models. n A formal logic model with automatic theorem proving. n A model involving the interaction of objects via message passing. _ SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 25

The Most Important Concept o What is the most important concept in computer science?

The Most Important Concept o What is the most important concept in computer science? n o Computer science deals with information and with complexity. n n n o Abstraction 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 Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 26

Programming Language Abstractions o Two types of programming language abstractions: n n o Data

Programming Language Abstractions o Two types of programming language abstractions: n n o Data abstractions n n o Data abstraction Control abstraction Simplify the behavior and attributes of data. Examples: numbers, character strings, search trees Control abstractions n n Simplify properties of the transfer of control. Examples: loops, conditional statements, procedure calls _ SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 27

Programming Language Abstractions, cont’d o Abstractions can also be categorized by levels. n n

Programming Language Abstractions, cont’d o Abstractions can also be categorized by levels. n n o Basic abstractions n o Collect the most localized machine information. Structured abstractions n o How much information is contained or hidden in the abstraction? An orthogonal axis to data and control. Collect intermediate information about the structure of a program. Unit abstractions n Collect large-scale information in a program. SJSU Dept. of Computer Science Spring 2014: January 29 CS 152: Programming Language Paradigms © R. Mak 28

LEVEL Programming Language Abstractions, cont’d unit structured basic unit data unit control structured data

LEVEL Programming Language Abstractions, cont’d unit structured basic unit data unit control structured data structured control basic data basic control data SJSU Dept. of Computer Science Spring 2014: January 29 control CS 152: Programming Language Paradigms © R. Mak TYPE 29