Organization of Programming Languages CSE 452 Instructor Dr

  • Slides: 27
Download presentation
Organization of Programming Languages (CSE 452) Instructor: Dr. B. Cheng Fall 2005 Organization of

Organization of Programming Languages (CSE 452) Instructor: Dr. B. Cheng Fall 2005 Organization of Programming Languages-Cheng (Fall 2005) 1

Why are there so many programming languages? u Evolution -- we've learned better ways

Why are there so many programming languages? u Evolution -- we've learned better ways of doing things over time u Socio-economic factors: u Proprietary interests, u Commercial advantage orientation toward special purposes u Orientation toward special hardware u Diverse ideas about what is pleasant to use Organization of Programming Languages-Cheng (Fall 2005) 2

What makes a language successful? u Ease of use: l Easy to learn (BASIC,

What makes a language successful? u Ease of use: l Easy to learn (BASIC, Pascal, LOGO, Scheme) l Easy to express things l Easy to use once fluent -- "powerful" (C++, Common Lisp, APL, Algol-68, perl) l Easy to implement (BASIC, Forth) possible to compile to very good (fast/small) code (For. Tran) u Cost factors: l Backing of a powerful sponsor (COBOL, PL/1, Ada, Visual Basic) l Wide dissemination at minimal cost (Pascal, Turing, Java) Organization of Programming Languages-Cheng (Fall 2005) 3

Why do we have programming languages? u Programmer’s l l l way of thinking

Why do we have programming languages? u Programmer’s l l l way of thinking way of expressing algorithms languages from the user's point of view u Abstraction l l perspective: of virtual machine way of specifying what you want the hardware to do without getting down into the bits languages from the implementor's point of view Course Objective: balance coverage of two angles. • Commonalities and differences among languages • Implementations of languages Organization of Programming Languages-Cheng (Fall 2005) 4

History of Programming Languages http: //www. webopedia. com/TERM/P/programming_language. html Organization of Programming Languages-Cheng (Fall

History of Programming Languages http: //www. webopedia. com/TERM/P/programming_language. html Organization of Programming Languages-Cheng (Fall 2005) 5

Detour into Dr. Cheng’s background u u u Freshman year at Northwestern Univ in

Detour into Dr. Cheng’s background u u u Freshman year at Northwestern Univ in 1981: l First programs written in Fortran IV l Typed programs onto punch cards l Computer used: CDC Cyber (size of 2 -3 fridges) l Terminal used: card punch machine End of first quarter, exposed to new language -Pascal Second quarter: computer organization class l Learned PDP-11 assembly language l Computer used: PDP-11 machine (size of 1 fridge) Organization of Programming Languages-Cheng (Fall 2005) 6

More of the detour u u Subsequent courses in undergrad mostly in Pascal (structured

More of the detour u u Subsequent courses in undergrad mostly in Pascal (structured programming, data abstractions, etc. ) AI course exposed to LISP. Graduate course taken as undergrad exposed to Prolog (as part of AI and theorem proving). Graduate school at UIUC (1985) l Exposed to Unix and C. l Shared office with Smalltalk research group. l C++ was just gaining popularity, along with OO Organization of Programming Languages-Cheng (Fall 2005) 7

End of Detour … Industry experience: l Boeing (Fortran and Pascal) (1982 -83) l

End of Detour … Industry experience: l Boeing (Fortran and Pascal) (1982 -83) l IBM (version of PL/I) (1984) l Data General (Pascal, C) (1985) l Digital ( C ) (1986) u Fast forward to start at MSU (1990): l First quarter taught Org. of Programming Languages: (C, LISP, Prolog, C++) l Java introduced in early 1990 s l Web takes off in mid 1990 s. l Mobile computing, cross platform computing, etc. l 2004 -05: multi-paradigm languages, heterogeneous platforms, “anytime, anywhere” Organization of Programming Languages-Cheng (Fallcomputing 2005) 8 u

Major Influences to Programming Languages u Computer Architecture l Von Neumann Architecture u Programming

Major Influences to Programming Languages u Computer Architecture l Von Neumann Architecture u Programming methodologies l Programming paradigms Organization of Programming Languages-Cheng (Fall 2005) 9

Von Neumann Architecture Organization of Programming Languages-Cheng (Fall 2005) 10

Von Neumann Architecture Organization of Programming Languages-Cheng (Fall 2005) 10

Influence of Computer Architecture Programming Language u Memory cells u Variables u Pipelined execution

Influence of Computer Architecture Programming Language u Memory cells u Variables u Pipelined execution of instructions u Computation is viewed as a sequence of actions Organization of Programming Languages-Cheng (Fall 2005) 11

Programming Paradigms Imperative Procedural (von Neumann) For. Tran, C, Basic, Pascal, Algol 60 Object-Oriented

Programming Paradigms Imperative Procedural (von Neumann) For. Tran, C, Basic, Pascal, Algol 60 Object-Oriented Declarative Functional Logical Simula 67, C++, Smalltalk, Java, C# LISP, Scheme, ML, Haskell Prolog, Visi. Calc, RPG, spreadsheets Organization of Programming Languages-Cheng (Fall 2005) 12

Desirable Qualities of Software must be reliable v Program performs to its specification under

Desirable Qualities of Software must be reliable v Program performs to its specification under all conditions Software must be maintainable v v It is no longer feasible to always build software from scratch Must be able to easily modify existing software Software must execute efficiently v Although hardware getting cheaper and has better performance, need for efficient execution remains due to increasingly demanding applications Organization of Programming Languages-Cheng (Fall 2005) 13

Why study programming languages? u Help you choose a language. l l l C

Why study programming languages? u Help you choose a language. l l l C v. Modula-3 v. C++ for systems programming Fortran v. APL v. Ada for numerical computations C v. Ada v. Modula-2 for embedded systems Common Lisp v. Scheme v. ML for symbolic data manipulation Java v. C/CORBA for networked PC programs Organization of Programming Languages-Cheng (Fall 2005) 14

Why study programming languages? u Make it easier to learn new languages (by analogy)

Why study programming languages? u Make it easier to learn new languages (by analogy) l some languages are similar; easy to walk down family tree (e. g. , For. Tran 77, For. Tran 90) l Identify common concepts : u E. g. : iteration, recursion, abstraction l Think of an analogy to human languages: u good grasp of grammar makes it easier to pick up new languages (at least romance languages). Organization of Programming Languages-Cheng (Fall 2005) 15

Make better use of language u. Understand obscure features: l In C, help you

Make better use of language u. Understand obscure features: l In C, help you understand unions, arrays & pointers, separate compilation, varargs, l In Common Lisp, help you understand first-class functions/closures, streams, catch and throw, symbol internals Organization of Programming Languages-Cheng (Fall 2005) 16

Make better use of language u Understand implementation costs: choose between alternative ways of

Make better use of language u Understand implementation costs: choose between alternative ways of doing things, based on knowledge of what will be done underneath: u Use simple arithmetic equalities (use x*x instead of x**2) u Use C pointers or Pascal "with" statement to factor address calculations – avoid call by value with large data items in Pascal – avoid the use of call by name in Algol 60 – choose between computation and table lookup Organization of Programming Languages-Cheng (Fall 2005) 17

Make better use of given language u Figure out how to do things in

Make better use of given language u Figure out how to do things in languages that don't support them explicitly: l Lack of suitable control structures in Fortran IV u l use comments and programmer discipline for control structures Lack of recursion in Fortran 77, CSP, etc. write a recursive algorithm then use mechanical recursion u elimination (even for things that aren't quite tail recursive) u lack of named constants and enumerations in Fortran u lack of modules in C and Pascal l u use variables that are initialized once, then never changed use comments and programmer discipline lack of iterators in just about everything l fake them with (member? ) functions Organization of Programming Languages-Cheng (Fall 2005) 18

Language Design Criteria u Simplicity Simpler language is easier to master l Achieved by

Language Design Criteria u Simplicity Simpler language is easier to master l Achieved by having a small number of features l Feature multiplicity: l u more than one way to accomplish the same task u E. g. : count++; count = count + 1; count += 1 l Operator overloading: u same operator has more than one meaning u Overload “+” operator for l l Summing integers in two arrays Concatenating two arrays Organization of Programming Languages-Cheng (Fall 2005) 19

Language Design Criteria u Orthogonality l Every possible combination of primitive constructs of the

Language Design Criteria u Orthogonality l Every possible combination of primitive constructs of the language is legal and meaningful l Lack of orthogonality means lots of exceptions in the language rules u Assembly language for IBM mainframe: A Reg 1, memory cell AR Reg 1, Reg 2 registers l Two different rules for addition Cannot use A for adding 2 Too much orthogonality makes language become overly complex (Algol 68) Organization of Programming Languages-Cheng (Fall 2005) 20

Language Design Criteria-Syntax u Identifier forms l Fortran 77 restricts identifiers to ≤ 6

Language Design Criteria-Syntax u Identifier forms l Fortran 77 restricts identifiers to ≤ 6 characters u Special words l Pascal requires begin-end pairs to form groups for all control constructs l Ada uses “end if” or “end loop” to distinguish closing syntax for each type of control statement l Fortran 90 allows special words such as DO and END to be legal variable names Organization of Programming Languages-Cheng (Fall 2005) 21

Language Design Criteria u Safety l Language should not provide features that make it

Language Design Criteria u Safety l Language should not provide features that make it possible to write harmful programs u l Type checking u l testing for type errors in a given program, during compilation or program execution Aliasing u u E. g. , goto statements and pointer variables Having two or more distinct referencing methods, or names, for the same memory cell (e. g. , union members, pointers in C) Robustness l Provides the ability to deal with undesired events (arithmetic overflows, invalid input, etc) u E. g. , Exception handling facility in Java and C++ Organization of Programming Languages-Cheng (Fall 2005) 22

Language Design Criteria l Portability: u Programs can be compiled and run on different

Language Design Criteria l Portability: u Programs can be compiled and run on different machines without rewriting the source code l Uniformity: u Similar notations should look and behave in the same way (e. g. , every “end” must be preceded by a matching “begin”) l Support for abstraction u Ability to define and then use complicated structures or operations in ways that allow many details to be ignored u Process abstraction vs Data abstraction Organization of Programming Languages-Cheng (Fall 2005) 23

Design Trade-offs u Reliability vs Efficiency l Ada demands all references to array to

Design Trade-offs u Reliability vs Efficiency l Ada demands all references to array to be checked to ensure that indices are within their legal ranges l C does not require index range checking, and thus executes faster Buffer overflow problem void function (char *str) { char buffer[16]; strcpy (buffer, str); } int main () { char *str = "I am greater than 16 bytes"; function (str); } Organization of Programming Languages-Cheng (Fall 2005) 24

Design Trade-offs u Flexibility vs Safety l Pascal variant records allow a memory cell

Design Trade-offs u Flexibility vs Safety l Pascal variant records allow a memory cell to contain either a pointer or an integer u. This allows a program to do arithmetic on pointers, which is sometimes convenient, but is a dangerous practice. Organization of Programming Languages-Cheng (Fall 2005) 25

Course Organization u u Lectures material supplement textbook material l (i. e. , come

Course Organization u u Lectures material supplement textbook material l (i. e. , come to class) Homework assignments reinforce key concepts Programming assignments give hands-on experience Exams provide a way for you to demonstrate what you’ve learned l (and I need something to use for calculating grades) Organization of Programming Languages-Cheng (Fall 2005) 26

Course Organization Homework 15% Programming Assignments 30% Exams (2) Exam 1: 10/18/05 Exam 2:

Course Organization Homework 15% Programming Assignments 30% Exams (2) Exam 1: 10/18/05 Exam 2: 12/13/05 50% In-class participation 5% Organization of Programming Languages-Cheng (Fall 2005) 27