Chapter 1. Preliminaries. Topics. Languages. What is a Programming Language? I already know a Programming Language

Similar documents
Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

CSE 130 Programming Language Principles & Paradigms

CSC Software II: Principles of Programming Languages

Lecture 1: Introduction

What is a programming language?

CSE 307: Principles of Programming Languages

1/20/2016 INTRODUCTION

Chapter 5 Names, Bindings, Type Checking, and Scopes

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

COS 301 Programming Languages

CSCI 3136 Principles of Programming Languages

Programming Languages

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science

1.1 WHAT IS A PROGRAMMING LANGUAGE?

Chapter 13 Computer Programs and Programming Languages. Discovering Computers Your Interactive Guide to the Digital World

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation

Chapter 15 Functional Programming Languages

Programming Languages

McGraw-Hill The McGraw-Hill Companies, Inc.,

Semester Review. CSC 301, Fall 2015

Chapter 13: Program Development and Programming Languages

Evolution of the Major Programming Languages

Image credits:

On the (un)suitability of Java to be the first programming language

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

The C Programming Language course syllabus associate level

[Refer Slide Time: 05:10]

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

THE ROLE OF PROGRAMMING PARADIGMS IN THE FIRST PROGRAMMING COURSES. 1. Introduction

Programming Languages & Tools

Introduction to Python

Fall 2012 Q530. Programming for Cognitive Science

Characteristics of Java (Optional) Y. Daniel Liang Supplement for Introduction to Java Programming

Programming Language Pragmatics

Chapter 12 Programming Concepts and Languages

Chapter 6: Programming Languages

Parameter passing in LISP

Introduction to Software Paradigms & Procedural Programming Paradigm

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

White Paper: 5GL RAD Development

Functional Programming

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Chapter 13: Program Development and Programming Languages

Fundamentals of Programming Languages

Asogwa Tochukwu Chijindu Department of Computer Engineering, Enugu State University of Science and Technology(ESUT), Enugu, Nigeria.

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

Sources: On the Web: Slides will be available on:

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

COURSE CODE: CSC 411 Organization of Programming Languages

Programming and Software Development CTAG Alignments

Moving from CS 61A Scheme to CS 61B Java

Semantic Analysis: Types and Type Checking

KS3 Computing Group 1 Programme of Study hours per week

1. Overview of the Java Language

Fourth generation techniques (4GT)

Software: Systems and. Application Software. Software and Hardware. Types of Software. Software can represent 75% or more of the total cost of an IS.

Algorithms, Flowcharts & Program Design. ComPro

Instruction Set Architecture (ISA)

Cobol. By: Steven Conner. COBOL, COmmon Business Oriented Language, one of the. oldest programming languages, was designed in the last six

Levels of Programming Languages. Gerald Penn CSC 324

History OOP languages Year Language 1967 Simula Smalltalk

Quotes from Object-Oriented Software Construction

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Computer Programming I

Lab Experience 17. Programming Language Translation

Java Application Developer Certificate Program Competencies

CS 40 Computing for the Web

ATSBA: Advanced Technologies Supporting Business Areas. Programming with Java. 1 Overview and Introduction

COMPUTER SCIENCE (5651) Test at a Glance

Computer Programming. Course Details An Introduction to Computational Tools. Prof. Mauro Gaspari:

How To Teach Object Oriented Programming At An Introductory Level Course

Software Paradigms (Lesson 1) Introduction & Procedural Programming Paradigm

How To Understand Programming Languages And Programming Languages

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

#820 Computer Programming 1A

Concepts of Programming Languages: A Unified Approach. Karl Abrahamson

Software Engineering Techniques

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014!

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

COWLEY COLLEGE & Area Vocational Technical School

Time Limit: X Flags: -std=gnu99 -w -O2 -fomitframe-pointer. Time Limit: X. Flags: -std=c++0x -w -O2 -fomit-frame-pointer - lm

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Programming language concepts

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

Course Goal CMSC 330: Organization of Programming Languages. Studying Programming Languages. All Languages Are (Kind of) Equivalent.

An Introduction to Computer Science and Computer Organization Comp 150 Fall 2008

Transcription:

Topics hapter 1 Preliminaries Motivation Programming Domains Language Evaluation riteria Language Design Trade-Offs Influences on Language Design Language ategories Implementation Methods 2 Languages The purpose of language is communication Natural languages Programming languages Writing an English essay: Many can write in English Few write well What is a Programming Language? What is a language? A set of rules that enables communication of ideas between people (between people and machines). What is a program? A set of instructions intended for machine execution. What is a programming language? A set of rules that define a set of legal programs. 3 4 I already know a Programming Language What is the best Programming Language? Why do I need to learn the concepts of programming languages? I already know the latest/greatest/coolest programming language. I can solve any problem using the programming language that I already know. Java ++ Perl Python Visual Basic Lisp Pascal Prolog ML Modula-2 Fortran obol Smalltalk Haskell Algol 5 6 1

No clear winner Obviously there is no best language for all situations. Type of program Time available ost Size and scope of program Programmer familiarity Real computer programmers do not get religious about their languages, they get pragmatic and understand the trade-offs in their language choices. 1. Improves ability to express ideas Languages influence the way you think and approach problems. As you study new language features it may help you utilize or extend your own language skills. Limit kinds of control structure Limit of constructed algorithms New features can be later simulated in other language. 7 8 2. Improves background for choosing appropriate languages Helps you understand the trade-offs in languages. Provides alternatives choices that suits the project s scope. Trade-offs in languages Informed language decision 3. Increases ability to learn new languages There is significant similarity in the constructs provided by languages so that learning a language is often just a matter of syntax. Loops (while, for, do) Selection (if, case) Data types (int, char, string, object) Jumps (goto, break, continue) Data abstraction concept Abstract data type (Java) 9 10 4. Allows a better understanding of the significance of implementation Why the languages are design the way they are. Understand design s purpose Ability to use a language more intelligently 5. Increases ability to design new languages 6. Overall advancement of computing Is the most popular programming language the best choice? Why a language is the most popular? Recursion vs. Iteration (faster) 11 12 2

What impacts Programming Language Design? What impacts Programming Language Design? Application domain Evaluation riteria Application domain Evaluation riteria The set of applications (algorithms) that we want to implement using our programming language omputer architecture omputer architecture Programming methodologies Programming methodologies 13 14 Programming Domains Programming Domains Scientific Focus on calculations Simple data structures Large numbers of floating-point arithmetic computations Primary concern: efficiency Languages: Fortran, Algol 60 Business Focus on reports and calculations Facilitates the production of reports Have precise ways of describing and storing decimal numbers and character data Specifies decimal arithmetic operations Language: obol 15 16 Programming Domains Programming Domains Artificial Intelligence Use symbolic rather than numeric computations. Focus on string and list manipulation Languages: Lisp family (ommon Lisp, Scheme, ML), Prolog. Systems Programming Focus on fast execution Need efficiency because of continuous use Low-level features Languages: PL/S (IBM), Extended Algol, Scripting Languages Putting a list of commands (script) in a file to be executed. Little code Generally domain specific Usually interpreted Languages: shand ksh (for shell), awk (report-generation), tcland tk (X Windows), Perl (GI programming), JavaScript, PHP 17 18 3

What impacts Programming Language Design? Application domain Evaluation riteria omputer architecture Programming methodologies The set of factors that are important to the users of the programming language Project Manager s Dilemma Which language shall we use in the next project? To come to a decision one needs arguments in favor or against a language. There are 4 main criteria: Readability Writability ost Are there other factors? 19 20 Language Evaluation riteria Language Evaluation riteria Readability The ease with which programs can be read and understood. Writability The ease with which a language can be used to create programs. Reliable performance (according to specifications) under all conditions. haracteristics Simplicity / orthogonality ontrol structure Data type and structures Syntax design Support for abstraction Expressivity Type checking Exception handling Restricted aliasing Readability riteria Writability 21 22 Evaluation riteria: Readability Readability describes the ease of which programs can be read and understood. This is the most important criterion. It significantly affects the maintainability of code (mayor cost for programs). It must be considered in the context of problem domain. Evaluation riteria: Readability Overall simplicity Too many features is bad Multiplicity of features is bad. Operator overloading makes confusion. count = count+1 count += 1 count++ ++count Features Domain Prog. 1 Prog. 2 8 + 4 8.3 + 4.9 test + it [1,3,4] + [5,6,1] = [6,9,5] or [1,3,4,5,6,1] or 20? 23 Too simple can be just as much trouble (machine languages just 0 and 1) 24 4

Evaluation riteria: Readability Orthogonality A small number of primitive constructs combined in a relative small number of ways and everything can be combined with anything else. Every possible combination is legal. Meaning is context independent Pointer is able to point to any type of variable. Makes the language easy to learn and read. Lack of orthogonality leads to exceptions to rules. 25 Evaluation riteria: Readability ontrol statements Program easier to read from top to bottom. while( ( incr < 20) { Unstructured: GOTO while (sum <= 100) { sum += incr; Structured: loop incr++; Data type and structures Not enough structures leads to workarounds which can reduce clarity. Boolean type (vs. 0 and 1) Record (vs. Arrays) loop 1: if ( incr >=20) go to out; loop 2: if (sum > 100) go to next; go to loop2; next: incr++; go to loop 1; out: ADA 26 Evaluation riteria: Readability Syntax considerations Identifier length and form Too short equals bad variable names. Special words Block structure end vs. end-if and end-loop Special words Form and meaning for (i=1; i<10; i++) { for I in 1..10 loop if (a) if a then { end if; end loop; Semantics should follows directly from syntax. Evaluation riteria: Writability Writability describes the ease with which a language can be used to create programs for a given domain. Be careful not to compare things which should not be. Most of the features that affect readability affects also writability. 27 28 Evaluation riteria: Writability Simplicity and Orthogonality Lack of familiarity with some features leads to misuse and disuse of those features. Misuse could cause bizarre results. Too much orthogonality may produce undetected errors. Any combination of primitive is legal. score = 15 / 3 * 5; Evaluation riteria: Writability Support for abstraction Ability to define and use complicated structures or operations ignoring all the details. Important for modular programming. Two forms of abstraction Process: subprograms e.g. using a subprogram to implement a search or sort algorithm. Data: data types e.g. trees, arrays, etc. 29 30 5

Evaluation riteria: Writability Expressivity Aids writability by make it convenient and easy to specify things. e.g. count++ vs. count = count + 1 Evaluation riteria: Reliable programs work (according to specifications) under all conditions. Type checking Earlier error detection is less expensive to repair ompile-time checking is preferred. Exception handling The ability of a program to intercept run-time errors, take corrective measures, and then continue (e.g. ++, Java, Ada). 31 32 Evaluation riteria: Aliasing Having to or more distinct referencing methods, or names, for the same memory cell. e.g. using pointer in ++, reference in Java Readability and Writability The easiest a program is to write, the more likely it is to be correct. Programs that are difficult to read are difficult to both to write and modify. 33 Evaluation riteria: ost ost of learning/teaching a language (programmer training) ost of writing/developing a program (software creation) ost of compiling the program (fast) ost of running the program (fast) ost of the compiler (for free e.g. Java) ost of poor reliability ost of maintaining the program (corrections and modifications to add new capabilities) 34 Evaluation riteria: Other Portability The ease with which programs can be moved from one implementation to another. Generality The applicability to a wide range of applications. Well-definedness The completeness and precision of a language s official defining document. Language Design Trade-Offs There are so many important but conflicting criteria, that their reconciliation and satisfaction is a major engineering task. ( Tony Hoare 1973) Expressivity Writability vs. ost (execution) vs. Readability vs. Readability vs. Writability(flexibility) 35 36 6

Language Design Trade-Offs Most criteria cannot be defined nor measured precisely. The way a language is evaluated is heavily influenced by the point of view and background of the evaluator. Language designer Language implementor Language user A real designer understands trade-offs and make decisions rather than skirt them. What impacts Programming Language Design? Application domain Evaluation riteria omputer architecture Programming methodologies The programming language should map well to the hardware (computer architecture) 37 38 omputer Architecture Influence The von Neumann Architecture Imperative languages have been designed around the von Neumann architecture Data and programs are stored in memory entral processing unit (PU) executed the instructions PU and memory are separated Instructions/data must be transmitted from memory to PU Results from operations are transmitted back to memory Imperative languages map well to this architecture Variables are memory locations Assignments move data back and forth between PU and memory Iteration for repetition 39 40 What impacts Programming Language Design? Application domain Evaluation riteria omputer architecture Programming methodologies Programming languages respond to different ways of thinking about programs Programming Methodologies Influence People s needs affect the design of programming languages and paradigms. 1950 s and early 1960 s Worry about machine efficiency Simple applications Late 1960 s Worry about people efficiency Better control structures and improved readability Structured programming Top-down design and step-wise refinement 41 42 7

Programming Methodologies Influence Programming Paradigms Mid-late 1970 s Worry about reuse and maintenance Shift from process-oriented to data-oriented Data abstraction Paradigms are programming styles (a special way to express an idea or algorithm) that embody programming design technology 1980 s Rising complexity and costs Introduction of object-oriented programming Data abstraction + inheritance + polymorphism 1990 s The Internet Data + network issues + interoperability Imperative Procedural Fortran With blocks Algol Pascal OO ++ Eiffel Java Objects Smalltalk Parallel Occam AML Java Declarative Logical Prolog Functional Haskell ML Lisp Scheme Database SQL 43 44 Programming Paradigms: Imperative entral features are variables, assignment statements, and iterative form of repetition. Specific order of execution of the instruction Program = order series of steps Separation of data and algorithm, Pascal, obol, Fortran Example Programming Paradigms: Object- Oriented losely related to imperative Program = a set of definitions (data and code that operates on the data encapsulated together) Objects interact with each other by passing messages back and forth Other features: inheritance, dynamic binding Java, ++, Python, Smalltalk, Eiffel Example 45 46 Programming Paradigms: Functional entral features are functions (applied to given parameters) Program = a set of mathematical functions each with an input (domain) and an output (range) No assignments, tons of recursion, and less focus on order Lazy evaluation: postpone operand evaluation until operation. Lisp, Scheme, Haskell, ML Example 47 Programming Paradigms: Logic What vs. How Rule-based language Rules are specified in no particular order Program = collection of logical declarations that describe the problem to be solved An inference engine then finds the solution It is also called declarative Declare or make assertions No sequence Prolog Example 48 8

Programming Example Greatest ommon Denominator (gcd) Programming Paradigms: omparison Scheme Java Advantage Disadvantage intgcd( intx, inty ) { int remainder; do { remainder = a%b; if (remainder!= 0) { a = b; b = remainder; while (remainder); return b; (define ( gcd u v) (if (= v 0) u (gcd v (modulo u v)))) Prolog gcd( U, V, U ) :- V=0 gcd( U, V, X ) :- not( V=0 ) Y is U mod V, gcd( V, Y, X ) public class IntGcd { private intvalue; public intintgcd( intval ) { value = val; public intgetvalue() { return value; public intgcd( intv ) { intz = value; inty = v; while ( y!= 0 ) { int t = y; y = z%y; z = t; return z; Imperative Functional Object-oriented Running cost ompilation cost Writability (asbtract) Readability Verification Maintenance cost Abstraction Readability Running cost ompilation cost Learning cost ompilation cost Running cost 49 50 Language Implementation ompilation There are three possible approaches to translating human readable code to machine code 1. ompilation 2. Interpretation 3. Hybrid Translate high-level program to machine code Slow translation Fast execution Optimization (improve program by making it smaller or faster) Slow for development Difficult dealing with runtime errors 51 52 Interpretation Hybrid No translation Easier implementation Slower execution Often requires more space Easy run-time error handling Becoming rare on high-level languages Significant comeback with some Web scripting languages (e.g. JavaScript) A compromise between compilers and pure interpreters Faster than pure interpretation (medium execution speed) A high-level language program is translated to an intermediate language that allows easy interpretation (small translation cost) 53 54 9

Language Implementation: omparison Summary Speed (runtime) Memory needed Portability ompiler ++ simple instructions ++ - reusable backend -- no checks Interpreter -- complex statements -- source, symbol table -- ++ additional checks Hybrid - - ++ intermediate language ++ additional checks Increase our capacity to use different constructs Enables us to choose languages more intelligently Makes learning new languages easier Most important criteria for evaluating PLs Readability, writability, reliability, and cost Major influences on language design Machine architecture and software development methodologies Major methods of implementing languages ompilation, pure interpretation, and hybrid implementation 55 56 10