Title: Programming Languages
1Programming 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?
2Computational 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.
- ???
3Computational 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.
4A 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.
5Language 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.
6Language 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.
7Why 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.
8Programming 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)
9Language 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
10Evaluation 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
11Evaluation 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
12Evaluation 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
13Evaluation 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
14Evaluation 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
15Influences 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
16Computer 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
17The von Neumann Architecture
18The 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
19Programming 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
20Language 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
21Language 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
22Implementation 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
23Genealogy of Common Languages
24Brief History of PL
- Early Languages
- Fortran
- Cobol
- Algol60
- Lisp
- APL
- Basic
25Algol-based Languages
- PL/I
- Simula 67
- ALGOL68
- Pascal
26Languages of the 80s
- Prolog
- Smalltalk
- C/C
- Modula-2
- Ada
27Language of the 90s and beyond
- Domain-Specific Languages (www, database, GUI,
etc.) - Visual Programming Languages
- Visual Environments
- Scripting languages
- Libraries
28Learning 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.
29Learning a new language
- Problem-oriented.
- Syntax is unimportant at the conceptual stage.
- Syntax is the least interesting part of learning
a new language.
30Programming Models
- Paradigms
- Imperative
- Functional
- Object-Oriented
- Logical
- Distributed/Parallel
- Constraints
- Declarative
- ....
31Imperative 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.
32Imperative 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
33Functional 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.
34Functional Example
- QuickSort a list of items
- QuickSort(empty) empty
- QuickSort(head, tail) QuickSort(list lt head)
- head
-
QuickSort(list gt head) - concatenation
35Object-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.
36Logical 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.
37Problem Example
- Dexter wants to send flowers to Mimi
Mimi
Dexter
38Imperative 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
39OO Solution
Bank Teller
Dexter
Mimi
Delivery Person
Florist
40Functional 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()))
41Logical Solution
- Ask the Question
- ReceiveFlower(Mimi)?
- Lets see the rules and facts.
42Rules
- 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)
43Facts
- HasMoney(Dexter)
- Florist(Flo)
- GiveMoney(Dexter, Flo)
- Now ask the question ReceiveFlower(Mimi)?
- ???
- Whats missing?
44Facts
- Dog (Dexter)
- Dog(Mimi)
- ReceiveFlower(Mimi)?
- NO
45Problem Example
- Dexter wants to send flowers to Mimi
46Other Paradigms
- Distributed / Parallel
- Constraints
- Formulas
- Other names for functional
- Declarative
- Applicative
47Declarative Paradigm
- Specify the WHAT instead of HOW
- Definitional and not operational
- Includes functional, logical, constraints