0% found this document useful (0 votes)
74 views13 pages

Increased Capacity To Express Ideas. Increased Capacity To Express Ideas

Uploaded by

rymaa1923
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views13 pages

Increased Capacity To Express Ideas. Increased Capacity To Express Ideas

Uploaded by

rymaa1923
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1/6. Increased capacity to express 1/6.

Increased capacity to express


ideas. ideas.
• It is widely believed that the depth at which people can think is influenced -Example
by the expressive power of the language in which they communicate their • For example, a C programmer who had learned the structure and uses of
thoughts. associative arrays in Perl might design structures that simulate associative
arrays in that language.
• It is difficult for people to conceptualize structures they cannot describe,
verbally or in writing. • study of programming language concepts builds an appreciation for
valuable language features and constructs.
• Programmers, in the process of developing software, are similarly
constrained. • It encourages programmers to use them, even when the language they are
using does not directly support such features and constructs.
• The language in which they develop software places limits on the kinds of
control structures, data structures, and abstractions they can use.
• Thus, the forms of algorithms they can construct are likewise limited.
• Awareness of a wider variety of programming language features can reduce
such limitations in software development.
• Programmers can increase the range of their software development thought
processes by learning new language constructs.

3 4

2/6. Improved background for 3/6. Increased ability to learn new


choosing appropriate languages. languages.
• Computer programming has design methodologies, software development
• Many professional programmers have had little formal education in tools, and programming languages are still in a state of continuous
computer science with a limit to one or two languages that are directly evolution.
relevant to the current projects of the organization. • This makes software development an exciting profession, but it also means
• The result is that many programmers, when given a choice of languages for that continuous learning is essential.
a new project, use the language with which they are most familiar, even if it • Once a thorough understanding of the fundamental concepts of languages
is poorly suited for the project at hand. is acquired, it becomes far easier to see how these concepts are
• If programmers are familiar with a wider range of languages and language incorporated into the design of the new language being learnt.
constructs, they would be better able to choose the language with the • For example, programmers who understand the concepts of object-oriented
features that best address the problem. programming will have a much easier time learning Java than those who
have never used those concepts.
• Some of the features of one language often can be simulated in another
• Java, C, and C++ were the three most popular languages in use in 2011.
language.
• It is essential that practicing programmers know the vocabulary and
• However, it is preferable to use a feature whose design has been integrated fundamental concepts of programming languages so they can read and
into a language than to use a simulation of that feature, which is often less understand programming language descriptions and evaluations, as well as
elegant, more cumbersome, and less safe. promotional literature for languages and compilers.
5 6
4/6. Better understanding of the
4. Better understanding of the
significance of implementation.
significance of implementation.
-Example
• An understanding of implementation issues leads to an understanding of
why languages are designed the way they are.
• For example, programmers who know little about the complexity of the
• This knowledge leads to the ability to use a language more intelligently, as implementation of subprogram calls often do not realize that a small
it was designed to be used. subprogram that is frequently called can be a highly inefficient design
• We can become better programmers by understanding the choices among choice.
programming language constructs and the consequences of those choices.
• Benefit 1: Program bugs can be found and fixed only by a programmer who
knows some related implementation details.
• Benefit 2: By understanding implementation issues it allows us to visualize
how a computer executes various language constructs.
• Some knowledge of implementation issues provides hints about the relative
efficiency of alternative constructs that may be chosen for a program.

7 8

5/6. Better use of languages that are 6/6. Overall advancement of


already known. computing.
• Many contemporary programming languages are • Finally, there is a global view of computing that can justify the study of
programming language concepts.
large and complex.
• Although it is usually possible to determine why a particular programming
• Accordingly, it is uncommon for a programmer to language became popular, many believe, at least in retrospect, that the most
be familiar with and use all of the features of a popular languages are not always the best available.
• In some cases, it might be concluded that a language became widely used,
language they use. at least in part, because those in positions to choose languages were not
• By studying the concepts of programming sufficiently familiar with programming language concepts.
languages, programmers can learn about
previously unknown and unused parts of the
languages they already use and begin to use
those features.
9 10
6/6. Overall advancement of
computing. - Example
Reason for failure of ALGOL60 / Emergence of Fortran
• For example, many people believe it would have been better if
ALGOL60 had displaced Fortran in the early 1960s, because it was
more elegant and had much better control statements, among other
reasons.
• That it did not, is due partly to the programmers and software
development managers of that time, many of whom did not clearly
understand the conceptual design of ALGOL 60.
• They found its description difficult to read (which it was) and even Chapter 1
more difficult to understand.
• They did not appreciate the benefits of block structure, recursion, PROGRAMMING DOMAINS
and well-structured control statements, so they failed to see the
benefits of ALGOL 60 over Fortran.

11 12

1/5. Scientific Applications 2/5. Business Applications


• The first digital computers, which appeared in the late 1940s and early
1950s, were invented and used for scientific applications. • The use of computers for business applications began in the 1950s.
• Scientific applications used relatively simple data structures, but required • Special computers were developed for this purpose, along with
large numbers of floating-point arithmetic computations. special languages.
• The first successful high-level language for business was COBOL
• The most common data structures were arrays and matrices; the most
the initial version of which appeared in 1960.
common control structures were counting loops and selections.
• It is still the most commonly used language for these applications.
• The early high-level programming languages invented for scientific
• Business languages are characterized by facilities for producing
applications were designed to provide for those needs. elaborate reports, precise ways of describing and storing decimal
• Their competition was assembly language, so efficiency was a primary numbers and character data, and the ability to specify decimal
concern. arithmetic operations.
• The first language for scientific applications was Fortran. • There have been few developments in business application
languages outside the development and evolution of COBOL.
• ALGOL 60 and most of its descendants were also intended to be used in
this area, although they were designed to be used in related areas as well.
• For some scientific applications where efficiency is the primary concern,
no subsequent language is significantly better than Fortran.
13 14
3/5. Artificial Intelligence 4/5. Systems Programming
• Artificial intelligence (AI) - a broad area of computer applications • The operating system and the programming support tools of a computer
characterized by the use of symbolic rather than numeric computations. system are collectively known as its systems software.
Symbolic computation means that symbols, consisting of names rather than • Systems software is used almost continuously and so it must be efficient.
numbers. Furthermore, it must have lowlevel features that allow the software
• These are more conveniently done with linked lists of data rather than interfaces to external devices to be written.
arrays. This kind of programming sometimes requires more flexibility than • In the 1960s and 1970s, some computer manufacturers, such as IBM,
other programming domains. Digital, and Burroughs (now UNISYS), developed special machine-
• For example, in some AI applications the ability to create and execute code oriented high-level languages for systems software on their machines.
segments during execution is convenient. • For IBM mainframe computers, the language was PL/S, a dialect of PL/I;
• The first widely used programming language developed for AI applications for Digital, it was BLISS, a language at a level just above assembly
was the functional language LISP in 1959. language; for Burroughs, it was Extended ALGOL.
• During the early 1970s, however, an alternative approach to some of these • However, most system software is now written in more general
applications appeared—logic programming using the Prolog programming languages, such as C and C++.
• More recently, some AI applications have been written in systems
languages such as C.
15 16

5/5. Web software


• The World Wide Web is supported by an eclectic
collection of languages, ranging from markup
languages, such as HTML, which is not a programming
language, to general-purpose programming languages,
such as Java.
• Because of the pervasive need for dynamic Web
content, some computation capability is often included
in the technology of content presentation. Chapter 1
• This functionality can be provided by embedding
programming code in an HTML document. LANGUAGE EVALUATION CRITERIA
• Such code is often in the form of a scripting language,
such as JavaScript or PHP.

17 18
Factor 1: Readability Readability
• One of the most important criteria for judging a programming language is
the ease with which programs can be read and understood. • Overall Simplicity
• Before 1970, software development was largely thought of in terms of
writing code. • Orthogonality
• The primary positive characteristic of programming languages was
efficiency. • Data Types
• Language constructs were designed more from the point of view of the
computer than of the computer users. • Syntax Design
• Because ease of maintenance is determined in large part by the readability
• of programs, readability became an important measure of the quality of
• programs and programming languages.
• This was an important juncture in the evolution of programming languages.
• There was a distinct crossover from a focus on machine orientation to a
focus on human orientation.
• Readability must be considered in the context of the problem domain.

20 21

1. Overall simplicity 1. Overall Simplicity – Example 1


• The overall simplicity of a programming language strongly affects its • For example, in Java, a user can increment a
readability.
simple integer variable in four different ways:
• A language with a large number of basic constructs is more difficult to
count = count + 1
learn than one with a smaller number.
count += 1
• Programmers who must use a large language often learn a subset of the
count++
language and ignore its other features.
++count
• This learning pattern is sometimes used to excuse the large number of
language constructs, but that argument is not valid. • Although the last two statements have slightly
• Readability problems occur whenever the program’s author has learned a different meanings from each other and from the
different subset from that subset with which the reader is familiar. others in some contexts, all of them have the
• A second complicating characteristic of a programming language is feature
multiplicity.
same meaning when used as stand-alone
expressions.

22 23
1. Overall Simplicity – Example 2 2. Orthogonality
• A third potential problem is operator overloading, in which a single
operator symbol has more than one meaning. • Orthogonality in a programming language means that a relatively small set of
• Although this is often useful, it can lead to reduced readability if users are primitive constructs can be combined in a relatively small number of ways to
allowed to create their own overloading and do not do it sensibly. build the control and data structures of the language.
• Furthermore, every possible combination of primitives is legal and meaningful.
• For example, it is clearly acceptable to overload + to use it for both integer
• Suppose a language has four primitive data types (integer, float, double, and
and floating-point addition. character) and two type operators (array and pointer).
• In fact, this overloading simplifies a language by reducing the number of • If the two type operators can be applied to themselves and the four primitive
operators. However, suppose the programmer defined + used between data types, a large number of data structures can be defined.
single-dimensioned array operands to mean the sum of all elements of both • The meaning of an orthogonal language feature is independent of the
arrays. context of its appearance in a program.
• Because the usual meaning of vector addition is quite different from this, it • The word orthogonal comes from the mathematical concept of orthogonal
would make the program more confusing for both the author and the vectors, which are independent of each other.
program’s readers. • Orthogonality follows from a symmetry of relationships among primitives.
• An even more extreme example of program confusion would be a user • A lack of orthogonality leads to exceptions to the rules of the language.
defining + between two vector operands to mean the difference between
their respective first elements.
24 25

2. Orthogonality- Example 2. Orthogonality- Example


• C has two kinds of structured data types, arrays and records (structs), records
• For example, in a programming language that supports pointers, it should can be returned from functions but arrays cannot.
be possible to define a pointer to point to any specific type defined in the • A member of a structure can be any data type except void or a structure of the
language. same type.
• However, if pointers are not allowed to point to arrays, many potentially • An array element can be any data type except void or a function. Parameters
useful user-defined data structures cannot be defined. are passed by value, unless they are arrays, passed by reference (because the
• Orthogonality is closely related to simplicity: The more orthogonal the appearance of an array name without a subscript in a C program is interpreted
design of a language, the fewer exceptions the language rules require. to be the address of the array’s first element).
• Fewer exceptions mean a higher degree of regularity in the design, which • An example of context dependence, consider the C expression a+b
makes the language easier to learn, read, and understand. • This expression often means that the values of a and b are fetched and added
together. However, if a happens to be a pointer, it affects the value of b.
• For example, if a points to a float value that occupies four bytes, then the
value of b must be scaled—in this case multiplied by 4—before it is added to
a.
• Therefore, the type of a affects the treatment of the value of b. The context of
b affects its meaning.
26 27
3. Data Types 4. Syntax Design(1/2)
• The presence of adequate facilities for defining data types and data • The syntax, or form, of the elements of a language has a significant effect on the
readability of programs.
structures in a language is another significant aid to readability. For
• Following are some examples of syntactic design choices that affect readability:
example, suppose a numeric type is used for an indicator flag because there
• Special words like while, class, and for especially important is the method of forming
is no Boolean type in the language. compound statements, or statement groups, primarily in control constructs.
• In such a language, we might have an assignment such as the following: • C and its descendants use braces to specify compound statements.
timeOut = 1 • All of these languages suffer because statement groups are always terminated
in the same way, which makes it difficult to determine which group is being
• The meaning of this statement is unclear, whereas in a language that ended when an end or a right brace appears.
includes Boolean types, we would have the following:
• Fortran 95 and Ada make this clearer by using a distinct closing syntax for each
timeOut = true type of statement group.
• The meaning of this statement is perfectly clear. • For example, Ada uses end if to terminate a selection construct and end loop to
terminate a loop construct.
• This is an example of the conflict between simplicity that results in fewer
reserved words, as in C++, and the greater readability that can result from using
more reserved words, as in Ada.

28 29

4. Syntax Design(2/2) Factor 2: Writability


• Form and meaning. Designing statements so that their appearance at least • Writability is a measure of how easily a language can be used to
partially indicates their purpose is an obvious aid to readability. create programs for a chosen problem domain.
• Semantics, or meaning, should follow directly from syntax, or form. • Most of the language characteristics that affect readability also
affect writability.
• In some cases, this principle is violated by two language constructs that are
• This follows directly from the fact that the process of writing a
identical or similar in appearance but have different meanings, depending program requires the programmer frequently to reread the part of the
perhaps on context. program that is already written.
• In C, for example, the meaning of the reserved word static depends on the • As is the case with readability, writability must be considered in the
context of its appearance. context of the target problem domain of a language.
• If used on the definition of a variable inside a function, it means the • For example, the writabilities of Visual BASIC (VB) and C are
variable is created at compile time. dramatically different for creating a program that has a graphical
user interface, for which VB is ideal.
• If used on the definition of a variable that is outside all functions, it means
– Simplicity and Orthogonality
the variable is visible only in the file in which its definition appears; that is,
– Support for Abstraction
it is not exported from that file.
– Expressivity

30 31
Simplicity and Orthogonality
• Smaller number of primitive constructs and a consistent set of rules for
combining them is much better than simply having a large number of
primitives. Support for Abstraction
• A programmer can design a solution to a complex problem after learning • Abstraction means the ability to define and then use complicated structures or
operations in ways that allow many of the details to be ignored.
only a simple set of primitive constructs. • Abstraction is a key concept in contemporary programming language design.
• On the other hand, too much orthogonality can be a detriment to writability. • This is a reflection of the central role that abstraction plays in modern program
design methodologies.
• Errors in programs can go undetected when nearly any combination of
• The degree of abstraction allowed by a programming language and the naturalness
primitives is legal. of its expression are therefore important to its writability.
• Programming languages can support two distinct categories of abstraction, process
and data.
• A simple example of process abstraction is the use of a subprogram to implement a
sort algorithm that is required several times in a program.
• Without the subprogram, the sort code would need to be replicated in all places
where it was needed, which would make the program much longer and more
tedious to write.

32 33

Expressivity
• In a language such as APL ,it means that there are very powerful operators
Factor 3: Reliability
that allow a great deal of computation to be accomplished with a very small
program. • A program is said to be reliable if it performs to its specifications under all
• More commonly, it means that a language has relatively convenient, rather conditions.
than cumbersome, ways of specifying computations. – Type Checking
• For example, in C, the notation count++ is more convenient and shorter – Exception Handling
than count = count + 1.
– Aliasing
• Also, the and then Boolean operator in Ada is a convenient way of
– Readability and Writability
specifying short-circuit evaluation of a Boolean expression.
• The inclusion of the for statement in Java makes writing counting loops
easier than with the use of while, which is also possible.
• All of these increase the writability of a language.

34 35
Type Checking
Exception Handling
• It is simply testing for type errors in a given program, either by the
• The ability of a program to intercept run-time errors (as well as other
compiler or during program execution.
unusual conditions detectable by the program), take corrective measures,
• Type checking is an important factor in language reliability. and then continue is an obvious aid to reliability. This language facility is
• Because run-time type checking is expensive, compile-time type checking called exception handling.
is more desirable. • Ada, C++, Java, and C# include extensive capabilities for exception
• Earlier errors in programs are detected, the less expensive it is to make the handling, but such facilities are practically nonexistent in many widely
required repairs. used languages, including C and Fortran.
• The design of Java requires checks of the types of nearly all variables and Aliasing
expressions at compile time. • Loosely defined, aliasing is having two or more distinct names that can be
• This virtually eliminates type errors at run time in Java programs. used to access the same memory cell.
• One example of how failure to type check, at either compile time or run • It is now widely accepted that aliasing is a dangerous feature in a
time, has led to countless program errors is the use of subprogram programming language.
parameters in the original C language. • Most programming languages allow some kind of aliasing—for example,
• An int type variable could be used as an actual parameter in a call to a two pointers set to point to the same variable, which is possible in most
function that expected a float type as its formal parameter, and neither the languages.
compiler nor the run-time system would detect the inconsistency

36 37

5. cost of a language is the cost of the language implementation system. One


Factor 4: Cost of the factors that explains the rapid acceptance of Java is that free
compiler/interpreter systems became available for it soon after its design
Total cost of a programming language is a function of many of its
was released.
characteristics.
6. cost of poor reliability. If the software fails in a critical system, such as a
1. cost of training programmers to use the language, which is a function of
nuclear power plant or an X-ray machine for medical use, the cost could
the simplicity and orthogonality of the language and the experience of the
be very high.
programmers
7. cost of maintaining programs, which includes both corrections and
2. cost of writing programs in the language. This is a function of the
modifications to add new functionality. The cost of software maintenance
writability of the language, which depends in part on its closeness in
depends on a number of language characteristics, primarily readability.
purpose to the particular application
3. cost of compiling programs in the language.
4. cost of executing programs written in a language is greatly influenced by
that language’s design. Optimization is the name given to the collection
of techniques that compilers may use to decrease the size and/or increase
the execution speed of the code they produce. If little or no optimization
is done, compilation can be done much faster than if a significant effort is
made to produce optimized code.

38 39
• Two of the primary components of a computer are its internal memory and
its processor.
• The internal memory is used to store programs and data.
• The processor is a collection of circuits that provides a realization of a set
of primitive operations, or machine instructions, such as those for
arithmetic and logic operations.
• In most computers, some of these instructions, which are sometimes called
macroinstructions, are actually implemented with a set of instructions
called microinstructions, which are defined at an even lower level.
• The machine language of the computer is its set of instructions.
Chapter 1 • In the absence of other supporting software, its own machine language is
the only language that most hardware computers “understand.”
IMPLEMENTATION METHODS • A language implementation system cannot be the only software on a
computer.
• Also required is a large collection of programs, called the operating system,
which supplies higher-level primitives than those of the machine language.

41 42

• These primitives provide system resource management, input and output


operations, a file management system, text and/or program editors, and a
variety of other commonly needed functions.
• The operating system and language implementations are layered over the • Compilation
machine language interface of a computer.
• These layers can be thought of as virtual computers, providing interfaces to • Pure Interpretation
the user at higher levels.
• Most computer systems provide several different virtual computers. • Hybrid Implementation systems
• User programs form another layer over the top of the layer of virtual
computers.
• Preprocessors
• The greatest success of those efforts was in the area of syntax analysis,
primarily because that part of the implementation process is an application
of parts of automata theory and formal language theory that were then well
understood.

43 45
Compilation
• Programming languages can be implemented by any of three general
methods.
• At one extreme, programs can be translated into machine language, which
can be executed directly on the computer.
• This method is called a compiler implementation and has the advantage
of very fast program execution, once the translation process is complete.
• Most production implementations of languages, such as C, COBOL, C++,
and Ada, are by compilers.
• The language that a compiler translates is called the source language.
• The process of compilation and program execution takes place in several
phases….

46 47

• The lexical analyzer gathers the characters of the source program into • The user and system code together are sometimes called a load module, or
lexical units. executable image.
• The lexical units of a program are identifiers, special words, operators,and • The process of collecting system programs and linking them to user
punctuation symbols. programs is called linking and loading, or sometimes just linking.
• The syntax analyzer takes the lexical units from the lexical analyzer and • It is accomplished by a systems program called a linker.
uses them to construct hierarchical structures called parse trees.
• The speed of the connection between a computer’s memory and its
• These parse trees represent the syntactic structure of the program. processor usually determines the speed of the computer, because
• The intermediate code generator produces a program in a different instructions often can be executed faster than they can be moved to the
language, at an intermediate level between the source program and the final processor for execution.
output of the compiler: the machine language program. • This connection is called the von Neumann bottleneck; it is the primary
• Optimization, which improves program by making them smaller or faster limiting factor in the speed of von Neumann architecture computers.
or both, is often an optional part of compilation. • The von Neumann bottleneck has been one of the primary motivations for
• The code generator translates the optimized intermediate code version of the research and development of parallel computers.
the program into an equivalent machine language program.
• The symbol table serves as a database for the compilation process.
• The primary contents of the symbol table are the type and attribute
information of each user-defined name in the program.

48 49
Pure Interpretation
• Pure interpretation lies at the opposite end (from compilation) of • It has a serious disadvantage that execution is 10 to 100 times slower than
implementation methods. in compiled systems.
• With this approach, programs are interpreted by another program called an • The primary source of this slowness is the decoding of the high-level
interpreter, with no translation. language statements, which are far more complex than machine language
• The interpreter program acts as a software simulation of a machine whose instructions.
fetch-execute cycle deals with high-level language program statements • Another disadvantage of pure interpretation is that it often requires more
rather than machine instructions. space.
• This software simulation obviously provides a virtual machine for the
language.
• Pure interpretation has the advantage of allowing easy implementation of
many source-level debugging operations, because all run-time error
messages can refer to source-level units.

50 51

• A Just-in-Time ( JIT) implementation


Hybrid Implementation Systems system initially translates programs to
an intermediate language.
• Some language implementation systems are a compromise between
• Then, during execution, it compiles
compilers and pure interpreters; they translate high-level language
intermediate language methods into
programs to an intermediate language designed to allow easy interpretation.
machine code when they are called.
• This method is faster than pure interpretation because the source language
• .NET languages are all implemented
statements are decoded only once. Such implementations are called hybrid
with a JIT system
implementation systems.
• Perl is implemented with a hybrid system. Perl programs are partially
compiled to detect errors before interpretation and to simplify the
interpreter.
• Initial implementations of Java were all hybrid. Its intermediate form,
called byte code, provides portability to any machine that has a byte code
interpreter and an associated run-time system. Together, these are called the
Java Virtual Machine

52 53
Preprocessors
• A preprocessor is a program that processes a program immediately before
the program is compiled.
• Preprocessor instructions are embedded in programs.
• The preprocessor is essentially a macro expander.
• Preprocessor instructions are commonly used to specify that the code from
another file is to be included.
• Examples
– #include "myLib.h“ causes the preprocessor to copy the contents of myLib.h into the
program at the position of the #include.
– #define max(A, B) ((A) > (B) ? (A) : (B)) to determine the largest of two given
expressions

54

You might also like