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

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

Dec 27, 2015

Download

Documents

Sheila Sparks
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Programming Languages and Design Lecture 1 Introduction to Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern University,

Programming Languages and Design

Lecture 1 Introduction to Programming Languages

Instructor: Li Ma

Department of Computer ScienceTexas Southern University, Houston

January, 2008

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

2

Structure of the Lectures

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

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

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!

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

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

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

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

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

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

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

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

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

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

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

9

Evolution of ProgrammingLanguages

HardwareMachine codeAssemblyMacro AssemblyFORTRAN 1954etc.

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

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

10

History of ProgrammingLanguages

See the poster from O’Reilly

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

11

Why So Many Languages?

EvolutionFrom goto to loops, case statements

Personal PreferenceSyntaxLoops vs. recursionPointers vs. recursive data types

Special Purposes

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

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)

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

13

What Makes a Language Succeed?

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

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

14

Language Design Issues

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

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

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

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

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

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

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

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

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

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

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!

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

20

Languages in Common Use

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

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

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?

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

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, …

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

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

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

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

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

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

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

26

Implementation Methods

Interpretation (early Lisp)

Compilation (C, ML)

CompilerSource Program

Target Program

Target Program

Input

Output

Interpreter

Source Program

Input

Output

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

27

Implementation Methods (cont’)

Hybrid Systems (early Java)

Translator

Source Program

Intermediate Program

Virtual Machine

Input

Output

Intermediate Program

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

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