Topics Motivation Programming Domains Language Evaluation Criteria Language Design Trade-Offs Influences on Language Design Language Categories Implementation Methods
Chapter 1 Preliminaries
Chapter 1: Preliminaries
Languages
What is a Programming Language?
The purpose of language is communication n n
2
Natural languages Programming languages
What is a language? n
A set of rules that enables communication of ideas between people (between people and machines).
What is a program? Writing an English essay: n
Many can write in English
n
Few write well
n
What is a programming language? n
Chapter 1: Preliminaries
I already know the latest/greatest/coolest programming language. I can solve any problem using the programming language that I already know.
Chapter 1: Preliminaries
Chapter 1: Preliminaries
4
What is the best Programming Language?
Why do I need to learn the concepts of programming languages?
n
A set of rules that define a set of legal programs.
3
I already know a Programming Language
n
A set of instructions intended for machine execution.
5
Java
Prolog
C C++
ML Modula- 2
Perl Python
Fortran Cobol
Visual Basic Lisp
Smalltalk Haskell
Pascal
Algol
Chapter 1: Preliminaries
6
1
No clear winner
Reasons to study concepts of PLs 1. Improves ability to express ideas
Obviously there is no “best” language for all situations. n n n n n
n
Type of program Time available Cost Size and scope of program Programmer familiarity
n
Languages influence the way you think and approach problems. As you study new language features it may help you utilize or extend your own language skills. Limit kinds of control structure
Real computer programmers do not get religious about their languages, they get pragmatic and understand the trade-offs in their language choices.
n
Chapter 1: Preliminaries
n
Helps you understand the trade- offs in languages.
n
Provides alternatives choices that suits the project’s scope.
Chapter 1: Preliminaries
3. Increases ability to learn new languages n
There is significant similarity in the constructs provided by languages so that learning a language is often just a matter of syntax. • • • •
Informed language decision
Loops (while, for, do) Selection (if, case) Data types (int, char, string, object) Jumps (goto, break, continue) Data abstraction concept
Chapter 1: Preliminaries
9
Reasons to study concepts of PLs 4. Allows a better understanding of the significance of implementation n
Why the languages are design the way they are. Understand design’s purpose
n
8
Reasons to study concepts of PLs
2. Improves background for choosing appropriate languages
Trade-offs in languages
New features can be later simulated in other language.
7
Reasons to study concepts of PLs
Limit of constructed algorithms
Abstract data type (Java) Chapter 1: Preliminaries
10
Reasons to study concepts of PLs 5. Increases ability to design new languages 6. Overall advancement of computing n
Is the most popular programming language the best choice?
n
Why a language is the most popular?
Ability to use a language more intelligently
Recursion vs. Iteration (faster) Chapter 1: Preliminaries
11
Chapter 1: Preliminaries
12
2
What impacts Programming Language Design?
What impacts Programming Language Design? The set of applications (algorithms) that we want to implement using our programming language
Application domain
Application domain
Evaluation Criteria
Evaluation Criteria
Computer architecture
Computer architecture
Programming methodologies
Programming methodologies
Chapter 1: Preliminaries
13
Chapter 1: Preliminaries
Programming Domains
Programming Domains
Scientific n
Business
Focus on calculations
n
Simple data structures Large numbers of floating-point arithmetic computations n
Primary concern: efficiency
n
Languages: Fortran, Algol 60
Chapter 1: Preliminaries
n
n
Chapter 1: Preliminaries
Scripting Languages
Use symbolic rather than numeric computations. Focus on string and list manipulation Languages: Lisp family (Common Lisp, Scheme, ML), Prolog. Focus on fast execution
n
Low-level features Languages: PL/S (IBM), Extended Algol, C Chapter 1: Preliminaries
n
Putting a list of commands (script) in a file to be executed.
n
Generally domain specific
n
Usually interpreted Languages: s h and ksh (for shell), a w k (report- generation), tcl and tk (X Windows), Perl (CGI programming), JavaScript, PHP
Little code
n
Need efficiency because of continuous use n
16
Programming Domains
Systems Programming n
Language: Cobol
15
Artificial Intelligence n
Focus on reports and calculations Facilitates the production of reports Have precise ways of describing and storing decimal numbers and character data Specifies decimal arithmetic operations
Programming Domains n
14
17
Chapter 1: Preliminaries
18
3
What impacts Programming Language Design?
Project Manager’s Dilemma Which language shall we use in the next project?
Application domain
n
Evaluation Criteria
The set of factors that are important to the users of the programming language
There are 4 main criteria: n n
Computer architecture
n n
Programming methodologies Chapter 1: Preliminaries
To come to a decision one needs arguments in favor or against a language. Readability Writability Reliability Cost
Are there other factors? 19
Language Evaluation Criteria
Chapter 1: Preliminaries
Language Evaluation Criteria
Readability n
Criteria
The ease with which programs can be read and understood. The ease with which a language can be used to create programs.
Reliability n
Reliable performance (according to specifications) under all conditions. Chapter 1: Preliminaries
Readability
Writability
Reliability
Simplicity / orthogonality
♦
♦
♦
Control structure
♦
♦
♦
Data type and structures
♦
♦
♦
Syntax design
♦
♦
♦
Support for abstraction
♦
♦
Expressivity
♦
♦
Characteristics
Writability n
20
Type checking
♦
Exception handling
♦
Restricted aliasing
♦
21
Evaluation Criteria: Readability
Chapter 1: Preliminaries
22
Evaluation Criteria: Readability Factors
Readability describes the ease of which programs can be read and understood. This is the most important criterion. It significantly affects the maintainability of code (mayor cost for programs). It must be considered in the context of problem domain.
Chapter 1: Preliminaries
23
Overall simplicity
Features Domain
n
Too many features is bad
n
Multiplicity of features is bad.
Prog. 1
Prog. 2
C
count = count+1 count += 1 count++ ++count
n
Operator overloading makes confusion.
C
8+4 8.3 + 4.9 “test” + “it” [1,3,4] + [5,6,1] = [6,9,5] or [1,3,4,5,6,1] or 20?
Too simple can be just as much trouble (machine languages just 0 and 1) Chapter 1: Preliminaries
24
4
Evaluation Criteria: Readability
Evaluation Criteria: Readability
Factors
Factors
Orthogonality n
Control statements
A small number of primitive constructs combined in a relative small number of ways and everything can be combined with anything else.
n
Program easier to read from top to C bottom. Unstructured: GOTO Structured: loop
Every possible combination is legal. n
Meaning is context independent
Data type and structures
Pointer is able to point to any type of variable. n n
n
Makes the language easy to learn and read. Lack of orthogonality leads to exceptions to rules. Chapter 1: Preliminaries
Syntax considerations
n
Special words
C
n
end vs. end-if and end-loop
Special words n
Chapter 1: Preliminaries
26
Evaluation Criteria: Writability Writability describes the ease with which a language can be used to create programs for a given domain.
Too short equals bad variable names. Block structure
Not enough structures leads to workarounds which can reduce clarity.
25
Factors Identifier length and form
ADA
loop 1: if ( incr >=20) go to out; loop 2: if (sum > 100) go to next; go to loop2; next: incr++; go to loop 1; out:
Boolean type (vs. 0 and 1) Record (vs. Arrays)
Evaluation Criteria: Readability n
while( ( incr < 20) { while (sum