Chapter OneProgramming Languages1. Chapter OneProgramming Languages2 Recommended Course Textbooks A. B. Webber (2002) Modern Programming Languages: A.

Slides:



Advertisements
Similar presentations
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Advertisements

Senem Kumova Metin Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Chapter 1: An Overview of Computers and Programming Languages J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program.
High-Level Programming Languages
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
The Evolution of Programming Languages
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. COMPSCI 125 Introduction to Computer Science I.
CSE S. Tanimoto Syntax and Types 1 Representation, Syntax, Paradigms, Types Representation Formal Syntax Paradigms Data Types Type Inference.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Summer 02-03Programming Language Concepts1 Programming Language Concepts (CS 360) Lecture 1: Overview, Grammars, and Little Languages Jeremy R. Johnson.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Introduction (Chapter 1)
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Dr. Muhammed Al-Mulhem ICS An Introduction to Functional Programming.
Programming Languages Chapter OneModern Programming Languages, 2nd ed.1.
CS102 Introduction to Computer Programming
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
High-Level Programming Languages: C++
G Programming Languages T he main themes of programming language design and use: –Model of computation –Expressiveness types and their operations.
1 TOPIC 1 INTRODUCTION TO COMPUTER SCIENCE AND PROGRAMMING Topic 1 Introduction to Computer Science and Programming Notes adapted from Introduction to.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
CS 363 Comparative Programming Languages
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Programming Languages –14 David Watt (Glasgow) Steven Wong (Singapore) Moodle : Computing Science → Level 3 → Programming Languages 3 © 2012 David.
Chapter 1 - Introduction
1 Functional Programming In Text: Chapter Chapter 2: Evolution of the Major Programming Languages Outline Functional programming (FP) basics A bit.
1 Concepts of Programming Languages TK 327, Fall 2015 MW 2:00 PM – 3:15 PM STV 104 Instructor:Dr. Chung-Chih Li Home page of the Class.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Overview.  Explores the theoretical foundations of computing  What can and cannot be done by an algorithm  Most of the material predates computers!
Chapter 8 High-Level Programming Languages. 2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
1-1 An Introduction to Functional Programming Sept
ISBN Structure of Programming Languages Prof. Dr. Mostafa Abdel Aziem Mostafa Senior Lecturer
1 The Evolution of Major Programming Languages Different Languages Characteristics.
CPS120: Introduction to Computer Science Variables and Constants.
1-1 1 Introduction  Programming linguistics: concepts and paradigms syntax, semantics, and pragmatics language processors.  Historical development of.
Chapter 1 An Overview of Computers and Programming Languages.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Victoria Ibarra Mat:  Generally, Computer hardware is divided into four main functional areas. These are:  Input devices Input devices  Output.
Programming Languages Chapter OneModern Programming Languages 1.
Programming Languages 2nd edition Tucker and Noonan
Functional Programming
Java Programming: From the Ground Up
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
Chapter 1: An Overview of Computers and Programming Languages
PROGRAMMING LANGUAGES
Programming Languages
课程名 编译原理 Compiling Techniques
C++ Programming: From Problem Analysis to Program Design
User-Defined Functions
Chap. 6 :: Control Flow Michael L. Scott.
Representation, Syntax, Paradigms, Types
Chap. 6 :: Control Flow Michael L. Scott.
Programming Languages 2nd edition Tucker and Noonan
High Level Programming Languages
Low Level Programming Languages
Von Neumann Architecture
Principles of Programming Languages
Presentation transcript:

Chapter OneProgramming Languages1

Chapter OneProgramming Languages2 Recommended Course Textbooks A. B. Webber (2002) Modern Programming Languages: A Practical Introduction, Franklin Beedle & Associates, 572 p. D. A. Watt (2004) Programming Language Design Concepts, John Wiley & Sons, 492 p. F. A. Turbak, D. K. Gifford (2008) Design Concepts in Programming Languages, MIT Press, 1200 p. S. Thompson (1999) The Craft Of Functional Programming, Addison Wesley, 528 p. D. P. Friedman, M. Wand (2008) Essentials Of Programming Languages, 3 rd Edition, MIT Press, 416 p.

Chapter OneProgramming Languages3 Programming Languages Overview Purpose:  Discover language design successes and failures.  Discover how languages are designed and implemented. Several real languages will be programmed but:  Course is not intended to teach programming  Experience the key programming language elements that are common to or distinguish two classes of languages.  Assume you can already program in at least one object oriented language that uses C++ style syntax.  Java used as a recent object oriented, threaded and networking language.  Haskell used as a very high-level language mainly for studying and implementing interpretive language.

Chapter OneProgramming Languages4 Programming Languages Overview Computer systems have come to effective use with programs consisting of a well-ordered and finite set of non-ambiguous and computable operations. A program written in a natural language (English, German, Turkish) can’t be executed from a computer:  we need a formal language. It must be a language provided with a set of rules in order to avoid any possible ambiguity. Programming languages is basically developed to utilize the capabilities of a computer system. A programming language is the problem solving tool of computer science used for human expression of computer solutions.  Ideas are expressed in a language.

Chapter OneProgramming Languages5 Programming Languages Overview The Sapir-Whorf linguistic theory states that the structure of language defines the boundaries of thought.  New ideas often require new language, for example algebra. A given language can impede or facilitate certain modes of thought. All programming languages are capable of solving any computable problem – computer languages are equivalent.  No programming language can prevent a problem solution.  A given language can subtlety influence the class of solutions examined and the quality of a program.

Chapter OneProgramming Languages6 Some of the Problems Hardware simulator to interpret machine language (Java). Defining language syntax and parsing (XML). Interpreter for high-level language (Hugs). Light-weight threads (Java) Networking (Java) Object-oriented programming (Java) Components (Java)

Chapter OneProgramming Languages7 The von Neumann architecture The main problem of the early computers was the difference in the implementation of data and programs (external connections, wires...) In 1950 J. von Neumann, defined the first computer with memorized program: the EDVAC. It weighted 8 tons and had a memory of 1024 words but it was not so different from our modern PC… Interpretation of the instructions, guide of the execution, coordination of the other hardware components Storage of data (input/intermediate/ output) and programs Arithmetical and logical operations

Chapter OneProgramming Languages8 The EDVAC Electronic Discrete Variable Automatic Computer, which has the following features 6,000 vacuum tubes 12,000 diodes 56 kW of power consumption 45 m 2 of floor space 8 tons of weigh

Chapter OneProgramming Languages9 The modern personal computers They basically follow the scheme given by von Neumann: they are only much more powerful in computation and storage capabilities 1) Not only the central memory (RAM) but also the hard disk (permanent data storage) 2) Several input devices: keyboard, mouse, CD, DVD, scanner, microphone, camera, joystick… 3) Several output devices: screen, printer, speakers, plotter…

Chapter OneProgramming Languages10 Chapter Outline What makes programming languages an worthwhile subject of study? oThe amazing variety oThe odd controversies oThe intriguing evolution oThe connection to programming practice oThe many other connections

Chapter OneProgramming Languages11 The Amazing Variety There are very many, very different languages A list of computer languages (~2500) is provided on  m Hello world programs for many languages:  Often grouped into four families:  Imperative  Functional  Logic  Object-oriented

Chapter OneProgramming Languages12 A Sample Language List

Chapter OneProgramming Languages13 Imperative Languages Example: a factorial function in C Hallmarks of imperative languages:  Assignment and side-effects  Iteration  Order of execution is critical int fact(int n) { int sofar = 1; while (n>0) sofar *= n--; return sofar; }

Chapter OneProgramming Languages14 Functional Languages Example: a factorial function in Haskell Hallmarks of functional languages:  Single-valued variables  Heavy use of recursion  Functions are first-class citizens, can be used as parameters, function results, etc.  Minimal use of assignments and side-effects fact x = if x <= 0 then 1 else x * fact(x-1);

Chapter OneProgramming Languages15 Another Functional Language Example: a factorial function in Lisp Looks very different from Haskell  Fully-parenthesized, prefix syntax But Haskell and Lisp are closely related  Single-valued variables: no assignment  Heavy use of recursion: no iteration (defun fact (x) (if (<= x 0) 1 (* x (fact (- x 1)))))

Chapter OneProgramming Languages16 Logic Languages Example: a factorial function in Prolog Hallmark of logic languages  Program expressed as rules in formal logic  Execution attempts to prove a result based upon rules fact(X,1) :- X =:= 1. fact(X,Fact) :- X > 1, NewX is X - 1, fact(NewX,NF), Fact is X * NF.

Chapter OneProgramming Languages17 Object-Oriented Languages Example: a Java definition for a kind of object that can store an integer and compute its factorial Hallmarks of object-oriented languages:  Usually imperative, plus…  Constructs to help programmers use “objects”—little bundles of data that know how to do things to themselves

Chapter OneProgramming Languages18 public class MyInt { private int value; public MyInt(int value) { this.value = value; } public int getValue() { return value; } public MyInt getFact() { return new MyInt(fact(value)); } private int fact(int n) { if (n <= 0) return 1; else return n * fact(n-1); } }

Chapter OneProgramming Languages19 Strengths and Weaknesses The different language groups show to advantage on different kinds of problems Decide for yourself at the end of the semester, after experimenting with them For now, one comment: don’t jump to conclusions based on factorial!  Functional languages do well on such functions  Imperative languages, a bit less well  Logic languages, considerably less well  Object-oriented languages need larger examples

Chapter OneProgramming Languages20 About Those Families There are many other language family terms (not exhaustive and sometimes overlapping)  Applicative, concurrent, constraint, declarative, definitional, procedural, scripting, single- assignment, … Some languages straddle families Others are so unique that assigning them to a family is pointless

Chapter OneProgramming Languages21 Example: Forth Factorial A stack-oriented language Postscript language used by printers is similar Could be called imperative, but has little in common with most imperative languages : FACTORIAL 1 SWAP BEGIN ?DUP WHILE TUCK * SWAP 1- REPEAT ;

Chapter OneProgramming Languages22 Example: APL Factorial An APL expression that computes X’s factorial Expands X it into a vector of the integers 1..X, then multiplies them all together (You would not really do it that way in APL, since there is a predefined factorial operator: !X) Could be called functional, but has little in common with most functional languages    X   X

Chapter OneProgramming Languages23 Outline What makes programming languages an interesting subject?  The amazing variety  The odd controversies  The intriguing evolution  The connection to programming practice  The many other connections

Chapter OneProgramming Languages24 The Odd Controversies Programming languages are the subject of many heated debates:  Partisan arguments  Language standards  Fundamental definitions

Chapter OneProgramming Languages25 Language Partisans There is a lot of argument about the relative merits of different languages Every language has partisans, who praise it in extreme terms and defend it against all detractors To experience some of this, explore newsgroups: comp.lang.* (Plenty of rational discussion there too!)

Chapter OneProgramming Languages26 Language Standards The documents that define language standards are often drafted by international committees Can be a slow, complicated and rancorous process Fortran 82 8X standard released in 1991

Chapter OneProgramming Languages27 Basic Definitions Some terms refer to fuzzy concepts: all those language family names, for example No problem; just remember they are fuzzy  Bad: Is X really an object-oriented language?  Good: What aspects of X support an object-oriented style of programming? Some crisp concepts have conflicting terminology: one person’s argument is another person’s actual parameter

Chapter OneProgramming Languages28 Outline What makes programming languages an interesting subject?  The amazing variety  The odd controversies  The intriguing evolution  The connection to programming practice  The many other connections

Chapter OneProgramming Languages29 The Intriguing Evolution Programming languages are evolving rapidly  New languages are being invented  Old ones are developing new dialects

Chapter OneProgramming Languages30 New Languages A clean slate: no need to maintain compatibility with an existing body of code But never entirely new any more: always using ideas from earlier designs Some become widely used, others do not Whether widely used or not, they can serve as a source of ideas for the next generation

Chapter OneProgramming Languages31 Widely Used: Java Quick rise to popularity since 1995 release Java uses many ideas from C++, plus some from Mesa, Modula, and other languages C++ uses most of C and extends it with ideas from Simula 67, Ada, Clu, ML and Algol 68 C was derived from B, which was derived from BCPL, which was derived from CPL, which was derived from Algol 60

Chapter OneProgramming Languages32 Not Widely Used: Algol One of the earliest languages: Algol 58, Algol 60, Algol 68 Never widely used Introduced many ideas that were used in later languages, including  Block structure and scope  Recursive functions  Parameter passing by value

Chapter OneProgramming Languages33 Dialects Experience with languages reveals their design weaknesses and leads to new dialects New ideas pass into new dialects of old languages

Chapter OneProgramming Languages34 Some Dialects Of Fortran Original Fortran, IBM Major standards:  Fortran II  Fortran III  Fortran IV  Fortran 66  Fortran 77  Fortran 90  Fortran 95  Fortran 200x? n Deviations in each implementation n Parallel processing – HPF – Fortran M – Vienna Fortran n And many more…

Chapter OneProgramming Languages35 Outline What makes programming languages an interesting subject?  The amazing variety  The odd controversies  The intriguing evolution  The connection to programming practice  The many other connections

Chapter OneProgramming Languages36 The Connection To Programming Practice Languages influence programming practice  A language favors a particular programming style—a particular approach to algorithmic problem-solving Programming experience influences language design

Chapter OneProgramming Languages37 Language Influences Programming Practice Languages often strongly favor a particular style of programming  Object-oriented languages: a style making heavy use of objects  Functional languages: a style using many small side-effect-free functions  Logic languages: a style using searches in a logically-defined problem space

Chapter OneProgramming Languages38 Fighting the Language Languages favor a particular style, but do not force the programmer to follow it It is always possible to write in a style not favored by the language It is not usually a good idea…  C++ is not good for logic programming.  Prolog is not good for systems programming.

Chapter OneProgramming Languages39 Imperative Haskell fact n = foldl (*) 1 [1..n] OR fact n = foldl (\t m->t*m) 1 [1..n] Haskell makes it impossible to use assignment and side- effects. However some Haskell code seems imperative:

Chapter OneProgramming Languages40 Non-object-oriented Java Java, more than C++, tries to encourage you to adopt an object-oriented mode. But you can still put your whole program into static methods of a single class: class Fubar { public static void main (String[] args) { // whole program here! }

Chapter OneProgramming Languages41 Functional Pascal function ForLoop(Low, High: Integer): Boolean; begin if Low <= High then begin {for-loop body here} ForLoop := ForLoop(Low+1, High) end else ForLoop := True end; Any imperative language that supports recursion can be used as a functional language:

Chapter OneProgramming Languages42 Programming Experience Influences Language Design Corrections to design problems make future dialects, as already noted Programming styles can emerge before there is a language that supports them  Programming with objects predates object- oriented languages  Automated theorem proving predates logic languages

Chapter OneProgramming Languages43 Obfuscatable Languages Obfuscated code is source code that is very hard to read and understand, often intentionally. Some languages are more prone to obfuscation than others. Sample obfuscatable languages  C, C++, Perl, … There are programming contests which reward the most creatively obfuscated code  International Obfuscated C Code Contest  Obfuscated Perl Contest

Chapter OneProgramming Languages44 Sample C Code (1) _(__,___,____){___/__ 1&&___%__<___/__?_(__,1+___,____+!(___/__%(___%__))):___<__*_ _?_(__,___+1,____):0;}main(){_(100,0,0);} The above code prints out the prime numbers less than 100, which is equivalent to: f (a,b,c) { b/a<=1 ? f(a,b+1,c) : !(b%a) ? f(a,b+1,0) : b%a==b/a && !c ? (printf("%d\t",b/a),f(a,b+1,0)) : b%a>1 && b%a<b/a ? f(a,1+b,c+!(b/a%(b%a))) : b<a*a ? f(a,b+1,c) : 0; } main() { f (100, 0, 0); } Output:

Chapter OneProgramming Languages45 Another C Code (2) main(l,a,n,d)char**a;{ for(d=atoi(a[1])/10*80- CLCCGZAAQBEAADAFaISADJABBA^\ SNLGAQABDAXIMBAACTBATAHDBAN\ ZcEMMCCCCAAhEIJFAEAAABAfHJE\ TBdFLDAANEfDNBPHdBcBBBEA_AL\ H E L L O, W O R L D! " [l++-3];)for(;n-->64;) putchar(!d+++33^ l&1);}

Chapter OneProgramming Languages46 Another C Code (2) if the program is compiled from map.c into map Output: map !!!!!!!!!!! !!! !!! !!!!!!! ! !!!!!!!!!!!!!!!!! !!!!! ! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!! !!!! ! !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!! !!!!!!! !!!!!!!!!!!!!!!!! !! ! !!!!!!!!! !! ! !!"!!!!!!!!!!!!!!!!! ! ! !!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!! !!!!!!!!!!!!! !!! !!! ! !!!!! !!!!!!!!!! ! ! ! ! !!!!!!!! !!!!! !! !!!!!! !!!! ! !!!!! !!!! !! !!!!!!!! !! !! !! ! !

Chapter OneProgramming Languages47 Outline What makes programming languages an interesting subject?  The amazing variety  The odd controversies  The intriguing evolution  The connection to programming practice  The many other connections

Chapter OneProgramming Languages48 Other Connections: Computer Architecture Language evolution drives and is driven by hardware evolution:  Call-stack support – languages with recursion  Parallel architectures – parallel languages  Internet – Java

Chapter OneProgramming Languages49 Other Connections: Theory of Formal Languages Theory of formal languages is a core mathematical area of computer science  Regular grammars, finite-state automata – lexical structure of programming languages, scanner in a compiler  Context-free grammars, pushdown automata – phrase- level structure of programming languages, parser in a compiler  Turing machines – Turing-equivalence of programming languages

Chapter OneProgramming Languages50 Turing Equivalence Languages have different strengths, but fundamentally they all have the same power  {problems solvable in Java} = {problems solvable in Fortran} = … And all have the same power as various mathematical models of computation  = {problems solvable by Turing machine} = {problems solvable by lambda calculus} = … Church-Turing thesis: this is what “computability” means

Chapter OneProgramming Languages51 Conclusion Why programming languages are worth studying (and this course worth taking):  The amazing variety  The odd controversies  The intriguing evolution  The connection to programming practice  The many other connections Plus…there is the fun of learning a new language!