37
Copyright © 2006 The McGraw-Hill Companies, Inc. CS 424/524 PROGRAMMING LANGUAGES Overview

CS 424/524 PROGRAMMING LANGUAGES

Embed Size (px)

DESCRIPTION

CS 424/524 PROGRAMMING LANGUAGES. Overview. Course Organization. Class meetings: MW 3:55pm-5:15pm TH N326 Instructor Information: Dr. Mary Ellen Weisskopf Email: [email protected] Phone number: (256) 824-6306 Office: Technology Hall, N300A. - PowerPoint PPT Presentation

Citation preview

Page 1: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

CS 424/524PROGRAMMING LANGUAGES

Overview

Page 2: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Course Organization

Class meetings: • MW 3:55pm-5:15pm• TH N326

Instructor Information: • Dr. Mary Ellen Weisskopf • Email: [email protected]• Phone number: (256) 824-6306• Office: Technology Hall, N300A

Page 3: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Programming Languages2nd edition

Tucker and Noonan

Chapter 1Overview

A good programming language is a conceptual universe for thinking about programming.

A. Perlis

Page 4: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Contents

1.1 Principles1.2 Paradigms1.3 Special Topics1.4 A Brief History1.5 On Language Design

1.5.1 Design Constraints1.5.2 Outcomes and Goals

1.6 Compilers, Interpreters, and Virtual Machines

Page 5: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Programming languages have several properties:

– Syntax

– Names & types

– Semantics

For any language:

– Its designers must define these properties

– Its programmers must master these properties

1.1 Principles

Page 6: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Syntax• The syntax of a programming language is a precise

description of all its grammatically correct programs.

– Rules that define how symbols can be combined to create

legal language statements and how the statements can be

combined into programs

When studying syntax, we ask questions like:

– What is the grammar for the language? (grammar = rules)

– What is the basic vocabulary? (operators/variables/…)

– How are syntax errors detected?

Page 7: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Names

Various kinds of entities in a program have names:

variables, functions, parameters, classes, objects, …

Named entities are bound in a running program to:

– Scope

– Visibility

– Type

– Lifetime

Page 8: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Types

A type is a collection of values and a collection of operations on those values.

– Simple types: numbers, characters, booleans, …

– Structured types: Strings, lists, trees, hash tables, …

A language’s type system can help to:

– Determine legal operations

– Detect type errors

Page 9: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Semantics

A program’s meaning is called its semantics.

In studying semantics, we ask questions like:

– When a program is running, what happens to the values of

the variables?

– What does each statement mean?

– What underlying model governs the run-time behavior of a

function call?

– How are objects allocated to memory at run-time?

• Run-time stack, heap

• Related to function behavior & implementation

Page 10: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

A programming paradigm is a pattern of problem-solving thought that underlies a particular category of programs and languages.

There are four main programming paradigms:

– Imperative

– Object-oriented

– Functional

– Logic (declarative)

1.2 Paradigms

Page 11: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Imperative Paradigm

Follows the classic von Neumann-Eckert model:

– Program and data are indistinguishable in memory– Program = a sequence of commands– State = values of all variables when program runs

Large programs use procedural abstraction as a way to organize individual imperative statements.

Example imperative languages:

– Cobol, Fortran, C, Ada, Perl, …

Page 12: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

The von Neumann-Eckert Model

Page 13: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Object-oriented (OO) Paradigm

An OO Program consists of a collection of objects that interact by passing messages that transform object state.

OO languages are characterized by– Data encapsulation/abstraction– Inheritance– Polymorphism

Example OO languages: Smalltalk, Java, C++, C#, and Python

Page 14: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Functional ParadigmFunctional programming models a computation as a

collection of mathematical functions.

– Input = domain

– Output = range

Functional languages are characterized by:

– Functional composition

– Recursion

Example functional languages:

– Lisp, Scheme, ML, Haskell, …

Page 15: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Logic Paradigm (Declarative)

Logic programming declares what outcome the program should accomplish, rather than how it should be accomplished.

Rule-based

When studying logic programming we see:

– Programs as sets of constraints on a problem

– Programs that achieve all possible solutions

– Programs that are “nondeterministic”

Example logic programming languages: Prolog

Page 16: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

• Event handling

– E.g., GUIs, home security systems, monitoring systems of

various kinds

• Concurrency

– e.g., Client-server programs, rendering (in computer

graphics)

• Correctness

– How can we prove that a program does what it is

supposed to do under all circumstances?

1.3 Special Topics

Page 17: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

How and when did programming languages evolve?

What communities have developed and used them?

– Artificial Intelligence

– Computer Science Education

– Science and Engineering

– Information Systems

– Systems and Networks

– World Wide Web

1.4 A Brief History

Page 18: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Page 19: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

1.5.1 – Design Constraints

– Computer architecture

– Technical setting

– Standards

– Legacy systems

1.5 On Language Design

Page 20: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Design Outcomes and Goals

• Outcome: What makes a language successful?

• Goals: What characteristics make a programming language “good” ?

Page 21: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

What Makes A Successful Language?

Key characteristics:

– Simplicity and readability

– Clarity about binding

– Reliability

– Support

– Abstraction

– Orthogonality

– Efficient implementation

Page 22: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Simplicity (Writeability) and Readability• Easy to learn

– Don’t include too many features– Don’t make it too complex

• Simple conceptual model of semantics. • Uniformity: Similar syntax => similar semantics. • Lexical and syntactic conventions:

– descriptive identifier names, blocking of compound

statements

• Readability is not synonymous with wordiness: COBOL is not easier to read.

Page 23: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

A language element is bound to a property at the time that property is defined for it.

So a binding is the association between an object and a property of that object

– Examples:

• a variable and its type

• a variable and its value

Clarity about Binding

Page 24: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Major Binding Times• Major binding times

– Language definition time– Language implementation time– Program writing time– Compile time– Load time– Execution time

• In general,– Early binding takes place at compile-time or before– Late binding takes place at load time or run time

Page 25: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Reliability

A language is reliable if:

– Program behavior is the same on different platforms

• E.g., early versions of Fortran weren’t

– Type errors are detected

• E.g., C vs Haskell

– Semantic errors are properly trapped

• E.g., C vs C++ or Java

– Memory leaks are prevented

• E.g., C vs Java

Page 26: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Language Support

• Accessible (public domain) compilers/interpreters

• Good texts and tutorials

• Wide community of users

• Integrated with development environments (IDEs)

Page 27: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Abstraction in Programming

• Data

– Programmer-defined types/classes

– Class libraries

• Procedural

– Programmer-defined functions

– Standard function libraries

• Supports code reuse; simplifies the programming process.

Page 28: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Orthogonality• A language is orthogonal if it is built on a small,

mutually independent set of primitive operations.

– You can use one feature without worrying about how it

affects others

– Rules don’t have exceptions;

– Context doesn’t affect the behavior of a language feature

(e.g., a reserved word doesn’t have different meanings

based on where it’s used).

Page 29: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Orthogonality

• Non-orthogonal examples (rule exceptions):

– In C, a function can return a struct, but not an array.

Orthogonality => return value can be from any type.

– Most imperative languages don’t allow function

definitions to be passed as arguments

• Orthogonal languages are in general easier to read and write

Page 30: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Efficient Implementation

• Embedded systems

– Real-time responsiveness (e.g., navigation)

– Failures of early Ada implementations – real time?

• Web applications

– Responsiveness to users (e.g., Google search)

• Corporate database applications

– Efficient search and updating

Page 31: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Compiler – produces machine code

Interpreter – executes instructions directly

• Example compiled languages:

– Fortran, Cobol, C, C++

• Example interpreted languages:

– Scheme, Haskell, Python

• Hybrid compilation/interpretation: Java

– The Java Virtual Machine (JVM)

1.6 Compilers and Virtual Machines

Page 32: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Translation/Execution – Compiler

Page 33: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Compilers

• Translates source code program into object code (machine language).

• Object code can be executed without repeating the compilation process.

Page 34: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Translation/Execution – Interpreter

Page 35: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Interpreters

• No object code.

• Interpretive routines

– Examine the program. When an action is recognized,

do it (by calling one of the routines).

• Slower execution (than with compilation)

• Better interactive development environment.

Page 36: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

Virtual Machines & Interpreters

• Some languages (e.g., Java) are compiled to machine code (byte code) that runs on a virtual machine (the JVM).

• To run Java programs install a JVM for your machine that interprets the byte code.

• Benefit: compiler is platform independent

• Disdadvantage: slow

• Solution: JIT compilers

Page 37: CS 424/524 PROGRAMMING LANGUAGES

Copyright © 2006 The McGraw-Hill Companies, Inc.

• Programming language principles

– Grammars, syntax, semantics

• What makes a language successful?• Reliable, readable, writeable

• Supported by simplicity, orthogonality, efficiency, support, …

• Paradigms

– Imperative, object-oriented, functional, logic

• Language implementation

– Compilers & interpreters

SUMMARYSummary