0% found this document useful (0 votes)
4 views25 pages

01 Chapter 01

Chapter 1 introduces the study of programming languages, outlining key learning outcomes such as understanding evaluation criteria and design trade-offs. It discusses the motivation for studying programming languages, the various programming domains, and the importance of language evaluation criteria like readability, writability, reliability, and cost. Additionally, it categorizes programming languages and describes implementation methods and programming environments.

Uploaded by

Lucky John
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views25 pages

01 Chapter 01

Chapter 1 introduces the study of programming languages, outlining key learning outcomes such as understanding evaluation criteria and design trade-offs. It discusses the motivation for studying programming languages, the various programming domains, and the importance of language evaluation criteria like readability, writability, reliability, and cost. Additionally, it categorizes programming languages and describes implementation methods and programming environments.

Uploaded by

Lucky John
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 25

Chapter 1

Preliminaries

ISBN 0-321-19362-8
Introduction

Learning Outcomes:
By the end of this module you will be able to:
1. describe the reasons for studying programming languages
2. recognize and compare programming languages evaluation
criteria
3. identify some trade-offs in language design
4. explain the relative merits and demerits of compiled and
interpreted languages

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-2


Topics

• Motivation
• Programming Domains
• Language Evaluation Criteria
• Influences on Language Design
• Language Categories
• Language Design Trade-Offs
• Implementation Methods
• Programming Environments

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-3


What is a Programming Language?

• A language for expressing instructions to a


computer
• A series of instructions written by a programmer
according to a given set of rules or conventions
(“syntax”).
• A computer language that programmers utilize to
create programs. C, Perl, Java, BASIC, and
COBOL are examples of programming
languages.

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-4


Motivation: Why Study Programming
Languages?
• Increased ability to express ideas
– Knowledge of language features increases expressive power
– Similar to natural languages
• Improved background for choosing appropriate languages
– If you know only one language, it may not be the most
appropriate for certain applications
– Imagine writing a multithreaded application when you know
only C
• Greater ability to learn new languages
– Easier to learn how concepts you already know are incorporated
in languages
– A number of differences among languages are syntactic

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-5


Motivation: Why Study Programming
Languages?

• Understand significance of implementation


– Knowledge of language concepts
• increases appreciation of design & implementation choices
• Leads to more intelligent use of the language as it was designed
to be used
• Ability to design new languages
– Design a language with best collection of features
• Overall advancement of computing
– Ability to choose better languages over poor ones (when you are
a Boss!)

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-6


Programming Domains
• As computers are used in diverse applications, languages
with very different goals have been developed
• Scientific applications – Fortran, Algol 60
– Large number of floating point computations
• Business applications – COBOL
– Produce reports, use decimal numbers and characters
• Artificial intelligence – Lisp, Prolog, Scheme
– Symbols rather than numbers manipulated
• Systems programming – C
– Need efficiency because of continuous use
• Scripting languages – Perl
– Put a list of commands in a file to be executed
• Special-purpose languages
– For business report generation – RPG

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-7


Language Evaluation Criteria: Readability
• How easy is it to read and understand programs in the
language?
• One of the most important criterion
• Factors influencing readability:
1. Overall simplicity
– Too many features is bad
– Multiplicity of features is bad
2. Orthogonality
– Features of the language have as few restrictions as possible and can
be combined in any meaningful way.
– Language constructs should not behave differently in different
context
– Makes the language easy to learn and read
– Every possible combination is legal
– Lack of orthogonality leads to exceptions to rules
– C examples: by default, arrays are passed by address; array elements
cannot be of void type; arrays cannot be functions’ return type

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-8


Language Evaluation Criteria: Readability (cont’d)

• Readability factors (continued)


3. Control statements
– Readability can improve with adequate control structures rather than
frequent the use of the ‘goto’ statement
4. Defining data types and structures
– Programs in languages with a Boolean type can be more readable
than programs in those without a Boolean type
– Records modeled using structures are more readable than those
modeled using parallel arrays
5. Syntax considerations
– Identifier forms – restricting identifier length hinders use of
connotative names
– Special words – Pascal’s use of begin-end pairs and C’s use of
{ and } to form compound statements
– Form and meaning – semantics should follow from syntax, or form
» Violation: the same keyword, static, in C has meaning
depending on context.

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-9


Language Evaluation Criteria: Writability

• How easily can the language be used to create an


application from a chosen domain?
• Factors affecting writability:
1. Simplicity and orthogonality
– Most characteristics affecting readability also affect writability
2. Support for abstraction
– Process abstraction offers readability, writability, code re-use and
brevity
– Data abstraction offers greater modeling power, readability and
writability
3. Expressivity
– Having convenient (not cumbersome) and powerful ways of
specifying computation (e.g., APL)
– Makes programs short and concise

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-10


Language Evaluation Criteria: Reliability
• Does the language provide facilities to write programs
that work under all possible conditions?
• Factors affecting reliability:
1. Type checking
– Checking for type errors at compile or runtime
2. Exception handling
– Detecting and handling runtime errors and other unusual conditions
– Enables a program to continue execution after encountering errors
3. Aliasing
– Having two or more names referring to a memory cell
4. Readability and writability
– The more natural the constructs of a language, the more it is easier
to read and write programs.
– Such programs will be more likely to be correct

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-11


Discussion

/* Program in Language A */
c = 0;
for(int i=0; i<n; i++)
c = c + V[i] * W[i];
System.out.println(c);

/* Program in Language B */
INNERPROD <- + / V x W

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-12


Language Evaluation Criteria: Cost

• How much does the language cost the client, user


or designer?
• Categories
• Training programmers to use language
• Writing programs
• Compiling programs (reduced with clever compilers)
• Executing programs (reduced with static type checking)
• Language implementation system (reduced with free tools)
• Reliability (can lead to law suits or loss of business)
• Maintaining programs (depends on readability and
writability)

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-13


Language Evaluation Criteria: Others

• Portability
– Ease of moving programs from one implementation to
another
• Generality
– Applicability to a wide-range of applications
• Well-definedness
– Completeness and precision of the language’s defining
document

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-14


Influences on Language Design
• Computer architecture: Von Neumann
• We use imperative languages, at least in part,
because we use von Neumann machines
– Data and programs stored in same 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 on these computers because
instructions are stored in adjacent cells of memory

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-15


Von Neumann Architecture

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-16


von Neumann Architecture and Imperative Languages

CPU Feature Modeled using language feature

Memory Variables
Load Variable evaluation

Store Assignment
Conditional goto Control structure

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-17


Influences on Language Design

• Research on programming languages led to the following


programming methodologies
• Structured design – late 1960s
– Better control structures for readability and more programmer productivity
• Data-oriented design – late 1970s
– Encapsulation and information hiding
• Object-oriented design – middle 1980s
– Addition of inheritance and dynamic binding

• Major reasons for the research were


1. Decrease in hardware cost without matching decrease in software cost
2. Programming applications are becoming more and more complex

• Languages were developed to support the concepts in these


methodologies

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-18


Language Categories

• Programming languages are often grouped into


four classes
1. Imperative
• Central features are variables, assignment statements,
and iteration
• Order of executing statements is prescribed
• Examples: C, Pascal
2. Functional
• Main means of making computations is by applying
functions to given parameters
• Order of executing statements does not matter
• Examples: LISP, Scheme, Haskell

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-19


Language Categories

3. Logic
– Rule-based
– Rules are specified in no special order
– Example: Prolog
4. Object-oriented
– Encapsulate data objects with processing
– Inheritance and dynamic type binding
– Grew out of imperative languages
– Examples: C++, Java, C#

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-20


Language Design Trade-Offs

• The language evaluation criteria we discussed


are sometime contradictory
– Usually, a design has to trade some for others
• Examples of typical trade-off cases
1. Reliability vs. cost of execution
2. Readability vs. writability
3. Flexibility vs. safety

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-21


Implementation Methods

• Compilation
– Translate high-level
program to machine code
– Slower translation
– Faster execution
– Lack of portability

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-22


Implementation Methods

• Pure interpretation
– No translation
– Slow execution (10-100
time slower than
compilation)
– Becoming rare
– Requires more space since
the symbol table must be
available during
interpretation
– Examples: APL, LISP,
JavaScript, PHP

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-23


Implementation Methods

• Hybrid implementation
systems
– Small translation cost
– Medium execution speed
– Faster than pure
interpretations because
high level language
statements are decoded
only once
– Examples: Perl, Java

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-24


Programming Environments

• The collection of tools used in software


development
• UNIX
– An older operating system and tool collection
• Borland JBuilder
– An integrated development environment for Java
• Microsoft Visual Studio.NET
– A large, complex visual environment
– Used to program in C#, Visual BASIC.NET, Jscript,
J#, or C++

Copyright © 2004 Pearson Addison-Wesley. All rights reserved. 1-25

You might also like