Programming Languages - PowerPoint PPT Presentation

1 / 47
About This Presentation
Title:

Programming Languages

Description:

Programming Languages A programming language is a language that is intended to be used by a person to express a process by which a computer can solve a problem. – PowerPoint PPT presentation

Number of Views:744
Avg rating:3.0/5.0
Slides: 48
Provided by: yang1157
Category:

less

Transcript and Presenter's Notes

Title: Programming Languages


1
Programming Languages
  • A programming language is a language that is
    intended to be used by a person to express a
    process by which a computer can solve a problem.
  • ?? ?
  • Is a calculator a programming language?
  • Is a spreadsheet a programming language?
  • Is HTML a programming language?

2
Computational Theory
  • Anything that could be computed could, in theory,
    be computed on a simple device, a Turing Machine.
  • If our language can simulate a Turing Machine,
    then in theory, it can compute anything thats
    computable.
  • If so, we have a programming language.
  • ???

3
Computational Theory
  • Turing Tarpit Argument
  • Anything your language can do, my language can
    do as well, so there!
  • All languages have exactly the same power.
  • Why do we need more than one language then?
  • This argument is a tarpit because it is
    deceptively simple, but gets you nowhere.
  • Everything is possible, but nothing is easy.

4
A simpler definition
  • A language is a Programming Language iff it has
    the power for expressing 3 fundamental constructs
    in the problem solving process
  • Sequence (sequential execution of statements)
  • Conditional (if, switch/case)
  • Loops (while, for)
  • A programming language is said to be Turing
    Complete.

5
Language and Thought
  • Instead of theoretical computation power, we are
    concerned with ease of use.
  • How easily is it to communicate what we want the
    computer to do in some language?
  • Structure of a language defines the boundaries of
    thought.
  • Most of what we express is expressed in language,
    and must suffer the constraints of the medium.

6
Language and Thought
  • Languages predispose us to viewing the world in a
    certain way.
  • The same thing is true in programming languages,
    to an even greater extent.
  • Once someone has learned their first programming
    language, they tend to approach all problems from
    within that language.

7
Why study PLs?
  • Improve problem-solving ability.
  • Make better use of a language.
  • Choose an appropriate language.
  • Easier to learn a new language.
  • Better language designers.
  • Increased capacity to express ideas.

8
Programming Domains
  • Scientific applications
  • Large numbers of floating point computations use
    of arrays
  • Fortran
  • Business applications
  • Produce reports, use decimal numbers and
    characters
  • COBOL
  • Artificial intelligence
  • Symbols rather than numbers manipulated use of
    linked lists
  • LISP
  • Systems programming
  • Need efficiency because of continuous use
  • C
  • Web Software
  • Eclectic collection of languages markup (e.g.,
    XHTML), scripting (e.g., PHP), general-purpose
    (e.g., Java)

9
Language Evaluation Criteria
  • Readability the ease with which programs can be
    read and understood
  • Writability the ease with which a language can
    be used to create programs
  • Reliability conformance to specifications (i.e.,
    performs to its specifications)
  • Cost the ultimate total cost

10
Evaluation Criteria Readability
  • Overall simplicity
  • A manageable set of features and constructs
  • Minimal feature multiplicity
  • Minimal operator overloading
  • Orthogonality
  • A relatively small set of primitive constructs
    can be combined in a relatively small number of
    ways
  • Every possible combination is legal
  • Data types
  • Adequate predefined data types
  • Syntax considerations
  • Identifier forms flexible composition
  • Special words and methods of forming compound
    statements
  • Form and meaning self-descriptive constructs,
    meaningful keywords

11
Evaluation Criteria Writability
  • Simplicity and orthogonality
  • Few constructs, a small number of primitives, a
    small set of rules for combining them
  • Support for abstraction
  • The ability to define and use complex structures
    or operations in ways that allow details to be
    ignored
  • Expressivity
  • A set of relatively convenient ways of specifying
    operations
  • Strength and number of operators and predefined
    functions

12
Evaluation Criteria Reliability
  • Type checking
  • Testing for type errors
  • Exception handling
  • Intercept run-time errors and take corrective
    measures
  • Aliasing
  • Presence of two or more distinct referencing
    methods for the same memory location
  • Readability and writability
  • A language that does not support natural ways
    of expressing an algorithm will require the use
    of unnatural approaches, and hence reduced
    reliability

13
Evaluation Criteria Cost
  • Training programmers to use the language
  • Writing programs (closeness to particular
    applications)
  • Compiling programs
  • Executing programs
  • Language implementation system availability of
    free compilers
  • Reliability poor reliability leads to high costs
  • Maintaining programs

14
Evaluation Criteria Others
  • 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 the languages
    official definition

15
Influences on Language Design
  • Computer Architecture
  • Languages are developed around the prevalent
    computer architecture, known as the von Neumann
    architecture
  • Programming Methodologies
  • New software development methodologies (e.g.,
    object-oriented software development) led to new
    programming paradigms and by extension, new
    programming languages

16
Computer Architecture Influence
  • Well-known computer architecture Von Neumann
  • Imperative languages, most dominant, because of
    von Neumann computers
  • Data and programs stored in memory
  • Memory is separate from CPU
  • Instructions and data are piped from memory to
    CPU
  • Basis for imperative languages
  • Variables model memory cells
  • Assignment statements model piping
  • Iteration is efficient

17
The von Neumann Architecture
18
The von Neumann Architecture
  • Fetch-execute-cycle (on a von Neumann
    architecture computer)
  • initialize the program counter
  • repeat forever
  • fetch the instruction pointed by the counter
  • increment the counter
  • decode the instruction
  • execute the instruction
  • end repeat

19
Programming Methodologies Influences
  • 1950s and early 1960s Simple applications worry
    about machine efficiency
  • Late 1960s People efficiency became important
    readability, better control structures
  • structured programming
  • top-down design and step-wise refinement
  • Late 1970s Process-oriented to data-oriented
  • data abstraction
  • Middle 1980s Object-oriented programming
  • Data abstraction inheritance polymorphism

20
Language Categories
  • Imperative
  • Central features are variables, assignment
    statements, and iteration
  • Include languages that support object-oriented
    programming
  • Include scripting languages
  • Include the visual languages
  • Examples C, Java, Perl, JavaScript, Visual BASIC
    .NET, C
  • Functional
  • Main means of making computations is by applying
    functions to given parameters
  • Examples LISP, Scheme
  • Logic
  • Rule-based (rules are specified in no particular
    order)
  • Example Prolog
  • Markup/programming hybrid
  • Markup languages extended to support some
    programming
  • Examples JSTL, XSLT

21
Language Design Trade-Offs
  • Reliability vs. cost of execution
  • Example Java demands all references to array
    elements be checked for proper indexing, which
    leads to increased execution costs
  • Readability vs. writability
  • Example APL provides many powerful operators
    (and a large number of new symbols), allowing
    complex computations to be written in a compact
    program but at the cost of poor readability
  • Writability (flexibility) vs. reliability
  • Example C pointers are powerful and very
    flexible but are unreliable

22
Implementation Methods
  • Compilation
  • Programs are translated into machine language
  • Pure Interpretation
  • Programs are interpreted by another program known
    as an interpreter
  • Hybrid Implementation Systems
  • A compromise between compilers and pure
    interpreters

23
Genealogy of Common Languages
24
Brief History of PL
  • Early Languages
  • Fortran
  • Cobol
  • Algol60
  • Lisp
  • APL
  • Basic

25
Algol-based Languages
  • PL/I
  • Simula 67
  • ALGOL68
  • Pascal

26
Languages of the 80s
  • Prolog
  • Smalltalk
  • C/C
  • Modula-2
  • Ada

27
Language of the 90s and beyond
  • Domain-Specific Languages (www, database, GUI,
    etc.)
  • Visual Programming Languages
  • Visual Environments
  • Scripting languages
  • Libraries

28
Learning a new language
  • Questions to ask
  • What problem domain is the language intended for?
  • What is the programming model?
  • What are the basic objects (data structures)
    manipulated in the language?
  • What are the things that you can do with these
    objects?
  • How is control flow managed in the language?
  • How is information flow managed in the language?
  • Parameter passing, scope rules, declaration
    statements, etc.

29
Learning a new language
  • Problem-oriented.
  • Syntax is unimportant at the conceptual stage.
  • Syntax is the least interesting part of learning
    a new language.

30
Programming Models
  • Paradigms
  • Imperative
  • Functional
  • Object-Oriented
  • Logical
  • Distributed/Parallel
  • Constraints
  • Declarative
  • ....

31
Imperative Paradigm
  • Dictatorship
  • Processor in control
  • Stuff things in new places in the processor
    memory.
  • State modification - program consists of a
    sequence of modification to the memory.
  • Somewhere in the state modification lies the
    answer.

32
Imperative Example
i
  • cin gtgt i
  • X x i
  • y
  • Z x / y
  • for (int j0 jlti j)
  • a a Z

X
Y
Z
j
a
33
Functional Paradigm
  • Mathematician
  • Express the process in an abstract way.
  • Programming has to do with specifying definitions
    much like math functions.
  • Program describe, in an abstract way, the
    operations that must be performed to solve the
    problem.

34
Functional Example
  • QuickSort a list of items
  • QuickSort(empty) empty
  • QuickSort(head, tail) QuickSort(list lt head)
  • head

  • QuickSort(list gt head)
  • concatenation

35
Object-Oriented Paradigm
  • Committee
  • Send messages to ask members to do stuff
  • Objects have states.
  • Only objects can change their own states.
  • Divide up the responsibilities.

36
Logical Paradigm
  • Philosopher
  • People ask questions
  • Program is a logical description of the problem
    expressed as facts and rules.
  • Output or answers are derived from the facts.

37
Problem Example
  • Dexter wants to send flowers to Mimi

Mimi
Dexter
38
Imperative Solution
  • Allocate space for flower
  • Get money from bank
  • Store money
  • Retrieve money
  • Give money to florist
  • Get flower from florist
  • Store flower
  • Arrive at destination
  • Retrieve flower
  • Deliver flower


39
OO Solution
Bank Teller
Dexter
Mimi
Delivery Person
Florist
40
Functional Solution
  • What needs to be done here?
  • Cash Withdraw
  • Buy Flowers
  • Delivery Flowers
  • What order do they need to happen?
  • Cash -gt Flowers -gt Deliver
  • Functions have parameters and return values
  • Deliver( Buy (Withdraw()))

41
Logical Solution
  • Ask the Question
  • ReceiveFlower(Mimi)?
  • Lets see the rules and facts.

42
Rules
  • ReceiveFlower(x) DeliverFlower(y, x)
  • DeliverFlower(y,x)
  • Florist(y) OrderFlower(z, y) Person(x)
  • OrderFlower(x,y) Florist(y) Person(x)
    HasMoney(x) GiveMoney(x, y)

43
Facts
  • HasMoney(Dexter)
  • Florist(Flo)
  • GiveMoney(Dexter, Flo)
  • Now ask the question ReceiveFlower(Mimi)?
  • ???
  • Whats missing?

44
Facts
  • Dog (Dexter)
  • Dog(Mimi)
  • ReceiveFlower(Mimi)?
  • NO

45
Problem Example
  • Dexter wants to send flowers to Mimi

46
Other Paradigms
  • Distributed / Parallel
  • Constraints
  • Formulas
  • Other names for functional
  • Declarative
  • Applicative

47
Declarative Paradigm
  • Specify the WHAT instead of HOW
  • Definitional and not operational
  • Includes functional, logical, constraints
Write a Comment
User Comments (0)
About PowerShow.com