CS 152 Programming Language Paradigms January 27 Class

  • Slides: 31
Download presentation
CS 152: Programming Language Paradigms January 27 Class Meeting Department of Computer Science San

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

CS 152: Programming Language Paradigms o o o Instructor: Ron Mak Faculty website: http:

CS 152: Programming Language Paradigms o o o Instructor: Ron Mak Faculty website: http: //www. cs. sjsu. edu/~mak/ Office hours: MW 7: 15 - 8: 30 pm in MH 413 SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 2

Course Notes o Class website n n o http: //www. cs. sjsu. edu/~mak Green

Course Notes o Class website n n o http: //www. cs. sjsu. edu/~mak Green sheet Lecture notes and handouts Assignments Required textbook: Programming Languages: Principles and Practice, 3 rd edition by Kenneth Louden and Kenneth Lambert _ SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 3

Goals of the Course o Program in languages from different “cultures”. n n Learn

Goals of the Course o Program in languages from different “cultures”. n n Learn new ideas and concepts. Apply the new concepts to your “native” language. o n o C++, Java, etc. Become a better programmer! Different programming cultures (paradigms). n Object-oriented o n Functional o n C++, C#, Objective C, Java, etc. Lisp, Scheme, ML, Haskell, F# Logic o Prolog SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 4

Goals of the Course o How are programming languages designed? n n o Can

Goals of the Course o How are programming languages designed? n n o Can we design a language? What are the design criteria? How can we specify the language’s syntax and semantics? What about data types and control structures? How are programming languages implemented? n n Interpreters Compilers _ SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 5

Course Overview o First half: Mostly about culture. n n n Introduction Design criteria

Course Overview o First half: Mostly about culture. n n n Introduction Design criteria Functional paradigm Logic paradigm Object-oriented paradigm Syntax and semantics o Midterm o Second half: Mostly about design and implementation n n o Data types and control structures Abstract data types Formal semantics Introduction to compilers and interpreters Final SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 6

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. After forming a team, 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 27 CS 152: Programming Language Paradigms © R. Mak 7

Individual Responsibilities You are personally responsible for participating and contributing to your team’s work,

Individual Responsibilities You are personally responsible for participating and contributing to your team’s work, and for understanding each part of the work for every assignment, whether or not you worked on that part. SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 8

Postmortem Assessment Report o At the end of the semester, each student will individually

Postmortem Assessment Report o At the end of the semester, each student will individually turn in a short (1 page) report: n A brief description of what you learned in the course. o n An assessment of your personal accomplishments for your project team. n An assessment of each of your project team members. _ SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 9

Individual Student’s Overall Class Grade o 60% assignments (team scores) 15% midterm exam (individual

Individual Student’s Overall Class Grade o 60% assignments (team scores) 15% midterm exam (individual score) 25% final exam (individual score) Final letter grade based on the class curve. o Participation will be important! o o o n n n Can move your final grade up or down, especially in borderline cases. Participation in class. Participation in your team. o As reported by the postmortem assessment reports. _ SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 10

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

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

Introduction o How we program computers influences how we think about computation, and vice

Introduction o How we program computers influences how we think about computation, and vice versa. o The basic principles and concepts of programming languages are part of the fundamental body of computer science knowledge. n o The study of these principles is essential to programmers and to computer scientists. We will study principles and concepts. n n The languages we examine will illustrate how to apply these principles and concepts. Not a “language of the week” class. _ SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 12

More Good Reasons o Increased capacity to express ideas. n n o The depth

More Good Reasons o Increased capacity to express ideas. n n o The depth at which we can think is influenced by the expressive power of the language in which we communicate our thoughts. Example: If you have weak grasp of your natural language, you are limited in the complexity of your thinking, particularly in the area of abstraction. Improved background for choosing appropriate languages. n Make better informed choices if you are familiar with other available languages, especially the particular features of those languages. _ SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 13

More Good Reasons, cont’d o Increased capacity to learn new languages. n n o

More Good Reasons, cont’d o Increased capacity to learn new languages. n n o Better understanding language implementation. n o A thorough understanding of the fundamental concepts of languages makes it easier to see how those concepts are incorporated into the design of the new languages. Learning a new language gives you better understanding of your first language. Understand implementation issues Understand why languages are designed the way they are Ability to use a language more intelligently. Increased ability to design new languages. n n Advance the state of the art. Better languages can crowd out poor languages. SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 14

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

A Historic Timeline SJSU Dept. of Computer Science Spring 2014: January 27 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 15

Origins of Programming Languages o A programming language is often defined as “a notation

Origins of Programming Languages o A programming language is often defined as “a notation for communicating to a computer what we want it to do”. o Before the mid 1940 s, computer operators set switches to adjust the internal wiring of a computer to perform the requested tasks. o Programming languages allowed computer users to solve problems without having to reconfigure hardware. _ SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 16

Plugboard Control Panel IBM 407 Accounting Machine (1949) SJSU Dept. of Computer Science Spring

Plugboard Control Panel IBM 407 Accounting Machine (1949) SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 17

Programming a Plugboard o “Programming” was hand-wiring plugboards. “Hmm, should I pass this parameter

Programming a Plugboard o “Programming” was hand-wiring plugboards. “Hmm, should I pass this parameter by value or by reference? ” SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 18

Programming a Plugboard o Plugboard wiring diagram n SJSU Dept. of Computer Science Spring

Programming a Plugboard o Plugboard wiring diagram n SJSU Dept. of Computer Science Spring 2014: January 27 It doesn’t look too complicated, does it? CS 152: Programming Language Paradigms © R. Mak 19

Machine Language o John von Neumann proposed that computers should be permanently hardwired with

Machine Language o John von Neumann proposed that computers should be permanently hardwired with a small set of general-purpose operations. n An operator could input a series of binary codes to organize the basic hardware operations to solve more specific problems. n Operators could flip switches to enter these codes, called machine language, into memory. _ SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 20

Machine Language o Machine language programming was tedious and error prone. SJSU Dept. of

Machine Language o Machine language programming was tedious and error prone. SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 21

Assembly Language o Assembly language: a set of mnemonic symbols for instruction codes and

Assembly Language o Assembly language: a set of mnemonic symbols for instruction codes and memory locations. n Example: LD R 1, R 2 o Assembler: a program that translates the symbolic assembly language code to binary machine code. o Loader: a program that loads the machine code into computer memory for execution. o Input devices: n n Keypunch machine Punched card reader _ SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 22

IBM 1401 Autocoder Programming o 80/80 List n Read and print a deck of

IBM 1401 Autocoder Programming o 80/80 List n Read and print a deck of cards. JOB 80/80 CARD LISTER ORG CS CS SW 333 332 * START * READ * DONE R MCW W BLC B H END SJSU Dept. of Computer Science Spring 2014: January 27 1, 201 80, 280 DONE READ DONE START LOCATE AFTER THE PRINT AREA CLEAR STORAGE 332 - 300 CLEAR STORAGE 299 - 200 SET WORD MARKS AT 1 AND 201 READ A CARD INTO READ AREA MOVE TO PRINT AREA Main loop PRINT IT GO TO DONE IF LAST CARD READ ELSE GO READ ANOTHER CARD ALL DONE CS 152: Programming Language Paradigms © R. Mak MCW Move characters to word mark 23

Assembly Language o o Mnemonic symbols were an improvement over binary machine codes but

Assembly Language o o Mnemonic symbols were an improvement over binary machine codes but still had shortcomings. n Lacks abstraction of conventional mathematical notation. n Each type of computer hardware architecture has its own machine language instruction set and requires its own dialect of assembly language. Assembly languages first appeared in the 1950 s and are still used today for low-level system tools or for hand-optimization. _ SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 24

Punched Cards o Data was stored in punched cards called “IBM cards” or “Hollerith

Punched Cards o Data was stored in punched cards called “IBM cards” or “Hollerith cards” n SJSU Dept. of Computer Science Spring 2014: January 27 Named after Herman Hollerith. o 80 columns per card, one character per column. o Up to 12 punched holes per column. o Alphanumeric data, often grouped into fields. _ CS 152: Programming Language Paradigms © R. Mak 25

A Data Processing Job o A typical “job”. Tanenbaum & Woodhull Operating Systems: Design

A Data Processing Job o A typical “job”. Tanenbaum & Woodhull Operating Systems: Design and Implementation (c) 2006 Prentice-Hall, Inc. All rights reserved. 0 -13 -142938 -8 SJSU Dept. of Computer Science Spring 2014: January 27 CS 152: Programming Language Paradigms © R. Mak 26

Punched Cards o Data processing was all about punched cards. o My school compiler

Punched Cards o Data processing was all about punched cards. o My school compiler project: n n SJSU Dept. of Computer Science Spring 2014: January 27 3½ boxes of punched cards Each box = 2000 cards, 10 lbs. CS 152: Programming Language Paradigms © R. Mak 27

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 27 CS 152: Programming Language Paradigms © R. Mak 28

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') What does this FORTRAN IV program do? 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 27 END CS 152: Programming Language Paradigms © R. Mak Demo 29

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 27 CS 152: Programming Language Paradigms © R. Mak 30

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 27 CS 152: Programming Language Paradigms © R. Mak 31