Modern Programming Languages
Modern Programming Languages
Course Objectives
over the last 60 years. The questions that come to mind are:
In addition, we will discuss the design issues of various languages, design choices and
alternatives available, historical context and specific needs, and specific implementation issues.
Text Book
1
Introduction and Historical Background
The first question is: why should we study programming languages. There are many
reasons for that and some of them are enumerated in the following paragraphs.
2
By learning a number of programming languages, one gets to know the pros and cons of
different language features and issues related to these features. This knowledge will
therefore help if one has to design a new language for any purpose.
Readability
Readability is directly related to the cost of maintenance. The different factors that impact
readability are:
– Simplicity
– Control Statements
– Data types and data structures
– Syntax Considerations
Simplicity
A simple language will be easy to learn and hence understand. There are a number of
factors that account for simplicity. These are:
• Number of basic components
Learning curve is directly proportional to the number of basic components. If a
language has more basic components, it will be difficult to learn and vice-versa. It is
important to note that one can learn a subset of a programming language for writing
you must know everything.
Feature multiplicity
If a language has more than one way to accomplish the same task, then it can
cause confusion and complexity. For example, a number can be incremented in C
in any of the following manners.
i = i + 1;
i++;
++i;
i += 1;
If a programmer has used all these different constructs to increment a variable at
different locations, the reader may get confused. It is simpler to adopt one
structure and use it consistently.
• Operator overloading
3
Operator overloading can be problematic if its use is inconsistent orunconventional.
Simplicity has another dimension as well. If a language is very simple then its level may
also be decreased as it may loose abstraction. In that case, it will bedifficult to write and
read algorithms in that language.
Control Statements
Control statements also play an important role in readability. We are all aware of the
hazards of goto statement. If a language relies on goto statements for control flow, the
logic becomes difficult to follows and hence understand and maintain. Restricted use of
goto in extreme was needed and useful as well but with the emergence of new language
constructs to handle those situations, it probably not an issue any more.
Data types and data structures also play an important role in improving the abstraction
level of a programming language, hence making it more readable. For example, a
simple omission of Boolean type in C resulted in many problems as integers were
instead of Boolean which made the program difficult to follow and debug in many
cases.
Similarly, in FORTRAN there was no record (or struct) type. So related data had to be
put in different data structures, making it very difficult to read the logic and maintain.
Syntax
Syntax of a language plays a very important role in programming languages. There are
many different considerations that we will discuss throughout this course. Here we give a
brief overview of some of these considerations.
Variable names
The first consideration is the restriction of variable names. In the beginning it was
a huge issue as some languages restricted the length of a variable name up to 6 or
8 characters making it difficult to choose meaningful names for the variable.
Other considerations include the type of special characters allowed in the variable
names to improve readability.
• Special keywords for signaling the start and end of key words.
Some languages allow special keywords for signaling the start and end of a
construct, making it more readable and less prone to errors. This can be elaborated
with the help of following examples:
Let us first consider the following C if statement.
4
if (some condition)
// do this
// now do this
It may be noted that the second part “// now do this” is not part of the body of the if statement
and it will be executed regardless of the truth value of the condition. This may cause problems
as it is easy for the reader to miss this point because of indentation.
Ada programming language solves this problem by using the keywords “then” and “end if” in
the if statement. The resulting code is shown below:
-- do this
end if
-- now do this
Now it can be easily seen that a reader of this program will not be confused by the indentation.
Another similar example is when the if has an else part also. Let us first consider the following C
code.
if (cond1)
if (cond2)
// do 1
else if (cond3)
// do 2
else
// do 3
Is the last else part of third if or the first one? Once again the indentation has caused this
confusion and the reader can easily miss this point. Ada has solved this problem by introducing
an elsif keyword. The Ada code is shown below and it can be seen very easily that the confusion
has been removed.
if (cond1) then
if (cond2) then
-- do 1
elseif (cond3) then
-- do 2
end if;
5
else
-- do 3
end if;
Writability
Writability is a measure of support for abstraction provided by a language. It is the ability
to define and use complicated structures without bothering about the details. It may be
noted that the degree of abstraction is directly related to the expressiveness. For example,
if you are asked to implement a tree, it will be a lot difficult in FORTRAN as compared
to C++. It also is a measure of expressivity: constructs that make it convenient to write
programs. For example, there is a set data type in Pascal which makes it easier to handle
set operations as compared to a language such as C++ where this support is not available.
Reliability
Reliability is yet another very important factor. A programming language should enable
the programmers to write reliable code. The important attributes that play an important
role in this respect are listed below:
• Type Checking
Type checking is related with checking the type of the variables used as operands
in different. The question that needs to be addressed is whether this type checking
is done at compile time or at run-time. This also includes checking types of
parameters and array bounds. Traditionally, these two have been the major
sources of errors in programs which are extremely difficult to debug. A language
that does type checking at compile time generates more reliable code than the one
that does it at run-time.
• Exception handling
Exception handling enables a programmer to intercept run-time errors and take
corrective measure if possible and hence making it possible to write more reliable
code.
• Aliasing
Loosely defined, when there are two or more names are used to access the same
memory cell, the concept is called aliasing. Aliasing is useful but need extreme
care when used as it may lead to critical errors and thus threaten reliability .
6
Cost
Cost is also a very important criterion for comparing and evaluating programming language. In
order to understand the cost involved, one has to consider the following:
• Training cost – how much does it cost to train a new programmer in this language.
• What is the cost of writing programs in the language – this is a measure of productivity
• What is the cost of the development environment and tools?
• What is the compilation cost? That is, how long does it take to compile a program.
This is related to productivity as the more time it takes to compile a program, the
more time a programmer will be sitting idle and hence there will be a reduction in
productivity.
• Execution cost is also an important factor. If the program written in a language
takes more execution time then the overall cost will be more.
• A related is whether to have a more optimized code or to increase the compilation speed
• Cost of language implementation deals with the level of difficulty in terms of
writing a compiler and development environment for the language.
• If the program written in a particular language is less reliable than the cost of
failure of the system may be significant.
• The most important of all of these factors is the maintenance cost. It is a function
of readability.
Portability
Portability deals with how easy it is to port a system written in a given programming
language to a different environment which may include the hardware and the operating
system. In today’s heterogeneous environment, portability is a huge issue. Portability has
to do a lot with the standardization of a language. One of the reasons the programs written
in COBOL were less portable than JAVA was because JAVA was standardized very early whereas
there was not universal standard available for COBOL.
Generality
Generality is also an important factor and deals with the applicability of the language to a
7
range of different domains. For example, C is more general purpose than LISP or
FORTRAN and hence can be used in more domains than these two languages.In contrast COGO
is a special purpose language design for Civil engineers and thus work in specific domain.
Issues and trade-offs
Like all design problems, in the case of programming language design, one has to deal
with competing criterion such as execution versus safety, readability versus writability,
and execution versus compilation. It would be nice if one could assign weights to
different criteria and then compare the different options. Unfortunately, this kind of help
is not available and hence the balancing act, as usual, is a very difficult job.