Introduction To Programmin Lanuages

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 44

Chapter 1

Introduction to
Programming Languages

compiled by: Tigabu Y.


1
Definition of programming language
History of Programming Languages
Programming Domains and Role of
programming languages

Why study programming languages?


Attributes of good programming language
2
1. Introduction
Definition of programming language
• A program is a description of a set of actions that we want a
computer to carry out.
• A programming language is an artificial language used to
write instructions that can be translated into machine
language and then executed by a computer.
• Both programming languages and natural languages have:
• Syntax (form)
• how expressions, commands, declarations, and other constructs
must be arranged to make a well‐formed program.

• Semantics (meaning)
• how a well‐formed program may be expected to behave when
executed on a computer
3
1. Introduction
History of Programming Languages

Period Languages Developed


1950s FORTRAN, LISP
1960s Simula, COBOL, RPG, ALGOL, PL1
1970s Ada, C, Pascal, Prolog, Small Talk
1980s C++, ML, Eiffel, Visual languages
1990s Java, Hypermedia languages, Visual
languages, Ada 95
2000s Kotkin, Erlang, Go, OCaml, TypeScript, Rust,
Elm, Crystal, Elixir, R, Swift, Haskell, Clojure,
C#, Python, Ruby, Scala
Table 1: Summary of the History of Programming Languages
4
1. Introduction
Programming Domains and Role of programming
Computers have been applied to different areas, from
controlling nuclear power plants to providing video games
in mobile phones.

Because of this great diversity in computer use,


programming languages with very different goals have
been developed.

5
1. Introduction
Programming Domains and Role of programming
languages
Programming languages are used to solve problems using
computers in various domains such as:

Scientific Applications
Business Applications
Artificial Intelligence
Systems Programming
Web Applications
6
1. Introduction
Role of programming languages
 Scientific Applications
 The first digital computers (appeared in the late 1940s)
were invented and used for scientific applications.
 Typically, the scientific applications of that time used
relatively simple data structures, but require large
numbers of floating-point arithmetic computations.
 The most common data structures are arrays and
matrices.
 The most common control structures are counting
loops and selections.
 The early high-level programming languages invented
for scientific applications were designed to provide for
those needs. The first language for scientific
applications was Fortran. 7
1. Introduction
Role of programming languages
 Business Applications
 Special computers were developed for business
application purpose, along with special languages.
 Commercial data processing was one the earliest
commercial applications of computers.
 Business languages are characterized by facilities for
 Producing elaborate reports
 Precise ways of describing and storing decimal
numbers and character data
 The ability to specify decimal arithmetic operations
 Example: COBOL
 The U.S. Defense Dept. sponsored the effort to develop
COBOL (Common Business-Oriented
8 Language)
1. Introduction
Role of programming languages
 Artificial Intelligence
 Deals with emulating human intelligence(human-style
reasoning) on a computer .
 is the search for a way to map intelligence into
mechanical hardware and enable a structure into that
system to formalize “thought”.
 Examples
 LISP
 Prolog

9
1. Introduction
Role of programming languages
 Systems Programming
 The operating system and all of the programming support
tools of a computer system are collectively known as its
systems software.
 Assembly languages were used for a very long time operating
Systems programming because of its power and efficiency.
 CPL, BCPL, C and C++ were later developed for this purpose.
 Other languages for systems programming included PL/I,
BLISS, and extended ALGOL.

10
1. Introduction
Role of programming languages
 Web Applications
 The World Wide Web is supported by an eclectic collection of
languages, ranging from markup languages, such as XHTML,
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
 This functionality can be provided by embedding
programming code in an XHTML document
 Such code is often in the form of a scripting language,
such as JavaScript or PHP.
11
1. Introduction
 Benefits of studying programming languages?
• Increased capacity to express ideas
 The language in which programmers use to develop software
places limits on the kind of control structures, data
structures, abstractions they use.
 Awareness of wider variety of programming language
features can reduce the above limitations.
 Programmers can increase the range of their software
development thought processes by learning new language
constructs.
• Improved background for choosing appropriate languages
 If a programmer is familiar with basic programming language
features and continues to learn new languages, S/he will be in
a good position to choose an appropriate language.
 Example: Consider a linked12 list in C++ and a list class in C#
1. Introduction
 Benefits of studying programming languages?
• Improved background for choosing appropriate languages
 Many professional programmers have a limited formal education;
rather, they have developed their programming skills independently or
through in-house training programs.
 Such training programs often limit instructions to one or two languages
that are relevant to the current projects.
 Many other programmers receive their formal training years ago.,
 The languages they learned then are no longer used
 Many features now available in pls were not widely known that time
 The result is that many programmers, when given a choice of languages
for a new project, use the language with which they are most familiar,
even if it is poorly suited for the project at hand.
 If these programmers were familiar with a wider range of languages and
language constructs, they would be better able to chose the language
with the features that best address the problem.
13
1. Introduction
 Benefits of studying programming languages?
• Improved background for choosing appropriate languages
 Knowledge of a variety of languages may allow the choice
of just the right language for a particular project, thereby
reducing the required coding effort.
 Some languages are better for some jobs than others
 For example:
 Applications requiring numerical calculations: C,
FORTRAN or Ada.
 Developing applications useful in decision making,
such as AI applications: LISP, ML, or Prolog.
 Internet applications are more readily designed using
Perl and Java
 Report generations: COBOL
14
and RPG
1. Introduction
• Increased ability to learn new languages
Computer science is a relatively young discipline and
most software technologies (design methodologies,
software development tools, and programming
languages) are not yet mature. Therefore, they are still
evolving.
Once a thorough understanding of the fundamental
concepts of a particular programming language is
acquired, it makes it easier to learn new languages.
 For example, programmers who understand the
concepts of object-oriented programming will have a
much easier time learning Java than those who have
never used those.
15
1. Introduction
• Increased ability to learn …. Cont’d
It is easier to learn a new language if you
understand the underlying structures of language.
Examples:
 It is easier for a BASIC program to FORTRAN than C.
 It is easier for a C++ programmer to learn Java.
 It is easier for a Scheme programmer to learn LISP.

16
1. Introduction
• Better understanding of the significance of implementation
 It is often necessary to learn about language implementation
issues as understanding of implementation issues can lead to a
better understanding of why the language was designed the
way it was.
 In turn, this knowledge leads to the ability to use a language
more intelligently, as it was designed to be used.
 Fixing some bugs requires an understanding of
implementation issues

17
1. Introduction
• Better understanding of the significance of implementation
 Understanding implementation issues helps to visualize how a
computer executes various language constructs
 This understanding in turn helps to evaluate efficiency of
alternative constructs
 Example-1: Programmers who know little about how recursion
is implemented often do not know that a recursive algorithm
can be far slower than an equivalent iterative algorithm
 Example-2: Programmers who know little about the complexity
of the implementation of subprogram calls often do not realize
that a small subprogram that is frequently called can be a highly
inefficient design choice. (Think of inline function)

18
1. Introduction
• Better use of languages that are already known
 By understanding how features in our programming
language are implemented, you are greatly increase your
ability to write efficient programs.
 For example,
 understanding how data structures are created and
manipulated by your language, knowing how the
implementation details of recursion, or understanding how
object classes are built allows you to build more efficient
programs consisting o such components.
 Data
 arrays, strings, lists or records

19
1. Introduction
• Overall advancement of computing
 Why a particular programming language become
popular while it is not the best available?
 Among other reasons, those who are in a position to choose
programming languages were not sufficiently informed about
programming language concepts

• Example: ALGOL60 and FORTRAN


 ALGOL60 had
o Block structure
o Much better control statements
o Recursion
• The reason why ALGOL60 did not replace FORTRAN in the
1960s was due to lack of understanding of the conceptual
design of ALGOL60
20
1. Introduction
• Overall advancement of computing
 If the people who were in a position to choose
programming languages were sufficiently informed
about programming language concepts, better
languages would eventually squeeze the poorer ones.

Better computing advancement

21
1. Introduction
 Attributes of good programming language

22
1. Introduction
 Attributes of good programming language
Readability – the ease with which programs can be read
and understood.
Writability – the ease with which programs can be
developed for a given program domain.
Reliability – the extent to which a program will perform
according to its specifications.
Cost- the ultimate total cost

23
1. Introduction
 Attributes of good programming language
Readability
• Overall Simplicity
• A language that has a set of large number of basic
constructs is more difficult to learn than one with a
smaller number.
• Multiplicity(that is, having more than one way to
accomplish a particular operation) of features provide
flexibility, but can lead to increased difficulty in
learning the language.
• for example, in C++ and Java, you can increment a
variable in four ways: x =x+1; x+=1; x++; ++x
• Operator overloading, in which a single operator
symbol has more than24one meaning. though powerful,
is potentially confusing.
1. Introduction
 Attributes of good programming language
Readability
• Orthogonality
• Orthogonality in a programming language means that a
relatively small set of primitive constructs can be combined
in a relatively small number of ways to build the control and
data structures of the language.
 Every possible combination of primitives is legal
and meaningful.
• For example, consider data types. Suppose a language has
four primitive data types (integer, float, double, and
character) and two type operators (array and pointer). If
the two type operators can be applied to themselves and
the four primitive data types, a large number of data
structures can be defined.
25
1. Introduction
 Attributes of good programming language
Readability
• Orthogonality
• Orthogonality is closely related to simplicity:
• The more orthogonal the design of a language, the
fewer exceptions the language rules require
• Fewer exceptions mean a higher degree of regularity in
the design, which makes the language easier to learn,
read, and understand
• Anyone who has learned a significant part of the
English language can testify to the difficulty of learning
its many rule exceptions (for example, i before e except
after c)
• Example: Receive and Believe

26
1. Introduction
 Attributes of good programming language
Readability
• Data Types
• The presence of adequate facilities for defining data types
and data structures in a language is another significant aid
to readability.
• For example, suppose a numeric type is used for an
indicator flag because there is no Boolean type in the
language. In such a language, we might have an assignment
such as the following:
timeOut = 1
• The meaning of the above statement is unclear, whereas in
a language that includes Boolean types, we would have the
following:
timeOut = true
• The meaning of the above27 statement is perfectly clear.
1. Introduction
 Attributes of good programming language
Readability
• Syntax Design
• The following are examples of syntactic design choices that
affect readability:
1. Identifier forms.
• Restricting identifiers to very short lengths decreases
readability.
• Older languages (like FORTRAN) restrict the length of
identifiers, which become less meaningful.
• Should be flexible composition

28
1. Introduction
 Attributes of good programming language
Readability
• Syntax Design
• The following are examples of syntactic design choices that
affect readability:
2. Special words:
 in addition to while, do and for, some languages use
special words to close structures such as endif and
endwhile.

29
1. Introduction
 Attributes of good programming language
Readability
• Syntax Design
• The following are examples of syntactic design choices that
affect readability:
3. Form and Meaning
• Designing statements so that their appearance
at least partially indicates their purpose is an
obvious aid to readability.
• Consider the static keyword in C
• If used on the definition of a variable inside
a function, it means the 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 30
1. Introduction
 Attributes of good programming language
Writability
• Writability is a 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.
• Simplicity and Orthogonality
• A smaller number of primitive constructs and a consistent
set of rules for combining them (that is, orthogonality) is
much better than simply having a large number of
primitives.
• On the other hand, too much orthogonality can be a
detriment (damage) to writability.
• Errors in programs can go undetected when nearly any
combination of primitives is legal. This can lead to code
absurdities that cannot be discovered by the compiler.
31
1. Introduction
 Attributes of good programming language
Writability
• Support for Abstraction
• The ability to define and use complex structures or
operations in ways that allow details to be ignored.
• 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
• Data Abstraction (Read: Ref [7], page 14)
32
1. Introduction
 Attributes of good programming language
Writability
• Expressivity
• it means that there are very powerful operators that allow
a great deal of computation to be accomplished with a very
small program
• More commonly, it means that a language has a set of
relatively convenient, rather than cumbersome, ways of
specifying computations.
 For example, in C/C++, the notation count++ is more
convenient and shorter than count = count + 1.

33
1. Introduction
 Attributes of good programming language
Reliability
• A program is said to be reliable if it performs to its specifications
under all conditions.
• Reliability is the assurance that a program will not behave in
unexpected or disastrous ways during execution.
• Type Checking
• it is simply testing for type errors in a given program, either by the
compiler or during program execution.

34
1. Introduction
 Attributes of good programming language
Reliability
• Type Checking
• Because run-time type checking is expensive, compile-time type
checking is more desirable (Run-time: Requires checking time
every time the program runs. )
• Furthermore, the earlier errors in programs are detected, the less
expensive it is to make the required repairs.
• The design of Java requires checks of the types of nearly all
variables and expressions at compile time.
• This virtually eliminates type errors at run time in Java
programs
35
1. Introduction
 Attributes of good programming language
Reliability
• Exception Handling
• The ability of a program to intercept run-time errors (as
well as other unusual conditions detectable by the
program), take corrective measures, and then continue is
an obvious aid to reliability.
• This language facility is called exception handling. Ada, C++,
Java, and C# include extensive capabilities for exception
handling
• Usually implemented in a try….catch….finally Block

36
1. Introduction
 Attributes of good programming language
Reliability
• Aliasing
• having two or more distinct names that can be used to
access the same memory cell
• Most programming languages allow some kind of aliasing—
for example, two pointers set to point to the same variable,
which is possible in most languages
• In such a program, the programmer must always remember
that changing the value pointed to by one of the two
changes the value referenced by the other.

37
1. Introduction
 Attributes of good programming language
Cost
• The total cost of a programming language is a function of many
of its characteristics: Cost of
 training programmers
 writing programs (Writability)
 compiling programs
 executing programs (if many run-time type checking)
 language implementation system (cheap or free
compiler /interpreter)
 poor reliability
 maintaining programs 38
1. Introduction
 Attributes of good programming language
 Evaluation Criteria: others
 Portability
• The ease with which programs can be moved from one
implementation to another
 Generality
• The applicability to a wide range of applications
 Well-definedness
• The completeness and precision of the language‘s official
definition
• .

39
1. Introduction
 Attributes of good programming language
Naturalness
• A good language should be natural for the application area it has
been designed.
 It should provide appropriate operators, data structures,
control structures, and a natural syntax in order to
facilitate the users to code their problem easily and
efficiently.

 FORTRAN------Scientific application
 COBOL----------Business software

40
1. Introduction
 Attributes of good programming language
Simplicity
• A good programming language must be simple and easy to
learn and use.
• For example, BASIC is liked by many programmers only
because of its simplicity.
• Thus, a good programming language should provide a
programmer with a clear, simple and unified set of
concepts which can be easily grasped.
• It is also easy to develop and implement a compiler or an
interpreter for a programming language that is simple.
• However, the power needed for the language should not be
sacrificed for its simplicity

41
1. Introduction
 Attributes of good programming language
Efficiency
• The program written in good programming language
 efficiently translated into machine code
 efficiently executed
 requires as little space in the memory as possible.
• That is, a good programming language is supported with a
good language translator (a compiler or an interpreter) that
takes consideration to space and time efficiency.

42
1. Introduction
 Attributes of good programming language
Locality
• A good programming language should be such that while
writing a program, a programmer need not jump around
visually as the text of the program is prepared.
• This allows the programmer to concentrate almost solely on
the part of the program around the statements currently being
worked with
• COBOL lacks locality because data definitions are separated
from processing statements, perhaps by many pages of code.
43
Summary Questions
1. Define Computer program and Programming language
2. Discuss with examples what we mean by Syntax and
Semantics with respect to natural languages and programming
languages.
3. List the benefits of studying general programming language
features.
4. Write one possible reason why ALGOL60 didn’t replace
FORTRAN in the early 1960s.
5. Discuss at least four of attributes of a good programming
language
44

You might also like