0% found this document useful (0 votes)
101 views17 pages

Programming Languages: Administrivia

456 programming languages 10 (mostly small) assignments readability counts! pselling too! assignments graded within 3 days of due date read and evaluated by human eyes each assignment up to10pt, fractions rounded up optional questions answered for additional credit Working together Collaborate! why study languages? Learn new ways of thinking about the act of programming understanding the tools (languages) helps avoiding nasty surprise Become a sophisticated, skeptical consumer Learn how to reason about your programs.

Uploaded by

Shama Nauman
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views17 pages

Programming Languages: Administrivia

456 programming languages 10 (mostly small) assignments readability counts! pselling too! assignments graded within 3 days of due date read and evaluated by human eyes each assignment up to10pt, fractions rounded up optional questions answered for additional credit Working together Collaborate! why study languages? Learn new ways of thinking about the act of programming understanding the tools (languages) helps avoiding nasty surprise Become a sophisticated, skeptical consumer Learn how to reason about your programs.

Uploaded by

Shama Nauman
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

456

programming languages

instructor: Jan Vitek


e-mail: jv@cs
web: www.cs.purdue.edu/~jv

Administrivia

Weight of grades:
homework: 30%
midterms: 30% optional project: 30%
final exam: 40%

Final grades:
A = 90pt, B = 80, C = 60, ... no curve!
Administrivia

• 10 (mostly small) assignments


• readability counts! pselling too!
• assignments graded within 3 days of due date
• read and evaluated by human eyes
• each assignment up to10pt, fractions rounded up
• optional questions answered for additional credit

Working together

Collaborate! (up to a point)


• that's what professionals do
• vital to your success
• discuss problems, techniques, ideas
• all discussions must be acknowledged
What should a programming language do?

Express computations
• precisely
• at a high level
• so that we can reason about them

What is it all for?

Make it easier to write programs that really work


Why study languages?

• Learn new ways of thinking about the act of


programming
• Understanding the tools (languages) helps avoiding
nasty surprise
• Become a sophisticated, skeptical consumer
• Learn how to reason about your programs
• Work at Sun, IBM, Microsoft, ...

Story: buffer overflows

• The oldest software defect in the book is the so-


called buffer overflow software defect

copy(Array a, Array b) {
for(int i=0; i < a.length; i++)
b.val[i] = a.val[i];
}
PL to the rescue: ccured

• CCured is a source-to-source translator for C.


• Determines smallest number of run-time checks to
insert in the program.
The resulting program is memory safe, it will stop
rather than overrun a buffer or scribble over memory
that it shouldn't touch.
• Many programs can be made memory-safe this way
while losing only 10--60% run-time performance.
• Used on sendmail, bind, openssl, Apache modules,
Linux device drivers, and SPEC95 benchmarks.

Research in PL

• Few new general-purpose languages -- adoption is a


big hurdle
• Many domain specific languages (DSL)
• Tools for understanding and providing execution
guarantees for programs (e.g. safety or security
guarantees)
CS 456 agenda

Intellectual tools to understand and evaluate


programming languages
• language features

Learn the notation of the trade


• precise way to model languages
• foundation for further study

Learn by doing
• write mostly short programs, thought required

studying language features

Choose abstractions (i.e. language features) to suite


the needs
Build your vocabulary (i.e. add to your toolbox)
Higher-order functions
Polymorphism
Pattern matching
Data for symbolic computing: lists, table, sets
Abstract data types, encapsulation
Objects and subtyping
Modules and parameterization
Which features?

"Programming language should be designed not by


piling feature on top of feature, but by removing the
weaknesses and restrictions that make additional
features appear necessary"
-- quote from?
a) Programming in Perl
b) The C++ Reference Manual
c) The Scheme Report

Why study bizarre languages?

Fact: some languages are more powerful that others


• the only valid reason to use an inferior language is
backward compatibility with legacy and libraries
• Happy user of Blub because Blub beats Cobol and
assembly. Use Haskell, Scheme, ML? Hell no! 'Cause
they are all equivalent to Blub plus some bizarre stuff
no one uses.
• habit blinds us to power
Chapter 1

Preliminaries

Copyright © 2007 Addison-Wesley. All rights reserved.


ISBN 0-321-49362-1

Chapter 1 Topics

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

• Scientific applications
– Large number of floating point computations: Fortran

• Business applications
– Produce reports, use decimal numbers and characters:
COBOL
• Artificial intelligence
– Symbols rather than numbers manipulated: 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 (Java)

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
Evaluation Criteria: Readability

• Overall simplicity
– A manageable set of features and constructs
– Few feature multiplicity (means of doing the same
operation)
– 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

• Control statements
– The presence of well-known control structures (e.g.,
while statement)

Evaluation Criteria: Readability

• Data types and structures


– The presence of adequate facilities for defining data
structures

• Syntax considerations
– Form and meaning: self-descriptive constructs,
meaningful keywords
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
– Example: the inclusion of for statement in many
modern languages

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 necessarily use
“unnatural” approaches, and hence reduced reliability
Evaluation Criteria: Cost

• Training programmers to use 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

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 language’s
official definition
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

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
Language Categories

• Imperative
– Central features are variables, assignment statements,
and iteration: C, Pascal

• Functional
– Main means of making computations is by applying
functions to given parameters: LISP, Scheme
• Logic
– Rule-based (rules are specified in no particular order):
Prolog

• Object-oriented
– Data abstraction, inheritance, late binding: Java, C++

Language Design Trade-Offs

• Reliability vs. cost of execution


– Example: Java demands all references to array
elements be checked for proper indexing but that
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 not reliably used
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

Compilation

• Translate high-level program (source language) into


machine code (machine language)
• Slow translation, fast execution
• Compilation process has several phases:
– lexical analysis: converts characters in the source
program into lexical units
– syntax analysis: transforms lexical units into parse
trees which represent the syntactic structure of
program
– Semantics analysis: generate intermediate code
– code generation: machine code is generated
Pure Interpretation

• No translation
• Easier implementation of programs (run-time errors
can easily and immediately displayed)
• Slower execution (10 to 100 times slower than
compiled programs)
• Often requires more space
• Becoming rare on high-level languages
• Significant comeback with some Web scripting
languages (e.g., JavaScript)

Hybrid Implementation Systems

• Ainterpreters
compromise between compilers and pure

• Aintermediate
high-level language program is translated to an
language that allows easy
interpretation
• Faster than pure interpretation
• Examples
– Perl programs are partially compiled to detect errors
before interpretation
– Initial implementations of Java were hybrid; the
intermediate form, byte code, provides portability to
any machine that has a byte code interpreter and a
run-time system (together, a Java Virtual Machine)
Just-in-Time Implementation Systems

• Initially
language
translate programs to an intermediate

• Then
code
compile intermediate language into machine

• Machine code version is kept for subsequent calls


• JIT systems are widely used for Java programs
• .NET languages are implemented with a JIT system

Summary

• The study of programming languages is valuable


for a number of reasons:
– Increase our capacity to use different constructs
– Enable us to choose languages more intelligently
– Makes learning new languages easier
• Most important criteria for evaluating
programming languages include:
– Readability, writability, reliability, cost

• Major influences on language design have been


machine architecture and software development
methodologies
• Major methods of implementing programming
languages: compilation, interpretation, and hybrid

You might also like