28
Programming Languages and Design Lecture 1 Introduction to Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern University, Houston January, 2008

Programming Languages and Design Lecture 1 Introduction to Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern University,

Embed Size (px)

Citation preview

Programming Languages and Design

Lecture 1 Introduction to Programming Languages

Instructor: Li Ma

Department of Computer ScienceTexas Southern University, Houston

January, 2008

2

Structure of the Lectures

Review of the last lectureSummary of what will be coveredMain contentsSummary of what was coveredSuggestions for the lecture

3

Homework

GoalsLearn programming techniquesReinforce the lecture materialEvaluate your comprehension

Exercises and ProblemsUnderstand concepts and put them in practice

A good preparation for the exams!

4

Some Course Goals

Programming Language ConceptsLearn useful concepts and programming methods Understand the languages you use, by comparisonAppreciate history, diversity of ideas in programmingBe prepared for new programming methods,

paradigms, toolsLanguage design and implementation trade-off

Every convenience has its costRecognize the cost of presenting an abstract view of

machineUnderstand trade-offs in programming language design

5

Computer and Programming

The Computer Age did not really begin until the first computer was made available to the public in 1951 (Seyed. H. Roosta)

Modern computers are highly complex system Hardware Operating System Middleware Application layers

Programming a computer is primarily designing and using abstractions to achieve new goals Enormous number of abstractions work together in a highly

organized manner

6

Abstractions

Eliminate detail unnecessary for solving a particular problemComplexity is hidden

Open build upon one anotherAllow us to solve increasingly complex problems

Modern software’s complexity has no precedentAbstractions are absolutely necessary to manage this

complexity

7

Languages as Abstractions

Human languages are a tool for abstracting thoughtExample: “When I am warm I turn on the fan.”

A statement communicates a simple intentionThe cognitive and neurological conditions from which the

intention arose are most likely too complex for anyone to understand

Meaning of the statement is left to the understanding of the individual who utters it and ones who hear it

8

Languages as Abstractions (cont’)

Programming Languages “Conceptual universe” (Perlis)

Framework for problem-solving

A software tool for abstracting computation Interface between clients and lower-level facilities

(Implementation)Clients are usually humans or their programsLower-level facilities can be files or operating systems

Example: if (temperature() > 30.0) { turn_on_fan(); }A statement involves a complex, but concrete sequence of actionsMeaning of the statement is fixed by the formal semantics of the

programming language and by the implementations of the functions

9

Evolution of ProgrammingLanguages

HardwareMachine codeAssemblyMacro AssemblyFORTRAN 1954etc.

Programming in machine code or Assembly is way too tedious/error-prone

10

History of ProgrammingLanguages

See the poster from O’Reilly

11

Why So Many Languages?

EvolutionFrom goto to loops, case statements

Personal PreferenceSyntaxLoops vs. recursionPointers vs. recursive data types

Special Purposes

12

Application Domains

Scientific applications (Fortran, TCE)Business applications (Cobol)Artificial intelligence (LISP)Systems programming (C, C++)Web service programming (Java, C#)Very High-Level Languages (perl)Special purpose languages (make, sh)

13

What Makes a Language Succeed?

Expressive PowerEase of Use for NoviceEase of ImplementationOpen SourceAvailability of Compilers, LibrariesEconomics, Patronage, InertiaSyntax that looks like C

14

Language Design Issues

ReadabilityAbstractions (functions, classes)Orthogonality (no special cases)Reliability (type checking)Cost (training programmers)

15

Why Do We Study Programming Languages?

Understand obscure language featuresChoose among ways to express ideasMake good use of debuggers, other toolsSimulate nice features in other languagesChoose appropriate language for problemLearn new languages fasterDesign simple languages

16

Computation Models

A computation model is a formal system that defines a language and how sentences of the language are executed by the abstract machinei.e. how computations are done

A programming paradigm is a style of programming a computer A set of programming techniques and design

principles to write programs in a languageBuilt on top of a computation model

17

Computation Models and Programming ParadigmsDeclarative Programming

Functional or logic programmingProcedural/Imperative Programming Object-Oriented ProgrammingConcurrent Programming

Multiple independent processes (running on the same CPU or distributed across multiple CPUs/computers)

Communication between processes via DataflowExchanging messagesSharing state

18

Languages for Programming ParadigmsFunctional programming

LISP/Scheme, ML, HaskellLogic programming

Prolog, SQL, Microsoft ExcelImperative programming

Fortran, Pascal, Basic, CObject-Oriented programming

Smalltalk, C++, Java, CLOSConcurrent programming for real-time systems

Erlang

19

Models with Which You Are Already Familiar

You already know Java, which supportsProgramming with state

(Procedural/Imperative programming)Object-oriented programming

It is clear that these two models are important!

20

Languages in Common Use

Compiled by François Labelle from statistics on open-source projects at SourceForge

21

Questions Worth Discussing for Programming LanguagesWhat is the structure (syntax) and meaning (semantics)

of the programming language constructs?How does the compiler writer deal with these constructs

in compilation? Is the programming language good for the programmer?

Easy to use? Expressive power? Readable? Easy to detect programming error?

22

What’s New in Programming LanguagesCommercial trend over past 5 years

Increasing use of type-safe languages: Java, C#, … Scripting languages, other languages for web applications

Teaching trends Java replacing C as most common introduction language

Less emphasis on how data, control represented in machine

Research and development trends Modularity

Java, C++: standardization of new module features Program analysis

Automated error detection, programming environment, compilation Isolation and security

Sandboxing, language-based security, …

23

What’s Worth Studying?

Dominant languages and paradigmsC, C++, Java Imperative and Object-oriented languages

Important implementation ideasPerformance challenges

Concurrency

Design tradeoffsConcepts that research community is exploring

for new programming languages and tools

24

Fundamental Concepts of Programming LanguagesVariables

declaration, binding, identifier, variable in memory, scope of a variable

Identifier, Literals, ExpressionsData types

integers, floating-point numbers, …Data structures

stack, queue, list, …Control structures

loops, conditional statements

25

Fundamental Concepts of Programming Languages (cont’)

Function, procedures and parameter passingdefinition, call (application)

RecursionFor example, inductive definition of a function

Block structuresRuntime store organization

26

Implementation Methods

Interpretation (early Lisp)

Compilation (C, ML)

CompilerSource Program

Target Program

Target Program

Input

Output

Interpreter

Source Program

Input

Output

27

Implementation Methods (cont’)

Hybrid Systems (early Java)

Translator

Source Program

Intermediate Program

Virtual Machine

Input

Output

Intermediate Program

28

Overview of Compilation

Scanner (Lexical Analysis)

Parser (Syntax Analysis)

Semantic Analysis and Intermediate Code Generation

Machine-Independent Code Improvement (optional)

Target Code Generation

Machine-Specific Code Improvement (optional)

Symbol Table

Character Stream

Token Stream

Parse Tree

Abstract Syntax Tree or Other Intermediate Form

Assembly or Machine Language or Other Target Language

Modified Target Language

Modified Intermediate Form