CS 363 Comparative Programming Languages Introduction.

21
CS 363 Comparative Programming Languages Introduction

Transcript of CS 363 Comparative Programming Languages Introduction.

CS 363 Comparative Programming Languages

Introduction

CS 363 GMU Spring 2005 2

Chapter 1 Topics

• Motivation

• Language Paradigms

• Programming Domains

• Language Design and Evaluation– Influences– Tradeoffs

• Implementation options

CS 363 GMU Spring 2005 3

Programming Languages

Sebesta Fig. 1.2

Languages are • an abstraction used by the programmer to express an idea• interface to the underlying computer architecture

CS 363 GMU Spring 2005 4

Why study Programming Languages?

• Increases ability to express ideas in a language– wide variety of programming features

• Improves ability to choose appropriate language– Each language has strengths and weaknesses in term of

expressing ideas

• Improves ability to learn new languages– different paradigms, different features– What does the future of programming languages hold?

• Improves understanding of significance of implementation

• Provides ability to design new languages– Domain specific languages increasingly popular

CS 363 GMU Spring 2005 5

Language Paradigms

• Imperative– Central features are variables, assignment statements, and

iteration– Ex: C, Pascal, Fortran

• Object-oriented– Encapsulate data objects with processing– Inheritance and dynamic type binding– Grew out of imperative languages– Ex: C++, Java

• Functional– Main means of making computations is by applying functions to

given parameters– Ex: LISP, Scheme, Haskell

CS 363 GMU Spring 2005 6

Language Paradigms• Logic

– Declarative Rule-based – implicit control flow– Ex: Prolog

• Dataflow– Declarative Model computation as information flow – implicit control

flow– Inherently parallel

• Event-Driven– Continuous loop with handlers that respond to events generated in

unpredictable order, such as mouse clicks– Often an add-on feature– Ex: Java

• Concurrent– Multiple interacting processes– Often an add-on feature– Ex: Java, High Performance Fortran (HPF), Linda

CS 363 GMU Spring 2005 7

Programming Domains• Scientific applications

– One of the earliest uses of computers– Large number of floating point computations– Long running– Imperative (Fortran, C) and Parallel (High Performance Fortran)

• Business applications– Produce reports, use decimal numbers and characters– Increasingly toward web-centric (Java, Perl, XML-based languages)– Imperative (Cobol) and domain specific (SQL)

• Artificial intelligence– Model human behavior and deduction– Symbol manipulation– Functional (Lisp) and Logical (Prolog)

• Systems programming– Need efficiency because of continuous use– Parallel and event driven– Imperative (C)

• …

CS 363 GMU Spring 2005 8

Language Design

• Principles of Design

• Influences on Design

• Evaluation of a design

CS 363 GMU Spring 2005 9

Principles of Language DesignBasic Vocabulary:• Syntax – what constitutes a correctly written program• Type Systems and Semantics – these allow us to

provide a meaning to a syntatically correct program. • Memory management – data mapping, static and

dynamic memory, stack, heap, object lifetime, garbage collection

• Exception handling – how to deal with unexpected problems at runtime

CS 363 GMU Spring 2005 10

Influences on Language Design• Von Neumann

architecture: 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

CS 363 GMU Spring 2005 11

Influences on Language Design

• Programming methodologies– 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

CS 363 GMU Spring 2005 12

Influences on Program Design

• Special Purpose (Domain Specific)– Abstraction closer to problem domain

• Personal Preferences– terse vs. verbose– recursion vs. iteration– user controlled vs. language controlled

dynamic allocation

CS 363 GMU Spring 2005 13

Language Evaluation Criteria• Readability – most important!

– Overall simplicity– Orthogonality – A relatively small set of primitive constructs

that can be combined in a relatively small number of ways• Makes the language easy to learn and read

• Meaning is context independent

• Every possible combination is legal

• Lack of orthogonality leads to exceptions to rules

– Control statements– Defining data types and structures– Syntax considerations: identifier forms, special words,

meaning

CS 363 GMU Spring 2005 14

Language Evaluation Criteria• Writability

– Simplicity and orthogonality– Support for abstraction– Expressivity

• Reliability– Conformance to specs.– Type checking– Exception handling– Aliasing– Readability and writability

CS 363 GMU Spring 2005 15

Language Evaluation Criteria• Cost

– Categories• Training programmers to use language• Writing programs• Compiling programs• Executing programs• Language implementation system• Maintaining programs (readability)

• Safety – prevention of unchecked errors• Others: portability, generality, well-definedness

CS 363 GMU Spring 2005 16

Language Implementation Options

• Compilers

• Interpreters

• Hybrid options

CS 363 GMU Spring 2005 17

Compilers

Scanner(lexical

analysis)

Parser(syntax

analysis)

CodeOptimizer

SemanticAnalysis

(IC generator)

CodeGenerator

SymbolTable

Sourcelanguage

tokens Syntacticstructure

Syntactic/semanticstructure

Machinelanguage

Computer

Input Data

Output

CS 363 GMU Spring 2005 18

Interpreters

Sourcelanguage Interpreter

Input Data

Output

CS 363 GMU Spring 2005 19

Compilation vs. Interpretation

Compilation:• Translate HL code

directly into machine• Translation can be

slow• Resulting code is

fast (typically optimized)

Interpretation:• Execute HL code

directly• No translation costs• Execution can be

slow

CS 363 GMU Spring 2005 20

Hybrid

Scanner(lexical

analysis)

Parser(syntax

analysis)

SemanticAnalysis

(IC generator)

SymbolTable

Sourcelanguage

tokens Syntacticstructure

Intermediate Code

Interpreter

Input Data

Output

CS 363 GMU Spring 2005 21

What makes a language successful?

• Expressive Power– Included features impact programmer use

• Ease of use for Novice– Pascal, Basic, Logo

• Ease of Implementation

• Excellent Compilers

• Economics, Patronage, Legacy