concepts of programming language

30
Author: Robert Sebesta

Upload: -

Post on 22-Nov-2014

407 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Concepts of Programming Language

Author: Robert Sebesta

Page 2: Concepts of Programming Language

OBJECTIVE:to introduce the main constructs of contemporary

programming languages and to provide the reader with the tools necessary for the critical evaluation of existing and future programming languages

to provide the reader with the tools necessary for the critical evaluation of existing and future programming languages.

to prepare the reader for the study of compiler design by providing an in-depth discussion of programming language structures, representing a formal method of describing syntax, and introducing approaches to lexical and syntactic analysis

Page 3: Concepts of Programming Language

Chapter 1: Preliminaries1.1 Reasons for Studying Concepts of

Programming Languages

1.2 Programming Domains1.3 Languages Evaluation Criteria1.4 Influences on Language Design1.5 Language Categories1.6 Language Design Trade-offs1.7 Implementation Methods1.8 Programming Environment

Page 4: Concepts of Programming Language
Page 5: Concepts of Programming Language

1.1 Reasons for Studying Concepts of Programming LanguageIncreased capacity to express ideas

it is difficult for people to conceptualize structures they cannot describe, verbally or in writing(e.i arrays)

awareness of a wider variety of programming language features can reduce such limitations in software development.

language constructs can be simulated in other languages that do not support those constructs directly

(e.i associative arrays in PERL is simulated by C programmers )

Page 6: Concepts of Programming Language

Improved background for choosing appropriatelanguagesif programmers were familiar with many

languages and the features in those languages, they would be in a better position to make more appropriate language choices.

1.1 Reasons for Studying Concepts of Programming Language

Page 7: Concepts of Programming Language

Increased ability to learn new languages computer programming is still a relatively young

discipline, and design methodologies, software development tools, and programming languages are still in a state of continuous evolution

once a thorough understanding of the fundamental concepts of languages is acquired, it becomes far easier to see how these concepts are incorporated into the design of the language being learned

the better you know the grammar of your native language, the easier you will find it to learn a second language (e.i C and PHP)

1.1 Reasons for Studying Concepts of Programming Language

Page 8: Concepts of Programming Language

Better understanding of the significance of implementationunderstanding of implementation issues leads

to an understanding of why languages are designed the way they are (e.i sorting algorithms)

We can become better programmers by understanding the choices among the programming language constructs and the consequences of those choices.

1.1 Reasons for Studying Concepts of Programming Language

Page 9: Concepts of Programming Language

Overall advancement of computingif those who choose languages were better

informed, perhaps better languages would eventually squeeze out poorer ones

1.1 Reasons for Studying Concepts of Programming Language

Page 10: Concepts of Programming Language
Page 11: Concepts of Programming Language

1.2 Programming Domain1.2.1 Scientific applications

Have simple data structures but require large numbers of floating-point arithmetic computations.

most common data structures are arrays and matrices ; most common control structures are counting loops and selections

FORTRAN, ALGOL 60

1.2.2 Business applications characterized by facilities for producing elaborate

reports, precise ways of describing and storing decimal numbers and character data and the ability to specify decimal arithmetic operations

COBOL, spreadsheet systems, database systems

Page 12: Concepts of Programming Language

1.2 Programming Domain1.2.3 Artificial intelligence

characterized by the use of symbolic rather than numeric computations

Symbolic computationsmeans that symbols, consisting of names

rather than numbers, are manipulatedmore conveniently done with linked lists of

data rather than arraysLISP, Prolog, Scheme

Page 13: Concepts of Programming Language

1.2 Programming Domain1.2.4 Systems programming

Systems software - composed of the operating system and all of the programming support tools of a computer system

used almost continuously and therefore must be efficient

the language for this domain must provide fast execution

PL/S, BLISS, Extended ALGOL, C

1.2.5 Web Software(scripting language) XHTML. PHP, Javascript,Perl

Page 14: Concepts of Programming Language
Page 15: Concepts of Programming Language

1.3: LANGUAGE EVALUATION CRITERIA1.3.1 Readability

1.3.1.1 Overall simplicity1.3.1.2Orthogonality1.3.1.3Control statements1.3.1.4 Data type and structures1.3.1.5 Syntax considerations 1.3.2 Writability

1.3.2.1 Simplicity and Orthogonality 1.3.2.2 Support for Abstraction

1.3.2.3 Expressivity

Page 16: Concepts of Programming Language

1.3.3 Reliability1.3.3.1 Type Checking

1.3.3.2 Exception Handling1.3.3.3 Aliasing1.3.3.4 Readability and Writability

1.3.4 Cost

1.3: LANGUAGE EVALUATION CRITERIA

Page 17: Concepts of Programming Language

1.3.1 ReadabilityMost important criteria for judging a

programming languageFactors:

1.3.1.1 Overall simplicityToo many features is bad (difficult to learn)Feature Multiplicity is bad(leads to

inconsistency)Ex:

Operator overloading(e.i ampersand (&))

Page 18: Concepts of Programming Language

1.3.1.2Orthogonality addresses how relatively small number of

components that can be combined in a relatively small number of ways to get the desired results

Makes the language easy to learn and read Meaning is context independent

1.3.1 Readability

Page 19: Concepts of Programming Language

Example of Orthogonality

Page 20: Concepts of Programming Language

The more orthogonal the design, the fewer exceptions the language rules require

Fewer exceptions means higher degree of regularity in the design, which makes the language easier to learn, read and understand

The most orthogonal programming language: ALGOL 68

Functional Language – offer a good combination of simplicity and orthogonality

Example: LISP

1.3.1 Readability

Page 21: Concepts of Programming Language

1.3.1.3Control statements structured programming revolution over the use

of gotos A program that can be read from top to bottom

is much easier to understand than a program that requires the reader to jump from one statement to some nonadjacent statement in order to follow the execution order.

1.3.1 Readability

Page 22: Concepts of Programming Language
Page 23: Concepts of Programming Language

1.3.1.4 Data type and structures the presence of adequate facilities for defining data types

and data structures in a language is another significant aid to readability

BOOLEAN Suppose a numeric type is used for an indicator flag

1.3.1 Readability

unclear meaning

Whereas in a language with Boolean types we would have :

In a language with no Boolean data types:

Page 24: Concepts of Programming Language

STRUCTURE vs COLLECTION OF ARRAYS In Fortran 95, an array of employee records might be

stored in the following arrays:

1.3.1 Readability

In C. employee records can be stored in a structure:

typedef struct { char Name[100]; int Age, Employee_Number; float Salary; } Employee_Record

Page 25: Concepts of Programming Language

1.3.1.5 Syntax considerations Identifier forms (length)

restricting identifiers to very short lengths distracts from readability Example: original American National

Standards Institute(ANSI) BASIC -> has an identifier could consist only of a single letter or a single letter followed by a single digit.

Special/reserved words Using these words as a variable name can lead to

confusion

1.3.1 Readability

Page 26: Concepts of Programming Language

Form and MeaningDesigning statements so that their

appearance at least partially indicates their purpose

Semantics or meaning - should follow directly from syntax or form

Example: In C, the meaning of the reserved word static depends on the context of its appearance if used in the definition of a variable inside a function -

variable is created at compile time if used on the definition of a variable that is outside all

functions, it means the variable is visible only in the file in which its definition appears

1.3.1 Readability

Page 27: Concepts of Programming Language

Measure of how easily a language can be used to create programs for a chosen problem domain

most of the language characteristics that affect readability also affect writability.

It is simply not reasonable to compare the writability of two languages in the realm of a particular application when one was designed for that application and the other was not.

1.3.2 WRITABILITY

Page 28: Concepts of Programming Language

1.3.2.1 Simplicity and OrthogonalityLarge number of different constructs can lead to

misuse of some features and a disuse of others that may be either more elegant or more efficient, or both,than those that are used.

Therefore, a smaller number of primitive constructs and a consistent set of rules for combining them(that is, orthogonality) is much better than simply having large numbers if primitives.

However too much orthogonality can lead to undetected errors because nearly any combination of primitives is legal.

1.3.2 WRITABILITY

Page 29: Concepts of Programming Language

1.3.2.2 Support for AbstractionAbstraction

means the ability to define and then use complicated structures or operations in ways that allow many of the details to be ignored

key concept in contemporary programming language design

Programming languages can support two distinct categories of abstraction: process and data

Example for process abstraction: the use of a subprogram to implement a sort algorithm that is required several times in a program

Example for data abstraction: a binary tree that stores integer data in its node

1.3.2 WRITABILITY

Page 30: Concepts of Programming Language

1.3.2.3 Expressivity