01 preliminaries

Upload: aashish39

Post on 03-Apr-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 01 Preliminaries

    1/30

    CSI 3125, Preliminaries, page 1

    Preliminaries

    Programming languages and the

    process of programming.

    Criteria for the design and evaluation

    of programming languages

    Basic ideas of programming language

    implementations.

    What we will discuss:

  • 7/28/2019 01 Preliminaries

    2/30

    CSI 3125, Preliminaries, page 2

    Programming languages

    and the process of programming

    Points to discuss:

    Programming means more thancoding.

    Why study programming languages?

    Programming language paradigmsand applications.

  • 7/28/2019 01 Preliminaries

    3/30

    CSI 3125, Preliminaries, page 3

    Programming means much more than

    coding in a programming language

    Before coding begins, you analyze the problem,

    design (or borrow) an algorithm, analyze the

    cost of the solution.

    After all coding has been done, you have tomaintain the program.

    Programming languages are used to instruct

    computers.

    What do we communicate to computers?

    How do computers talk back to us?

  • 7/28/2019 01 Preliminaries

    4/30

    CSI 3125, Preliminaries, page 4

    Programming means more than coding (2)

    How do programming languages differ

    from natural languages? Would talking to

    computers (instructing them) in human

    languages be preferable?

    What makes someone a good

    programmer?

    Should a good programmer know morethan one programming language?

  • 7/28/2019 01 Preliminaries

    5/30

    CSI 3125, Preliminaries, page 5

    Why should we study

    programming languages?

    To understand better the connection between

    algorithms and programs.

    To be able to look for general, language-

    independent solutions.

    To have a choice of programming tools that

    best match the task at hand:

    identify subtasks and apply to each of themthe bestlanguage, using the full expressive

    power of each language.

  • 7/28/2019 01 Preliminaries

    6/30

    CSI 3125, Preliminaries, page 6

    Why should we study

    programming languages? (2)

    To appreciate the workings of a computer

    equipped with a programming languageby

    knowing how languages are implemented.

    To learn new programming languages easilyand to know how to design new formal

    languages (for example, input data formats).

    To see how a language may influence thediscipline of computing and strengthen good

    software engineering practice.

  • 7/28/2019 01 Preliminaries

    7/30

    CSI 3125, Preliminaries, page 7

    The many classes

    of programming languages:

    programming language paradigms

    Every programming language supports a

    slightly different or dramatically differentstyle of problem solving.

    The same computation can be

    expressed in various languages, andthen run on the same computer.

  • 7/28/2019 01 Preliminaries

    8/30

    CSI 3125, Preliminaries, page 8

    Programming languages

    classified by paradigm

    Imperative: howdo we solve a problem (whatsteps does a solution have)?

    Logic-based: whatdo we do to solve a problem?

    (The language decides howto do it.) Functional: what simple operations can be

    applied to solving a problem, how are theymutually related, and how can they be combined?

    Object-oriented: what objects play roles in aproblem, what can they do, and how do theyinteract to solve the problem?

  • 7/28/2019 01 Preliminaries

    9/30

    CSI 3125, Preliminaries, page 9

    Classification by generality of use

    General-purpose programming languages

    (most of the known languages are in this

    category);

    Specialized programming languages

    (for example, database languages, vector-

    processing languages, report generation

    languages, scripting languages, and more).

  • 7/28/2019 01 Preliminaries

    10/30

    CSI 3125, Preliminaries, page 10

    Classification by complication,

    abstraction, level

    Low-level languages (machine languages,assembly languages).

    High-level languages (most of the well-known languages belong in this category).

    Very high-level languages (Prolog issometimes listed in this category, andsome specialized languages).

    Beyond programming languages: Programming environments, software

    development tools and workbenches.

  • 7/28/2019 01 Preliminaries

    11/30

    CSI 3125, Preliminaries, page 11

    Classification by area of application

    Data processing (also known as "businessapplications").

    Now made largely unnecessary, since we havedatabases and other business-related

    packages, such as spreadsheets, and special-purpose software.

    Scientific computing (this includes engineering).

    Today this has been changed by new hardware

    designs such as supercomputers or vectorcomputers, and specialized computing devices.

  • 7/28/2019 01 Preliminaries

    12/30

    CSI 3125, Preliminaries, page 12

    Classification by area of application (2)

    Artificial intelligence and other applicationsnot in the computer science mainstream.

    This might include educational softwareand games.

    New hardware (so far mostly simulated)such as connection machines and neuralnetworks.

    "In-house" computing applications.

    compiler construction, systemsprogramming, GUI, API, and so on.

  • 7/28/2019 01 Preliminaries

    13/30

    CSI 3125, Preliminaries, page 13

    Criteria for the design and evaluation

    of programming languages

    Points to discuss:

    Readability

    Writability

    Reliability

    Cost

  • 7/28/2019 01 Preliminaries

    14/30

    CSI 3125, Preliminaries, page 14

    Readability

    This is subjective, but very important.

    Language readability is essential because

    of software engineering practices, and in

    particular the needs of software evolution

    and maintenance.Abstractionsupport for generality of

    programs: procedural abstraction, data

    abstraction.

    Absence of ambiguity (and absence oftoo many coding choices, like having five

    different loop constructs).

  • 7/28/2019 01 Preliminaries

    15/30

    CSI 3125, Preliminaries, page 15

    Readability (2)

    Orthogonality: there are no restrictions oncombinations of primitive language concepts.(It is easier to detect lackof orthogonality.)

    For example, can everything have a value?

    Can an array group things of every kind?

    ......

    More orthogonality = fewer special cases inthe language.

    This may be carried too far (as in Algol 68).

  • 7/28/2019 01 Preliminaries

    16/30

    CSI 3125, Preliminaries, page 16

    Readability (3)

    Expressivity of control and data structures. what is better (easier to read, maintain and so on):

    a longer program made of simple elements?

    a shorter program built out of complex,

    specialized constructions? Examples of high expressive power: recursion,

    built-in backtracking (as in Prolog), search indatabase languages.

    Examples of low expressive power: instructions inmachine or assembly languages.

    Appearance: syntax, including comments.

  • 7/28/2019 01 Preliminaries

    17/30

    CSI 3125, Preliminaries, page 17

    Writability

    Abstraction and simplicity: once more, subjective. Pascal has always been considered simple, Ada

    complicated

    Basic is very simple

    Prolog is conceptually simple, but may be difficultto learn.

    is C++ simple? is Java?

    Expressivity again.

    Modularity and tools for modularization, support forintegrated programming environments.

  • 7/28/2019 01 Preliminaries

    18/30

    CSI 3125, Preliminaries, page 18

    Reliability and Cost

    Reliability.

    Safety for the programmer (type checking, errorand exception handling, unambiguous names).

    Cost.

    Development time (ease of programming,

    availability of shared code).

    Efficiency of implementation: how easy it is to builda language processor (Algol 68 is a known failure,

    Ada almost a failure; Pascal, C, C++ and Java are

    notable successes). Translation time and the quality of object code.

    Portability and standardization.

  • 7/28/2019 01 Preliminaries

    19/30

    CSI 3125, Preliminaries, page 19

    Implementing programming languages

    Points to discuss:

    Language processors,virtual machines

    Models of implementation

    Compilation and execution

  • 7/28/2019 01 Preliminaries

    20/30

    CSI 3125, Preliminaries, page 20

    Language processors

    A processor for language L is any device(hardware or software) that understands andcan execute programs in language L.

    Translation is a process of mapping a program

    in the source language into the target language,while preserving the meaning or function of thesource program.

    The target language may be directly executable

    on the computer or (more often) may have tobe translated againinto an even lower-levellanguage.

  • 7/28/2019 01 Preliminaries

    21/30

    CSI 3125, Preliminaries, page 21

    Virtual machines

    A virtual machine is a software realization

    (simulation) of a language processor.

    Programming directly for hardware is very

    difficultwe usually "cover" hardware with

    layers of software.

    A layer may be shared by several language

    processors, each building its own virtual

    machine on top of this layer.

  • 7/28/2019 01 Preliminaries

    22/30

    CSI 3125, Preliminaries, page 22

    Examples of shared layers

    All language processors require

    support for input/output.

    All language processors eventually

    must do some calculations, that is,

    use the CPU.

  • 7/28/2019 01 Preliminaries

    23/30

    CSI 3125, Preliminaries, page 23

    Virtual machines

    We normally have hierarchies of virtual

    machines:

    at the bottom, hardware;

    at the top, languages close to the

    programmer's natural way of thinking.

    Each layer is expressed only in terms of

    theprevious layerthis ensures proper

    abstraction.

  • 7/28/2019 01 Preliminaries

    24/30

    CSI 3125, Preliminaries, page 24

    A generic hierarchy

    of virtual machines

    Layer 0: hardware

    Layer 1: microcode

    Layer 2: machine language

    Layer 3: system routines

    Layer 4: machine-independent code

    Layer 5: high-level language (or assembler)

    Layer 6: application program

    Layer 7: input data [this is also a language!]

  • 7/28/2019 01 Preliminaries

    25/30

    CSI 3125, Preliminaries, page 25

    Virtual machinesexamples

    Layer 0: IBM Netvista with Intel Pentium 4, 2GHzLayer 1: IBM Intel machine language

    Layer 2: Windows XP

    Layer 3: Java byte-code

    Layer 4: Java 2.0 (code developed in JRE 1.4.0)

    Layer 5: smart comparator of C++ programs,written in Java

    Layer 6: two C++ programs to comparefor similarities

  • 7/28/2019 01 Preliminaries

    26/30

    CSI 3125, Preliminaries, page 26

    Virtual machinesexamples (2)

    Layer 0: IBM Netvista with Intel Pentium 4, 2GHz

    Layer 1: IBM Intel machine language

    Layer 2: Windows NT 4.0

    Layer 3: Java byte-code

    Layer 4: JDK 1.2

    Layer 5: a Java implementation of Prolog

    Layer 6: a Prolog implementation of mySQL

    Layer 7: a database schema defined and created

    Layer 8: records for insertion into the database

  • 7/28/2019 01 Preliminaries

    27/30

    CSI 3125, Preliminaries, page 27

    Models of implementation

    Compilation: translate the program into an equivalent

    form in a lower-layer virtual machinelanguage;

    execute later. Interpretation:

    divide the program up into small(syntactically meaningful) fragments;

    in a loop, translate and execute eachfragment immediately.

  • 7/28/2019 01 Preliminaries

    28/30

    CSI 3125, Preliminaries, page 28

    Models of implementation (2)

    Pure compilation and pure interpretation areseldom use. Normally, an implementationemploys a mix of these models.

    For example: compile Java intobytecodes, then interpret bytecodes.

    We consider a language processor aninterpreter if it has "more interpretation than

    compilation". We consider a processor acompiler if there is more of compilation.

  • 7/28/2019 01 Preliminaries

    29/30

    CSI 3125, Preliminaries, page 29

    Models of implementation (3)

    Some languages are better interpreted, forexample interactively used Prolog or Lisp.

    Some languages are better compiled, forexample, C++, Java.

    There can also be compiled Prolog or Lisp:

    an interpretive top-level loop handles userinteraction.

    Predicates of functions are compiled into anoptimized form which is then interpreted.

  • 7/28/2019 01 Preliminaries

    30/30

    CSI 3125 Preliminaries page 30

    Compilation and execution

    Output DataInput Data

    Target Program

    Abstract Program

    (Optimized)

    Parse TreeSymbol Table

    Source program

    Code

    OptimizationSemantic

    Analysis

    Loader / LinkerCode

    Generation

    Computer

    Lexical Analysis

    (scanning)

    Syntactic Analysis

    (parsing)

    compiler

    Token Sequence

    Abstract Program

    (Intermediate code)

    Object Program

    (Native Code)