Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu...

46
Chapter 9: The Tower of Babel 國國國國國國國國 國國國國國國國 國國國 (Chuan-Yu Chang ) 國國 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: [email protected]

Transcript of Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu...

Page 1: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

Chapter 9: The Tower of BabelChapter 9: The Tower of Babel

國立雲林科技大學 資訊工程研究所張傳育 (Chuan-Yu Chang ) 博士Office: ES 709

TEL: 05-5342601 ext. 4337

E-mail: [email protected]

國立雲林科技大學 資訊工程研究所張傳育 (Chuan-Yu Chang ) 博士Office: ES 709

TEL: 05-5342601 ext. 4337

E-mail: [email protected]

Page 2: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

22

ObjectivesObjectives

In this chapter, you will learn about:

Procedural languages

Special-purpose languages

Alternative programming paradigms

Page 3: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

33

Why Babel?Why Babel?

Story of Tower of Babel

A biblical story about people suddenly starting to speak different languages and no longer being able to communicate with each other

Multiple programming languages

Each language designed for specific needs

One language may be better suited than others for writing certain kinds of programs

Page 4: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

44

Procedural LanguagesProcedural Languages

Also called imperative languages

A program consists of sequences of statements that manipulate data items

They change the contents of memory cells.

The programmer devises the step by step sequence of “imperative commands”

Procedural languages follow directly from the Von Neumann architecture, (an architecture characterized by sequential fetch-decode-execute cycles.)

All procedural languages that tell the computer in a step by step fashion how to manipulate the contents of memory locations.

Page 5: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

55

FORTRANFORTRAN

FORTRAN is from FORmula TRANslation

Developed in the mid-1950s by a group at IBM headed by John Backus

First high-level programming language

Remains an effective language for engineering applications

Page 6: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

66

FORTRAN (continued)FORTRAN (continued)

Designed for numerical computations

Allows concise mathematical notation and a number of mathematical functions

Another goal: optimize the object code

External libraries of code modules that are separately compiled and used by a program

Page 7: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

77

COBOLCOBOL

COBOL derives from COmmon Business-Oriented Language

Developed in 1959–1960 by a group headed by Grace Hopper of the U.S. Navy

Designed to serve business needs such as managing inventories and payrolls

Better for file input than keyboard input

The “master file” would be updated from the “transaction file” on a daily or weekly basis.

Page 8: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

88

COBOL (continued)COBOL (continued)

Much of a COBOL program may be concerned with formatting

Particular attention was paid to input formatting for data being read from files and to output formatting both for writing data to a file and for generating business reports.

Described by “PICTURE clauses” in the program

COBOL programs

More verbose than other languages

In C++: sum = a + b ;

In COBOL: ADD A To B GIVING SUM

Highly portable

Page 9: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

99

COBOL (continued)COBOL (continued)

COBOL programs

Easy to read

Well-suited for manipulating large data files

Still the most widely used language

Page 10: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

1010

C/C++C/C++

C

Developed in the early 1970s by Dennis Ritchie at AT&T Bell Laboratories

Originally designed for systems programming (UNIX)

Most widely used language for system software

Also used for general-purpose computing

Page 11: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

1111

C/C++ (continued)C/C++ (continued)

Why is C so popular

Relationship between C and UNIX

C’s efficiency

C is close to assembly language

Has high-level statements

Portability

Page 12: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

1212

Figure 9.1

User Hardware Interface and Programming Languages

Page 13: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

1313

C/C++ (continued)C/C++ (continued)

C++

Developed in the early 1980s by Bjarne Stroustrup at AT&T Bell Laboratories

A “superset” of C

One of the most popular modern “industrial-strength” languages, because of

Standardization

Object-orientation

A strong collection of library code

Page 14: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

1414

AdaAda

Mid-1970s: Branches of the U. S. armed services started to develop a common high-level programming language

Efficiency, reliability, readability, and maintainability.

Straw-man, Wooden man, Tin-man, Iron man, Steel man

1979: winner of design competition

Ada 95 Reference Manual

Current international standard exists

Page 15: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

1515

Ada (continued)Ada (continued)

Ada

Provides multiprocessing capability

Strongly object-oriented

Still used today in

Transportation industry

Safety monitoring systems at nuclear reactors

Financial and communication systems

Page 16: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

1616

JavaJava

1995

Java programApplication

Standalone program

AppletSmall application

Web Browser

BytecodeJava bytecode interpreter

Page 17: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

1717

C# and .NETC# and .NET

C#

Introduced in June 2000

Many improvements in safe usage over C++

Shares many features with Java

MSIL (Microsoft Intermediate Language)

JIT (Just In Time)

Page 18: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

1818

C# and .NET (continued)C# and .NET (continued)

Microsoft .NET Framework

Supports C# and other languages

Facilitates ease of development

Traditional text-based applications

GUI applications

Web-based programs

Page 19: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

1919

C# and .NET (continued)C# and .NET (continued)

.NET programs are highly portable

.NET programs are compiled into Microsoft Intermediate Language (MSIL)

MSIL is not tied to any particular platform

Just In Time compiler or JIT

Compiles MSIL code into object code on the user’s machine

Page 20: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

2020

Special-purpose LanguagesSpecial-purpose Languages

Designed for one specialized task

Examples:

SQL

HTML

JavaScript

Page 21: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

2121

SQLSQL

SQL: Structured Query Language

A database stores data

Databases can be queried: the user can pose questions to the database

SQL is the language used to frame database queries

Example:

SELECT NAMEFROM VENDORWHERE PURCHASE>40000

Page 22: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

2222

HTMLHTML

HTML: HyperText Markup Language

HTML is the language used to create HTML documents

Web page

An HTML document viewed with Web browser software

Page 23: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

2323

HTML (continued)HTML (continued)

An HTML document

Consists of text displayed on the Web page and tags

The overall format for an HTML document is

<HTML> <HEAD> <TITLE> stuff to go in the title bar </TITLE> </HEAD> <BODY> stuff to go on the page </BODY></HTML>

Tags are special characters

Formatting

Special effects

References to other HTML documents

Page 24: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

2424

Figure 9.4: HTML Code for a Web Page

Page 25: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

2525

Figure 9.5

Body of the Web Page Generated by Figure 9.4

Page 26: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

2626

Figure 9.6

Some HTML Tags

Page 27: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

2727

JavaScriptJavaScript

JavaScript is a scripting language

Scripting language

A “lightweight” language that is

Interpreted (translated/executed, statement by statement)

Code fragments can be embedded in Web pages to make those pages active

Page 28: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

2828

Alternative Programming ParadigmsAlternative Programming Paradigms

A paradigm

A model or mental framework for representing or thinking about something

The paradigm of procedural programming languages

A sequence of detailed instructions is provided to the computer

Page 29: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

2929

Alternative Programming Paradigms (continued)Alternative Programming Paradigms (continued)

The paradigm of procedural programming languages (continued)

Each instruction accesses or modifies the contents of a memory location

Computer carries out the instructions one at a time, resulting in the solution to the problem

Page 30: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

3030

Alternative Programming Paradigms (continued)Alternative Programming Paradigms (continued)

Alternative paradigms for programming languages

Viewing a program’s actions as

A combination of various transformations upon items (functional programming)

A series of logical deductions from known facts (logic programming)

Multiple copies of same subtask or multiple subtasks of same problem being performed simultaneously by different processors (parallel programming)

Page 31: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

3131

Functional ProgrammingFunctional Programming

1958: LISP (LISt Processing) language designed by John McCarthy at MIT

Scheme

A functional programming language derived from LISP in the late 1970s

A functional programming language views every task in terms of functions

Page 32: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

3232

Functional Programming (continued)Functional Programming (continued)

In a functional programming language

Primitive functions are part of the language

Other functions can be defined and named by the programmer

Once defined, functions can be used in the definition of other functions

Functional programming languages sometimes called applicative languages

Page 33: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

3333

Functional Programming (continued)Functional Programming (continued)

(define (double x) ( * 2 x))

2x

(double 4) 8

(define (square x)) ( *x x)

X^2

(square 3) 9

(define (polynomial x) (double (square x)))

(polynomial 3)18

Page 34: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

3434

Figure 9.9

Scheme Program to Add Nonnegative Integers

Page 35: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

3535

Functional Programming (continued)Functional Programming (continued)

Functional languages offer another layer of abstraction: mathematics

Functions are described mathematically by what they do to an item of data rather than by how they modify memory cells

Possibility of “side effects” is eliminated

Page 36: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

3636

Logic ProgrammingLogic Programming

Logic programming

Various facts are asserted to be true

On the basis of these facts, a logic program can infer or deduce other facts

A query can be posed to the program

The program applies logical deductions to answer the query

Logic programming languages are sometimes called declarative languages

Page 37: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

3737

Logic Programming (continued)Logic Programming (continued)

Logic programming has been used to write expert systems

Prolog (PROgramming in LOGic)

Developed in France at the University of Marseilles in 1972 by a group headed by A. Colmerauer

Page 38: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

3838

Logic Programming (continued)Logic Programming (continued)

Prolog programs

Consist of “facts” and “rules”

A fact expresses a property about a single object or a relationship among several objects

A rule is a declaration of an “if A then B” form

We interact with the program by posing queries

Page 39: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

3939

Figure 9.10

A Prolog Program

Page 40: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

4040

Logic Programming (continued)Logic Programming (continued)

Logic programming paradigm

The program is a knowledge base of facts and rules about a certain domain of interest

Interaction with the program: posing queries to an inference engine (also called a query interpreter)

Page 41: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

4141

Figure 9.11

The Logic Programming Paradigm

Page 42: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

4242

Parallel ProgrammingParallel Programming

SIMD (single instruction stream/multiple data stream)

A single control unit broadcasts a single program instruction to multiple ALUs

Each ALU carries out that instruction on its own local data stored in its local memory

Page 43: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

4343

Parallel Programming (continued)Parallel Programming (continued)

MIMD (multiple instruction stream/multiple data stream)

Numerous interconnected processors execute their own programs on their own data, communicating results as necessary

Variations of parallel processing

Divide-and-conquer approach to MIMD parallel processing

Neural networks

Page 44: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

4444

Figure 9.13

An Example of MIMD Parallel Processing

Page 45: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

4545

SummarySummary

Each programming language was designed to meet specific needs

Procedural programming languages: FORTRAN, COBOL, C, Ada, Java, C++, C#, Visual Basic

Special-purpose languages: SQL, HTML, JavaScript

A functional programming language views every task in terms of functions

Page 46: Chapter 9: The Tower of Babel 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.tw

4646

SummarySummary

Logic programming: various facts are asserted to be true, based on whether the program infers or deduces other facts

Parallel programming

SIMD (single instruction stream/multiple data stream)

MIMD (multiple instruction stream/multiple data stream)