Class Orientation and Introduction

Download Report

Transcript Class Orientation and Introduction

Programming Languages and
Design
Lecture 1
Introduction to Programming Languages
Instructor: Li Ma
Department of Computer Science
Texas Southern University, Houston
January, 2008
Structure of the Lectures
 Review of the last lecture
 Summary of what will be covered
 Main contents
 Summary of what was covered
 Suggestions for the lecture
2
Homework
 Goals
Learn programming techniques
Reinforce the lecture material
Evaluate your comprehension
 Exercises and Problems
Understand concepts and put them in practice
 A good preparation for the exams!
3
Some Course Goals
 Programming Language Concepts
Learn useful concepts and programming methods
Understand the languages you use, by comparison
Appreciate history, diversity of ideas in programming
Be prepared for new programming methods,
paradigms, tools
 Language design and implementation trade-off
Every convenience has its cost
 Recognize the cost of presenting an abstract view of
machine
 Understand trade-offs in programming language design
4
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
5
Abstractions
 Eliminate detail unnecessary for solving a
particular problem
Complexity is hidden
 Open build upon one another
Allow us to solve increasingly complex problems
 Modern software’s complexity has no precedent
Abstractions are absolutely necessary to manage this
complexity
6
Languages as Abstractions
 Human languages are a tool for abstracting
thought
Example: “When I am warm I turn on the fan.”
 A statement communicates a simple intention
 The 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
7
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 programs
 Lower-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 actions
 Meaning of the statement is fixed by the formal semantics of the
programming language and by the implementations of the functions
8
Evolution of Programming
Languages
 Hardware
 Machine code
 Assembly
 Macro Assembly
 FORTRAN 1954
 etc.
Programming in machine code or Assembly is way
too tedious/error-prone
9
History of Programming
Languages
 See the poster from O’Reilly
10
Why So Many Languages?
 Evolution
From goto to loops, case statements
 Personal Preference
Syntax
Loops vs. recursion
Pointers vs. recursive data types
 Special Purposes
11
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)
12
What Makes a Language Succeed?
 Expressive Power
 Ease of Use for Novice
 Ease of Implementation
 Open Source
 Availability of Compilers, Libraries
 Economics, Patronage, Inertia
 Syntax that looks like C
13
Language Design Issues
 Readability
 Abstractions (functions, classes)
 Orthogonality (no special cases)
 Reliability (type checking)
 Cost (training programmers)
14
Why Do We Study Programming
Languages?
 Understand obscure language features
 Choose among ways to express ideas
 Make good use of debuggers, other tools
 Simulate nice features in other languages
 Choose appropriate language for problem
 Learn new languages faster
 Design simple languages
15
Computation Models
 A computation model is a formal system that
defines a language and how sentences of the
language are executed by the abstract machine
i.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 language
Built on top of a computation model
16
Computation Models and Programming
Paradigms
 Declarative Programming
Functional or logic programming
 Procedural/Imperative Programming
 Object-Oriented Programming
 Concurrent Programming
Multiple independent processes (running on the same
CPU or distributed across multiple CPUs/computers)
Communication between processes via
Dataflow
Exchanging messages
Sharing state
17
Languages for Programming
Paradigms
 Functional programming
LISP/Scheme, ML, Haskell
 Logic programming
Prolog, SQL, Microsoft Excel
 Imperative programming
Fortran, Pascal, Basic, C
 Object-Oriented programming
Smalltalk, C++, Java, CLOS
 Concurrent programming for real-time systems
Erlang
18
Models with Which You Are Already
Familiar
 You already know Java, which supports
Programming with state
(Procedural/Imperative programming)
Object-oriented programming
 It is clear that these two models are important!
19
Languages in Common Use
20
Compiled by François Labelle from statistics on open-source projects at SourceForge
Questions Worth Discussing for
Programming Languages
 What 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?
21
What’s New in Programming
Languages
 Commercial 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, …
22
What’s Worth Studying?
 Dominant languages and paradigms
C, C++, Java
Imperative and Object-oriented languages
 Important implementation ideas
 Performance challenges
Concurrency
 Design tradeoffs
 Concepts that research community is exploring
for new programming languages and tools
23
Fundamental Concepts of
Programming Languages
 Variables
declaration, binding, identifier, variable in memory,
scope of a variable
 Identifier, Literals, Expressions
 Data types
integers, floating-point numbers, …
 Data structures
stack, queue, list, …
 Control structures
loops, conditional statements
24
Fundamental Concepts of
Programming Languages (cont’)
 Function, procedures and parameter passing
definition, call (application)
 Recursion
For example, inductive definition of a function
 Block structures
 Runtime store organization
25
Implementation Methods
 Interpretation (early Lisp)
Source Program
Interpreter
Output
Input
 Compilation (C, ML)
Source
Program
Input
Compiler
Target Program
Target
Program
Output
26
Implementation Methods (cont’)
 Hybrid Systems (early Java)
Source
Program
Translator
Intermediate
Program
Intermediate
Program
Virtual Machine
Output
Input
27
Overview of Compilation
Character Stream
Scanner (Lexical Analysis)
Token Stream
Parser (Syntax Analysis)
Parse Tree
Semantic Analysis and Intermediate Code Generation
Abstract Syntax Tree or Other
Intermediate Form
Machine-Independent Code Improvement (optional)
Modified Intermediate Form
Target Code Generation
Assembly or Machine Language or
Other Target Language
Machine-Specific Code Improvement (optional)
Modified Target Language
Symbol Table
28