PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

47
PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES

Transcript of PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

Page 1: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

P R O G L A N S E S S I O N 0 2R O N A L D L . R A M O S

PROGRAMMING LANGUAGES

Page 2: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING LANGUAGES CONCEPTS

Page 3: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

OUTLINE

• Why Study Programming Languages?• Language Design Criteria• Effects of Environments on Languages• Programming Paradigms• History of Programming Languages

Page 4: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

WHY STUDY PROGRAMMING LANGUAGES?

LANGUAGE DESIGN CRITERIA

Page 5: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

WHAT IS A PROGRAMMING LANGUAGE?

• A notation for instructions to be performed by the computer

• Any notation for the description of algorithms and data structures

• Used as a means of communicating ideas about algorithms between people and computers

Page 6: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

WHAT IS A PROGRAMMING LANGUAGE?

• The earliest programming languages predate the invention of the computer, and were used to direct the behavior of machines such as Jacquard looms and player pianos

Page 7: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

WHY STUDY PROGRAMMING LANGUAGE CONCEPTS?

• To improve your ability to develop effective algorithms

• To improve your use of your existing programming language (better understanding of the significance of implementation)

• To increase your vocabulary of useful programming constructs (increased capacity to express ideas)

Page 8: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

WHY STUDY PROGRAMMING LANGUAGES CONCEPTS?

• To allow a better choice of programming language (improved background for choosing appropriate languages)

• To make it easier to learn a new language (increased ability to learn new languages)

• To make it easier to design a new language

Page 9: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

WHY STUDY PROGRAMMING LANGUAGES CONCEPTS?

• Overall advancement of computing• Why was Fortran more popular than Algol?

• because of industry support • because of the cost of change • because of acceptance by the public sector • because top management failed to understand the concepts

of programming languages

Page 10: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

INTRODUCTION

• Why Study Programming Languages?• Language Design Criteria• Effects of Environments on Languages• Programming Paradigms• History of Programming Languages

Page 11: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

EFFECTS OF ENVIRONMENTS ON LANGUAGESPROGRAMMING PARADIGMS

Page 12: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

LANGUAGE EVALUATION AND DESIGN CRITERIA

• Readability• Overall Simplicity

• Feature multiplicityThere are 4 ways to increment a variable called count in C++:

++count; count++;count += 1; count = count + 1;

Page 13: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

LANGUAGE EVALUATION AND DESIGN CRITERIA

• Operator overloading

The + operator has 4 meanings in Visual Basic:5 + 10 ‘ integer addition5.5 + 10 ‘ floating point addition5.5 + 3.5 ‘ floating point addition“hello” + “world” ‘ string concatenation

In languages that provide facilities for programmers to define their own overloaded operations, we could even have:

file1 + file2 ‘ appending file1 and file2bmp1 + bmp2 ‘ overlaying bitmapsarray1 + array2 ‘ adding parallel

arrays

Page 14: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

LANGUAGE EVALUATION AND DESIGN CRITERIA

• Readability• Orthogonality

// IBM instructions for adding two 32-bit integersA Reg, Mem Reg = Reg + Mem

AR Reg1, Reg2 Reg1 = Reg1 + Reg2// cannot add two memory, or memory and register, and// storing the result in memory

// VAX instructionADDL opd1, opd2

// opd1 and opd2 can be either a memory or a register// allow any possible combination of operands and all are valid// few exception and inconsistent rules

Page 15: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

LANGUAGE EVALUATION AND DESIGN CRITERIA

• Readability• Syntax (Form) Consideration

• Identifier forms• What is the maximum length of characters that is significant

in an identifier name? Are the following identifier names the same?

ThisIsALongIdentifier ThisIsALong• Is the language case-sensitive? Are the following identifier

names the same?

Name NAME name• Are connector characters, such as _, allowed?

Page 16: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

LANGUAGE EVALUATION AND DESIGN CRITERIA

• Special words for compound statements

“end” vs “end if” “end do” “end sub” sub … sub …

for … for … if … if … end end ifend end for

end end sub

• Reserved words vs Keywords

Are the following allowed as identifier names?

dim true as integerdim false as double

Page 17: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

LANGUAGE EVALUATION AND DESIGN CRITERIA

•Writability• Simplicity and orthogonality• Support for abstraction• Expressitivity

for I = 1 to 10 I = 1: while I <= 10

next I : I = I + 1loop

Page 18: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

LANGUAGE EVALUATION AND DESIGN CRITERIA

• Reliability• Type checking• Exception handling• Aliasing• Readability and Writability

• Portability• Generality• Well-definedness

Page 19: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

LANGUAGE EVALUATION AND DESIGN CRITERIA

• Cost • Training programmers• Writing programs• Validation and Verifying programs• Compiling programs• Executing programs• Maintaining programs• Reliability

Page 20: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

LANGUAGE DESIGN TRADE-OFFS

• Reliability vs. Cost of Execution• Readability vs. Writability• Flexibility vs. Safety

Page 21: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

INTRODUCTION

• Why Study Programming Languages?• Language Design Criteria• Effects of Environments on Languages• Programming Paradigms• History of Programming Languages ®

Page 22: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

WHAT IS AN ENVIRONMENT?

• Operating or target environment• External environment supporting the execution of a

program

• Host environment• Environment in which a program is designed, coded,

tested, and debugged

Page 23: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

BATCH-PROCESSING ENVIRONMENTS

• A program takes a set of data files as input, process the data, and produces a set of output data files.

• Input data are collected and processed as batch files by the program.

Page 24: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

BATCH-PROCESSING ENVIRONMENTS

• Effects on language design:• Input-output features

• File structure

• Error- and exception-handling features• The entire run must be stopped, the program corrected,

and then re-executed• No external help in immediately addressing the exception

is available from the user• Exception-handling must be coded into the program to

prevent abnormal termination

Page 25: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

BATCH-PROCESSING ENVIRONMENTS

• Timing facilities• None• OS (depending on its CPU scheduling algorithm) may allow

the program to execute partially, then swap it out to secondary storage for an indefinite period, and later bring it back to continue execution

• Program structure• Consists of a main program and a number of subprograms

Page 26: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

INTERACTIVE ENVIRONMENTS

• Direct interaction between the user and the computer during program execution.

• Examples: Office tools, games, database management systems, CAI, transaction processing systems, client/server applications

Page 27: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

INTERACTIVE ENVIRONMENTS

• Effects on language design:• Input-output features

• scanf, printf• println

• Error- and exception-handling features• Input validation• Error message

Page 28: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

INTERACTIVE ENVIRONMENTS

• Timing facilities• User response time (ATM, video game)• System response time

• Program structure• Consists of a set of subprograms

Page 29: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

EMBEDDED SYSTEM ENVIRONMENTS

• An embedded computer system is used to control part of a larger system.

• Failure of embedded systems can be life-threatening.

• Primary attributes - reliability and correctness.

Page 30: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

EMBEDDED SYSTEM ENVIRONMENTS

• Effects on language design:• Input-output features

• Special devices, e.g., hardware registers, memory locations, interrupt handlers, or subprograms written in assembly or other low-level languages

• Error- and exception-handling features• System-provided and extensive

Page 31: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

EMBEDDED SYSTEM ENVIRONMENTS

• Timing facilities• Real-time

• Program structure• An embedded computer system is often a distributed system,

consisting of tasks that operate concurrently, each controlling or monitoring one part of the system.

Page 32: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING ENVIRONMENTS

• The environment in which programs are created and tested.

• Support tools:• project management• compiler, debugger• text editor (color coding scheme, automatic code

completion, pretty printers)• help• test data generators

Page 33: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING ENVIRONMENTS

• Effects on language design:• Features aiding separate compilation of subprograms

• Require the redeclaration of needed information• Prescribe a particular order of compilation so that

specification of all subprograms and shared data are compiled first

• Presence of a library containing the relevant specifications during compilation so that the compiler may retrieve them as needed

Page 34: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING ENVIRONMENTS

• Examples• DLL (Visual Basic) Declare Function GetPrivateProfileInt Lib

“kernel” (ByVal Section As String, ByVal Entry As String, ByVal Entry As Integer, ByVal FileName As String) As Integer

• import <package> (Java) import java.util.*;• uses <unit> (Pascal) uses crt, graphics;• extern <variable declaration> (C) extern int i;

Page 35: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING ENVIRONMENTS

• Features aiding program testing and debugging• Execution trace feature• Break point• Assertion

• a conditional expression inserted as a separate statement in a program

• states the relations that must hold among the values of the variables at that point in the program

Page 36: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

INTRODUCTION

• Why Study Programming Languages?• Language Design Criteria• Effects of Environments on Languages• Programming Paradigms• History of Programming Languages ®

Page 37: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING PARADIGMS

• Paradigms are ways for expressing algorithms that appeal especially well in a particular application area.

Page 38: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING PARADIGMS

• Imperative or Procedural languages• Command-driven or statement-oriented languages• Basic concept: machine state• Influenced by the von Neumann architecture• Languages: Cobol, Fortran, Basic, C/C++, Pascal

Statement1;Statement2;

Page 39: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING PARADIGMS

• Applicative or Functional languages• What is the function that must be applied to the initial

machine state by accessing the initial set of variables and combining them in specific ways in order to get an answer?

• Focus: what is the desired result?• Languages: LISP, ML, Scheme

fn(…(f2(f1(data)))…)

Page 40: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING PARADIGMS

Rule-based or Logic programming languages Execute by checking for the presence of a certain

enabling condition and when it is satisfied, they execute an appropriate action

Languages: PrologEnabling conditon1 Action1

Enabling conditon2 Action2

Page 41: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING PARADIGMS

• Object-Oriented programming• Complex data objects are built and a limited set of

functions are designed to operate on those data.• Concepts: inheritance, classification, object modeling• Combination of imperative (building concrete data

objects) and applicative (building classes of functions that use a restricted set of data objects).

• Languages: Smalltalk, Java, C++, Eiffel

Page 42: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING PARADIGMS

• Event-driven programming• The program is a continuous loop that responds to

events that are generated in an unpredictable order. • Languages: Visual Basic, Javamain (){ while getmessage()

….. Check Charles Petzold

Page 43: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING PARADIGMS

• Declarative programming• The program is a collection of logical declarations about

what outcome a function should accomplish rather than how that outcome should be accomplished.

• Execution of the program applies these declarations to achieve a series of possible solutions to a problem.

Page 44: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

PROGRAMMING PARADIGMS

• Concurrent programming• The program is a collection of cooperating processes,

sharing information with each other from time to time but generally operating asynchronously.

• Parallelism can occur within an individual processes, such as the parallel execution of the different iterations of a loop.

Page 45: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

APPLICATION DOMAINS

• Scientific computing• Imperative programming (C) and parallel programming

(Ada) paradigms

• Management information systems • Imperative (Cobol)• Declarative (SQL) for database retrieval• Event-driven (Java) for client-server apps

Page 46: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

APPLICATION DOMAINS

• Artificial intelligence • Systems

• Imperative (Assembly, C)• Parallel programming• Event-driven programming

• Web-centric• Event-driven programming • Object-oriented design

Page 47: PROGLAN SESSION 02 RONALD L. RAMOS PROGRAMMING LANGUAGES.

END OF PRESENTATION