0% found this document useful (0 votes)
13 views

intro_prelim

Uploaded by

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

intro_prelim

Uploaded by

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

Week 1 - lecture

What What
is a Programming Language?
is Programming?
Languages in CS
Programming Languages
Java, C, Python, Haskell, Prolog, …
Cover of the
Communications of
Domain-Specific Languages
The ACM 1961 SQL, HTML, R, LaTex, Excel, …
Metalanguages
BNF (grammars), Rule Systems, ..
Formal Models
Automata, Logic(s), …
Science vs. Engineering
Scienc
Newton’s Laws Principles of e
Maxwell’s Life Computational
Equations Biolo Limits

Phys gy Computer
Science
Programming
ics Lang
Fundamentals

Mechani Agricult Medici


cal ure ne
Civil Engineer Software
Engineer ing Engineering
ing Programm
ing

Applied Knowledge
Programming vs Computer Science
What
What exactlyisis CS 381 About?
a programming language?

Recursion?
Functional
Programming
int x;
int f(int z) {x:= f(y)…};
{ int x;
f(3)
Value or Semantic
} Address? s
When to Based on
evaluate? what?
x:= f(y) * Parameter
g(z-1) Abstract Syntax
Which Passing AST
x? “Determine” value of RHS and
Scoping “assign it” to x
How to express
computation?
Programming Paradigms
The Role of Haskell in CS 381
Example of a non-imperative programming
paradigm
Tool for describing language concepts: syntax,
semantics, scope, typing
Executable PL Theory
Impacts of Languages & Programs
Practical Benefits of Studying
Programming Languages
Increased ability to express ideas
Improved background for choosing appropriate
languages
Increased ability to learn new languages
Better understanding of significance of
implementation
Better use of languages that are already known
Become more productive
Genealogy of Common Languages
Popularity
RedMonk has a language ranking scheme that combines pull requests on GitHub and
questions on StackOverflow. June 2021 .
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., HTML), scripting (e.g., PHP),
general-purpose (e.g., 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)
Evaluation Criteria: Readability
Overall simplicity
A manageable set of features and constructs
Minimum feature multiplicity
Minimum operator overloading

i = i +1
i += 1
i++
++i

Don’t overload (+) to mean


matrix multiplication
Evaluation Criteria: Readability
Orthogonality
A relatively small set of primitive constructs can be combined in a
relatively small number of ways
Every possible combination is legal
Few exceptions

Example in C – Data types structs and arrays


Structs can be returned by a function but an array can’t
Parameters are passed by value unless they are arrays then they have to
be passed by “address” reference.
Evaluation Criteria: Readability
Data types
Adequate predefined data types
Example: Boolean

Syntax considerations
Identifier forms: flexible composition
Special words and methods of forming compound statements
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
Strength and number of operators and predefined functions
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
Evaluation Criteria: Cost
Training programmers to use the language
Writing programs (closeness to particular
applications)
Executing programs
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
Program Design Methodologies
New software development methodologies (e.g.,
object-oriented software development) led to
new programming paradigms and by extension,
new programming languages
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
The von Neumann Architecture
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
Language Paradigms
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: Haskell, LISP, Scheme, ML, F#
Logic
Rule-based (rules are specified in no particular order)
Example: Prolog
Markup/programming hybrid
Markup languages extended to support some programming
Examples: JSTL, XML, HTML, LaTex
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
Implementation Methods
Compilation
Programs are translated into machine language; includes JIT systems
Use: Large commercial applications

Pure Interpretation
Programs are interpreted by another program known as an
interpreter
Use: Small programs or when efficiency is not an issue

Hybrid Implementation Systems


A compromise between compilers and pure interpreters
Use: Small and medium systems when efficiency is not the first
concern
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
The Compilation Process (CS 480)
Additional Compilation Terminologies

Load module (executable image): the


user and system code together
Linking and loading: the process of
collecting system program units and linking
them to a user program
Von Neumann Bottleneck
Connection speed between a computer’s
memory and its processor determines the
speed of a computer
Program instructions often can be executed
much faster than the speed of the
connection; the connection speed thus results
in a bottleneck
Known as the von Neumann bottleneck;
it is the primary limiting factor in the speed of
computers
Pure Interpretation
No translation
Easier implementation of programs (run-time errors can
easily and immediately be displayed)
Slower execution (10 to 100 times slower than compiled
programs)
Often requires more space
Now rare for traditional high-level languages
Significant comeback with some Web scripting languages
(e.g., JavaScript, PHP)
Pure Interpretation Process
Hybrid Implementation Systems
A compromise between compilers and pure
interpreters
A high-level language program is translated
to an intermediate 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, these are called Java
Virtual Machine)
Hybrid Implementation Process
Just-in-Time Implementation Systems

Initially translate programs to an intermediate language


Then compile the intermediate language of the subprograms
into machine code when they are called
Machine code version is kept for subsequent calls
JIT systems are widely used for Java programs
.NET languages are implemented with a JIT system
In essence, JIT systems are delayed compilers
Preprocessors
Preprocessor macros (instructions) are
commonly used to specify that code from
another file is to be included
A preprocessor processes a program
immediately before the program is compiled
to expand embedded preprocessor macros
A well-known example: C preprocessor
expands #include, #define, and similar
macros
Chapter 2

Evolution of the Major Programming


Languages
Genealogy of Common Languages
IBM 704 and Fortran
Fortran 0: 1954 - not implemented
Fortran I:1957
Designed for the new IBM 704, which had index registers and floating
point hardware
- This led to the idea of compiled programming languages,
because there was no place to hide the cost of interpretation (no
floating-point software)

Environment of development
Computers were small and unreliable
Applications were scientific
No programming methodology or tools
Machine efficiency was the most important concern
Fortran I Overview
First implemented version of Fortran
Names could have up to six characters
Post-test counting loop (DO)
Formatted I/O
User-defined subprograms
Three-way selection statement (arithmetic IF)
No data typing statements
Fortran 77
Became the new standard in 1978
Character string handling
Logical loop control statement
IF-THEN-ELSE statement
Fortran 90
Most significant changes from Fortran 77
Modules
Dynamic arrays
Pointers
Recursion
CASE statement
Parameter type checking
Latest versions of Fortran
Fortran 95 – relatively minor additions, plus
some deletions
Fortran 2003 – support for OOP, procedure
pointers, interoperability with C
Fortran 2008 – blocks for local scopes, co-
arrays, Do Concurrent
Fortran Evaluation
Highly optimizing compilers (all versions
before 90)
Types and storage of all variables are fixed before
run time
Dramatically changed forever the way
computers are used
Functional Programming: Lisp
LISt Processing language
Designed at MIT by McCarthy
AI research needed a language to
Process data in lists (rather than arrays)
Symbolic computation (rather than numeric)
Only two data types: atoms and lists
Syntax is based on lambda calculus
Lisp Evaluation
Pioneered functional programming
No need for variables or assignment
Control via recursion and conditional expressions
Still the dominant language for AI
Common Lisp and Scheme are contemporary
dialects of Lisp
ML, Haskell, and F# are also functional
programming languages, but use very
different syntax
Scheme

Developed at MIT in mid 1970s


Small
Extensive use of static scoping
Functions as first-class entities
Simple syntax (and small size) make it ideal for
educational applications
ALGOL 60 Overview
Modified ALGOL 58 at 6-day meeting in Paris
New features
Block structure (local scope)
Two parameter passing methods
Subprogram recursion
Stack-dynamic arrays

Still no I/O and no string handling


Computerizing Business Records: COBOL

Environment of development
UNIVAC was beginning to use FLOW-MATIC
USAF was beginning to use AIMACO
IBM was developing COMTRAN
COBOL Historical Background
Based on FLOW-MATIC
FLOW-MATIC features
Names up to 12 characters, with embedded
hyphens
English names for arithmetic operators (no
arithmetic expressions)
Data and code were completely separate
The first word in every statement was a verb
COBOL Design Process
First Design Meeting (Pentagon) - May 1959
Design goals
Must look like simple English
Must be easy to use, even if that means it will be less powerful
Must broaden the base of computer users
Must not be biased by current compiler problems
Design committee members were all from computer
manufacturers and DoD branches
Design Problems: arithmetic expressions? subscripts? Fights
among manufacturers
COBOL Evaluation
Contributions
First macro facility in a high-level language
Hierarchical data structures (records)
Nested selection statements
Long names (up to 30 characters), with hyphens
Separate data division
COBOL: DoD Influence
First language required by DoD
would have failed without DoD
Still the most widely used business
applications language
SNOBOL
Designed as a string manipulation language at
Bell Labs by Farber, Griswold, and Polensky in
1964
Powerful operators for string pattern
matching
Slower than alternative languages (and thus
no longer used for writing editors)
Still used for certain text processing tasks
The Beginning of Data Abstraction: SIMULA 67

Designed primarily for system simulation


in Norway by Nygaard and Dahl
Based on ALGOL 60 and SIMULA I
Primary Contributions
Coroutines - a kind of subprogram
Classes, objects, and inheritance
Orthogonal Design: ALGOL 68
From the continued development of ALGOL
60 but not a superset of that language
Source of several new ideas (even though the
language itself never achieved widespread
use)
Design is based on the concept of
orthogonality
A few basic concepts, plus a few combining
mechanisms
ALGOL 68 Evaluation
Contributions
User-defined data structures
Reference types
Dynamic arrays (called flex arrays)

Comments
Less usage than ALGOL 60
Had strong influence on subsequent languages,
especially Pascal, C, and Ada
Pascal - 1971
Developed by Wirth (a former member of the
ALGOL 68 committee)
Designed for teaching structured
programming
Small, simple, nothing really new
Largest impact was on teaching programming
From mid-1970s until the late 1990s, it was the
most widely used language for teaching
programming
C - 1972
Designed for systems programming (at Bell
Labs by Dennis Richie)
Evolved primarily from BCLP and B, but also
ALGOL 68
Powerful set of operators, but poor type
checking
Initially spread through UNIX
Though designed as a systems language, it has
been used in many application areas
Programming Based on Logic: Prolog
Developed, by Comerauer and Roussel (University of
Aix-Marseille), with help from Kowalski ( University
of Edinburgh)
Based on formal logic
Non-procedural
Can be summarized as being an intelligent database
system that uses an inferencing process to infer the
truth of given queries
Comparatively inefficient
Few application areas
History’s Largest Design Effort: Ada
Huge design effort, involving hundreds of
people, much money, and about eight
years
Sequence of requirements (1975-1978)
(Strawman, Woodman, Tinman, Ironman,
Steelman)
Named Ada after Augusta Ada Byron, the
first programmer
Ada Evaluation
Contributions
Packages - support for data abstraction
Exception handling - elaborate
Generic program units
Concurrency - through the tasking model
Comments
Competitive design
Included all that was then known about software engineering and
language design
First compilers were very difficult; the first really usable compiler came
nearly five years after the language design was completed
Ada 95
Ada 95 (began in 1988)
Support for OOP through type derivation
Better control mechanisms for shared data
New concurrency features
More flexible libraries
Ada 2005
Interfaces and synchronizing interfaces
Popularity suffered because the DoD no
longer requires its use but also because of
popularity of C++
Object-Oriented Programming: Smalltalk

Developed at Xerox PARC, initially by Alan Kay,


later by Adele Goldberg
First full implementation of an object-
oriented language (data abstraction,
inheritance, and dynamic binding)
Pioneered the graphical user interface design
Promoted OOP
Combining Imperative and Object-Oriented
Programming: C++
Developed at Bell Labs by Stroustrup in 1980
Evolved from C and SIMULA 67
Facilities for object-oriented programming, taken partially
from SIMULA 67
A large and complex language, in part because it supports
both procedural and OO programming
Rapidly grew in popularity, along with OOP
ANSI standard approved in November 1997
Microsoft’s version: MC++
Properties, delegates, interfaces, no multiple inheritance
A Related OOP Language
Swift – a replacement for Objective-C
Released in 2014
Two categories of types, classes and struct, like
C#
Used by Apple for systems programs
Delphi – another related language
A hybrid language, like C++
Began as an object-oriented version of Pascal
Designed by Anders Hejlsberg, who also designed
Turbo Pascal and C#
An Imperative-Based Object-Oriented Language:
Java
Developed at Sun in the early 1990s
C and C++ were not satisfactory for embedded
electronic devices
Based on C++
Significantly simplified (does not include
struct, union, enum, pointer arithmetic,
and half of the assignment coercions of C++)
Supports only OOP
Has references, but not pointers
Includes support for applets and a form of
concurrency
Java Evaluation
Eliminated many unsafe features of C++
Supports concurrency
Libraries for applets, GUIs, database access
Portable: Java Virtual Machine concept, JIT
compilers
Widely used for Web programming
Use increased faster than any previous
language
Scripting Languages for the Web
Perl
Designed by Larry Wall—first released in 1987
Variables are statically typed but implicitly declared
Three distinctive namespaces, denoted by the first character of a
variable’s name
Powerful, but somewhat dangerous
Gained widespread use for CGI programming on the Web
Also used for a replacement for UNIX system administration language
JavaScript
Began at Netscape, but later became a joint venture of Netscape and Sun Microsystems
A client-side HTML-embedded scripting language, often used to create dynamic HTML
documents
Purely interpreted
Related to Java only through similar syntax
PHP
PHP: Hypertext Preprocessor, designed by Rasmus Lerdorf
A server-side HTML-embedded scripting language, often used for form processing and
database access through the Web
Purely interpreted
The Flagship .NET Language: C#

Part of the .NET development platform (2000)


Based on C++ , Java, and Delphi
Includes pointers, delegates, properties,
enumeration types, a limited kind of dynamic
typing, and anonymous types
Is evolving rapidly
Summary
Development, development environment,
and evaluation of a number of important
programming languages
Perspective into current issues in language
design

You might also like