Programming Languages Overview

download Programming Languages Overview

of 33

Transcript of Programming Languages Overview

  • 8/11/2019 Programming Languages Overview

    1/33

  • 8/11/2019 Programming Languages Overview

    2/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Contents

    1.1 Principles

    1.2 Paradigms

    1.3 Special Topics1.4 A Brief History

    1.5 On Language Design

    1.5.1 Design Constraints

    1.5.2 Outcomes and Goals

    1.6 Compilers and Virtual Machines

  • 8/11/2019 Programming Languages Overview

    3/33

  • 8/11/2019 Programming Languages Overview

    4/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Syntax

    The syntaxof a programming language is a precise

    description of all its grammatically correct programs.

    {what constitutes a structurally correct program}

    When studying syntax, we ask questions like:

    What is the grammar for the language?

    What is the basic vocabulary?

    How are syntax errors detected?

  • 8/11/2019 Programming Languages Overview

    5/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Syntax

    Context-free grammar: is a linguistic formalism that

    defines the syntactic structure of most modern

    programming languages.

  • 8/11/2019 Programming Languages Overview

    6/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Names

    Various kinds of entities in a program have names:

    variables, types, functions, parameters, classes, objects,

    Named entities are bound in a running program to:

    Scope

    Visibility

    Type

    Lifetime

  • 8/11/2019 Programming Languages Overview

    7/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Types

    A typeis a collection of values and a collection of

    operations on those values.

    Simple types

    numbers, characters, booleans,

    Structured types

    Strings, lists, trees, hash tables,

    A languages type systemcan help to:

    Determine legal operations

    Detect type errors

  • 8/11/2019 Programming Languages Overview

    8/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Semantics

    The meaning of a program is called itssemantics (and

    the effect of each statement at run time).

    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 run-time behavior, suchas function call?

    How are objects allocated to memory at run-time?

  • 8/11/2019 Programming Languages Overview

    9/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    A programmingparadigmis a pattern of problem-

    solving thought that underlies a particular genre of

    programs and languages.

    There are four main programming paradigms:

    Imperative

    Object-oriented

    Functional

    Logic (declarative)

    1.2 Paradigms

  • 8/11/2019 Programming Languages Overview

    10/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    There are four main programmingparadigms:

    Imperative

    Object-oriented

    Functional

    Logic (declarative)

    1.2 Paradigms

  • 8/11/2019 Programming Languages Overview

    11/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Imperative Paradigm

    Follows the classic von Neumann-Eckert model:

    Program and data are indistinguishable in memory

    Program = a sequence of commands

    State = values of all variables when program runs

    Large programs use procedural abstraction

    Oldest paradigm

    Example imperative languages:

    Cobol, Fortran, C, Ada, Perl,

    Note: C++ is a hybrid imperative and object-oriented language

  • 8/11/2019 Programming Languages Overview

    12/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    The von Neumann-Eckert Model

  • 8/11/2019 Programming Languages Overview

    13/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Object-oriented (OO) Paradigm

    An OO Program is a collection of objects that interact by

    passing messages that transform the state.

    When studying OO, we learn about:

    Sending Messages

    Inheritance

    Polymorphism

    Example OO languages:

    Smalltalk, Java, C++, C#, and Python

  • 8/11/2019 Programming Languages Overview

    14/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Functional Paradigm

    Functional programming models a computation as a

    collection of mathematical functions, each with:

    Input = domain

    Output = range or results

    Functional languages are characterized by:

    Functional composition

    Recursion

    Example functional languages:

    Lisp, Scheme, ML, Haskell,

  • 8/11/2019 Programming Languages Overview

    15/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Logic Paradigm

    Logic programming declares what outcome the program

    should accomplish, rather than how it should be

    accomplished (sometimes called rule-based languages).

    When studying logic programming we see:

    Programs as sets of constraints on a problem

    Programs that achieve all possible solutions

    Programs that are nondeterministic

    Example logic programming languages:

    Prolog

  • 8/11/2019 Programming Languages Overview

    16/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Event handling

    E.g., GUIs, home security systems

    Concurrency

    E.g., Client-server programs

    Correctness

    How can we prove that a program does what it is

    supposed to do under all circumstances?

    Why is this important???

    1.3 Special Topics

  • 8/11/2019 Programming Languages Overview

    17/33

    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

    1.4 A Brief History

  • 8/11/2019 Programming Languages Overview

    18/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

  • 8/11/2019 Programming Languages Overview

    19/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Design Constraints

    Computer architecture

    Technical setting

    Standards

    Legacy systems

    Design Outcomes and Goals

    1.5 On Language Design

  • 8/11/2019 Programming Languages Overview

    20/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

  • 8/11/2019 Programming Languages Overview

    21/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    What makes a successful language?

    Key characteristics:

    Simplicity and readability

    Clarity about binding

    Reliability

    Support

    Abstraction

    Orthogonality Efficient implementation

  • 8/11/2019 Programming Languages Overview

    22/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Simplicity and Readability

    Small instruction set

    E.g., Java vs Scheme

    Simple syntax E.g., C/C++/Java vs Python

    Benefits:

    Ease of learning Ease of programming

  • 8/11/2019 Programming Languages Overview

    23/33

    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 bindingis the association

    between an object and aproperty of that object Examples:

    a variable and its type

    a variable and its value

    Early binding takes place at

    compile-time

    Late binding takes place at run

    time.

    Clarity about BindingThe binding time for an

    attribute is the time atwhich the binding occurs.

    For example, in C the

    binding time for a variable

    type is when the program

    is compiled (because thetype cannot be changed

    without changing and

    recompiling the program),

    but the value of the

    variable is not bound untilthe program executes

    (that is, the value of the

    variable can change

    during execution).

  • 8/11/2019 Programming Languages Overview

    24/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    The most commonbinding times for attributes are (in

    chronological order):

    1.Language definition time: e.g. integers are bound to the identifierint

    2.Language implementation time: e.g. the size of an int value inC is determined.

    3.Program writing time: variable names are bound to types

    4.Program translation (compile time): e.g. a statement is boundto a specific M.L. instruction

    5.Program load time: e.g. static variables are bound (assigned) to afixed memory addresses6.Program execution (run time): e.g. variables are bound to

    values

    Clarity about Bindingcontinued

  • 8/11/2019 Programming Languages Overview

    25/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Reliability

    A language is rel iableif:

    Program behavior is the same on different platforms

    E.g., early versions of Fortran

    Type errors are detected

    E.g., C vs Haskell

    Semantic errors are properly trapped

    E.g., C vs C++

    Memory leaks are prevented

    E.g., C vs Java

  • 8/11/2019 Programming Languages Overview

    26/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Language Support

    Accessible (public domain) compilers/interpreters

    Good texts and tutorials

    Wide community of users

    Integrated with development environments (IDEs)

  • 8/11/2019 Programming Languages Overview

    27/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Abstraction in Programming

    Data

    Programmer-defined types/classes

    Class libraries

    Procedural

    Programmer-definedfunctions

    Standard function libraries

  • 8/11/2019 Programming Languages Overview

    28/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Orthogonality

    A language is orthogonalif its features are built upon asmall, mutually independent set of primitive operations.

    Fewer exceptional rules = conceptual simplicity

    E.g., restricting types of arguments to a function

    Tradeoffs with efficiency.

    Example: in passing arguments in function call, a fully

    orthogonal language allows all types of objects includinga function to be passed as arguments. Most imperative

    languages do not allow function definition to be passed as

    arguments and thus are not orthogonal in this regard.

  • 8/11/2019 Programming Languages Overview

    29/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Efficient implementation

    Embedded systems

    Real-time responsiveness (e.g., navigation)

    Failures of early Ada implementations

    Web applications

    Responsiveness to users (e.g., Google search)

    Corporate database applications

    Efficient search and updating

    AI applications

    Modeling human behaviors

  • 8/11/2019 Programming Languages Overview

    30/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    Compilerproduces machine code

    Interpreterexecutes instructions on a virtual machine

    Example compiled languages:

    Fortran, Cobol, C, C++

    Example interpreted languages:

    Scheme, Haskell, Python

    Hybrid compilation/interpretation

    The Java Virtual Machine (JVM)

    1.6 Compilers and Virtual Machines

  • 8/11/2019 Programming Languages Overview

    31/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    The Compiling Process

  • 8/11/2019 Programming Languages Overview

    32/33

    Copyright 2006 The McGraw-Hill Companies, Inc.

    The Interpreting Process

  • 8/11/2019 Programming Languages Overview

    33/33

    Discussion Questions

    1. Comment on the following quotation:

    It is practically impossible to teach good programming to

    students that have had a prior exposure to BASIC; as potential

    programmers they are mentally mutilated beyond hope of

    regeneration.E. Dijkstra

    2. Give an example statement in your favorite language

    that is particularly unreadable. E.g., what does the C

    expression while (*p++ = *q++)mean?