Presentation is loading. Please wait.

Presentation is loading. Please wait.

Overview. Copyright © 2006 The McGraw-Hill Companies, Inc. Chapter 1 Overview A good programming language is a conceptual universe for thinking about.

Similar presentations


Presentation on theme: "Overview. Copyright © 2006 The McGraw-Hill Companies, Inc. Chapter 1 Overview A good programming language is a conceptual universe for thinking about."— Presentation transcript:

1 Overview

2 Copyright © 2006 The McGraw-Hill Companies, Inc. Chapter 1 Overview A good programming language is a conceptual universe for thinking about programming. A. Perlis

3 Copyright © 2006 The McGraw-Hill Companies, Inc. 1.1 Principles 1.2 Paradigms 1.3 Special Topics 1.4 A Brief History 1.5 On Language Design 1.5.1 Design Constraints 1.5.2 Outcomes and Goals 1.6 Compilers, Interpreters, and Virtual Machines

4 Copyright © 2006 The McGraw-Hill Companies, Inc.  Programming languages have several properties, including ◦ Syntax ◦ Names & types ◦ Semantics  Language designers define these properties  Language users must understand them

5 Copyright © 2006 The McGraw-Hill Companies, Inc.  Syntax describes ◦ Legal statements ◦ Legal programs  Syntax defines the form of a correct program – doesn’t say anything about program meaning  Who needs to know PL syntax? ◦ Programmers: how to write a correct program ◦ Translators: how to recognize a correct program

6 Copyright © 2006 The McGraw-Hill Companies, Inc.  Various kinds of entities in a program have names: variables, functions, parameters, classes, objects, …  Named entities are bound in a running program to: ◦ Scope ◦ Visibility ◦ Type ◦ Lifetime

7 Copyright © 2006 The McGraw-Hill Companies, Inc. A type is a collection of values and a collection of operations on those values. ◦ Simple types: numbers, characters, booleans, … ◦ Structured types: Strings, lists, arrays, hash tables, … A language’s type system ◦ Defines legal operations ◦ Defines type errors

8 Copyright © 2006 The McGraw-Hill Companies, Inc. A program’s meaning is defined by its semantics. In studying semantics, we ask questions like: ◦ When a program is running, what happens to the values of the variables? ◦ What does each statement mean? ◦ What underlying model governs the run-time behavior of a function call? ◦ …

9 Copyright © 2006 The McGraw-Hill Companies, Inc.  A programming paradigm is a pattern or framework for problem-solving  Languages typically identify primarily with one paradigm, but may have aspects of several  Common paradigms can be grouped together according to whether they have imperative characteristics or declarative characteristics.

10 Copyright © 2006 The McGraw-Hill Companies, Inc.  Imperative languages: ◦ Pure Imperative (von Neumann languages); e.g., C, Pascal, early versions of Fortran & Ada, … ◦ Object-oriented; e.g., C++, Java, Smalltalk ◦ Most of what we’ll study focuses on these languages  Declarative languages ◦ Functional  Lisp, Scheme, ML, Haskell, … ◦ Logic  Prolog, SQL, …

11 Copyright © 2006 The McGraw-Hill Companies, Inc.  Follows the classic von Neumann-Eckert model of computation: ◦ Program and data are indistinguishable in memory ◦ Program = a sequence of commands ◦ Programs work by changing values of memory variables  Large programs use procedural abstraction as a way to organize individual imperative statements.

12 Copyright © 2006 The McGraw-Hill Companies, Inc.

13  OO languages share many characteristics with the pure imperative languages  Programs consist of a collection of objects that communicate via “messages” that modify object state ◦ Messages are imperative  OO languages are characterized by ◦ Encapsulation ◦ Inheritance ◦ Polymorphism

14 Copyright © 2006 The McGraw-Hill Companies, Inc. Functional programming models a computation as a function that maps inputs to outputs. ◦ Input = domain ◦ Output = range Functional languages are characterized by: ◦ Functional composition ◦ Recursion Example functional languages: ◦ Lisp, Scheme, ML, Haskell, …

15 Copyright © 2006 The McGraw-Hill Companies, Inc. Logic programming declares what outcome the program should accomplish, rather than how it should be accomplished. Based on predicate logic Rule-based When studying logic programming we see: ◦ Programs as sets of constraints on a problem ◦ Find values that satisfy all constraints Example logic programming languages: Prolog

16 Copyright © 2006 The McGraw-Hill Companies, Inc.  Event handling ◦ E.g., GUIs, home security systems, monitoring systems of various kinds  Concurrency ◦ e.g., Client-server programs, rendering (in computer graphics)  Correctness ◦ Can we prove that a program does what it is supposed to do under all circumstances?

17 Copyright © 2006 The McGraw-Hill Companies, Inc.  How and when did programming languages evolve?  What communities have developed and used them? ◦ Artificial Intelligence ◦ Computer Science Education ◦ Science and Engineering ◦ Information Systems ◦ Systems and Networks ◦ World Wide Web

18 Copyright © 2006 The McGraw-Hill Companies, Inc.

19 1.5.1 – Design Constraints ◦ Computer architecture ◦ Technical setting (domain of applications) ◦ Standards ◦ Legacy systems

20 Copyright © 2006 The McGraw-Hill Companies, Inc. Key characteristics: ◦ Simplicity, readability and writability ◦ Clarity about binding ◦ Reliability ◦ Support ◦ Abstraction ◦ Orthogonality ◦ Efficient implementation

21 Copyright © 2006 The McGraw-Hill Companies, Inc.  Early languages focused on efficiency ◦ Time ◦ Space  Today, programs that are easy to read and easy to write are most likely to be successful  Promoted by simplicity of the language.

22 Copyright © 2006 The McGraw-Hill Companies, Inc.  Easy to learn ◦ Don’t include too many features ◦ Don’t make it too complex  Simple conceptual model of semantics.  Uniformity: Similar syntax => similar semantics.  Lexical and syntactic conventions: ◦ descriptive identifier names, blocking of compound statements

23 Copyright © 2006 The McGraw-Hill Companies, Inc.  A language element is bound to a property at the time that property is defined for it.  So a binding is the association between an object and a property of that object; the binding time should be clearly understood.  Examples: ◦ variable and type: program writing time or execution time? ◦ variable and value: program writing time and execution time ◦ language operator to machine language instruction: ??

24 Copyright © 2006 The McGraw-Hill Companies, Inc.  Major binding times ◦ Language definition time ◦ Language implementation time ◦ Program writing time ◦ Compile time ◦ Load time ◦ Execution time  In general, ◦ Early binding takes place at or before compile-time ◦ Late binding takes place at load time or run time  Early v late: efficiency versus flexibility

25 Copyright © 2006 The McGraw-Hill Companies, Inc. A language is reliable if: ◦ Program behavior is the same on different platforms  E.g., early versions of Fortran weren’t ◦ Type errors are detected  E.g., C vs Haskell or ML ◦ Good exception-handling facilities  E.g., C vs Java ◦ Memory leaks are prevented  E.g., C/C++ vs Java

26 Copyright © 2006 The McGraw-Hill Companies, Inc.  Good texts and tutorials  Wide community of users  Integrated with development environments (IDEs)  Accessible compiler/interpreters (public domain)

27 Copyright © 2006 The McGraw-Hill Companies, Inc.  Data ◦ Programmer-defined types/classes ◦ Class libraries  Procedural ◦ Programmer-defined functions ◦ Standard function libraries  Supports code reuse; simplifies the programming process.

28 Copyright © 2006 The McGraw-Hill Companies, Inc.  A language is orthogonal if it is built on a small, mutually independent set of primitive operations. ◦ You can use one feature without worrying about how it affects others ◦ Rules don’t have exceptions; ◦ Context doesn’t affect the behavior of a language feature (e.g., a reserved word doesn’t have different meanings based on where it’s used). ◦ Things that are syntactically similar have similar meaning.

29 Copyright © 2006 The McGraw-Hill Companies, Inc.  Rule exceptions: ◦ C functions can return a struct, but not an array. Orthogonality => return value can be any type.  Syntactic exceptions ◦ In Fortran, an identifier can indicate the type of the variable; this could be considered non-orthogonal  If A = B; and A = (B); acceptable, should (A) = B; be allowed?

30 Copyright © 2006 The McGraw-Hill Companies, Inc.  Embedded systems ◦ Real-time responsiveness (e.g., navigation) ◦ Failures of early Ada implementations – real time?  Corporate database applications ◦ Efficient search and updating  Ability to implement the language efficiently ◦ Characteristics of Lisp didn’t match the architectures of early computers ◦ Characteristics of Algol made it difficult to build efficient translators.

31 Copyright © 2006 The McGraw-Hill Companies, Inc. Compiler – produces machine code Interpreter – executes instructions directly  Example compiled languages: ◦ Fortran, Cobol, C, C++  Example interpreted languages: ◦ Scheme, Haskell, Python  Hybrid compilation/interpretation: Java ◦ The Java Virtual Machine (JVM)  Just-in-time (JIT) compilation: C#, some Java ◦ Compiled to intermediate code, machine code produced just before execution

32 Copyright © 2006 The McGraw-Hill Companies, Inc. Translation/Execution – Compiler se

33 Copyright © 2006 The McGraw-Hill Companies, Inc.  Translate source code program into object code (machine language).  Object code is linked to libraries, other modules, to generate an executable object code module  Object code can be executed repeatedly without repeating the compilation process.

34 Copyright © 2006 The McGraw-Hill Companies, Inc. Translation/Execution – Interpreter

35 Copyright © 2006 The McGraw-Hill Companies, Inc.  No object code file generated.  Interpretive routines ◦ Examine the program. When an action is recognized, do it (by calling one of the routines).  Slower execution (than with compilation): lexical, syntax, type/semantic analysis must be performed every time it runs  Better interactive development environment.

36 Copyright © 2006 The McGraw-Hill Companies, Inc.  Some languages (e.g., Java) are compiled to a machine code (byte code) that runs on a virtual machine (the JVM).  To run Java programs install a JVM for your machine that interprets the byte code.  Benefit: “compile once, run anywhere” – as long as “anywhere” has a JVM. Compiled languages need to be compiled for a specific platform  Disdadvantage: slow  Solution: JIT compilers

37 Copyright © 2006 The McGraw-Hill Companies, Inc.  Programming language principles ◦ Grammars, syntax, semantics  What makes a language successful?  Reliable, readable, writeable  Supported by simplicity, orthogonality, efficiency, support, …  Paradigms ◦ Imperative, object-oriented, functional, logic  Language implementation ◦ Compilers & interpreters & hybrid systems


Download ppt "Overview. Copyright © 2006 The McGraw-Hill Companies, Inc. Chapter 1 Overview A good programming language is a conceptual universe for thinking about."

Similar presentations


Ads by Google