lecture1
lecture1
1
Lecture 1:
Introduction to Programming
Language
s
What is a (Programming)
Language?
A language is a vocabulary and set of
grammatical rules for communication between
people.
4
Q: How many Programming Languages do
you know?
5
How many programming languages are out
there?
700 +
Source: Wikipedia (excluding dialects of BASIC)
https://en.wikipedia.org/wiki/List_of_programming_langua
ges
6
New Languages will Keep Coming
7
Be prepared to program in new
languages
Languages undergo constant
– FORTRAN
change 195
– ALGOL 3
60 196
– C 0
– C++ 197
– Java 3
Evolution steps: 12 years per widely adopted
198
language 5
– are we overdue for the next big one?
199
... or is the language
5 already here?
– Hint: are we going through a major shift in what
computation programs need to express?
– your answer here: 1
Pytho 1 11
Language as a thought shaper
We will cover less traditional languages, too.
The reason:
10
Slide from Ras 13
Bodik
Programming the ENIAC
11
Slide from Ras 13
Bodik
ENIAC (1946, Univ. of Philadelphia)
programming done by
– rewiring the interconnections
– to set up desired formulas, etc
Problem (what’s the tedious
part?)
– programming = rewiring
– slow, error-prone
solution:
– store the program in memory!
– birth of von Neuman paradigm
Slide from Ras 15
Bodik
Reasons for Studying Concepts of
Programming Languages
Increased Ability to Express Ideas
• Natural languages:
– The depth at which people think is influenced by the
expressive power of the language.
– The more appropriate constructs you have, the easier it is
to communicate.
– It is difficult for people to conceptualize structures that
they cannot describe verbally.
18
Increased Ability to Express Ideas
• Programming Languages:
– This is similar for PL’s. The language in which you develop
software puts limits on the kinds of data structures,
control structures and abstractions that can be used.
– Awareness of a wider variety of programming language
features can reduce such limitations in software
development.
– Programmers increase the range of software development
by learning new language constructs.
– For example, if you learn associate arrays in Perl, you can
simulate them in C.
19
Improved background for choosing
appropriate languages
• Not every programming language can be suitable for all
the software requirements.
• Many programmers learn one or two languages specific
to the projects.
• Some of those languages may no longer be used.
• When they start a new project they continue to use
those languages which are old and not suited to the
current projects.
20
Improved background for choosing
appropriate languages
• However another language may be more appropriate
to the nature of the project.
– Lots of text processing -> Perl may be a good option.
– Lots of matrix processing -> MATLAB can be used.
2
TIOBE programming community 3
Languages in common use (2020)
24
Languages in common use (2022)
25
Languages in common use (today)
2
TIOBE programming community 6
Better understanding of significance of
implementation
• The best programmers are the ones having at least
understanding of how things work under the hood
– Understand the implementation issues
• You can simply write a code and let the compiler do
everything, but knowing implementation details
helps you to use a language more intelligently and
write the code that is more efficient
• Also, it allows you to visualize how a
computer executes language constructs
– Cost optimization; e.g. recursion is slow
27
Better use of languages that are already
known
28
Overall advancement of computing
• New ways of thinking about computing, new technology,
hence need for new appropriate language concepts
• Not to repeat history
– Although ALGOL 60 was a better language (with better block
structure, recursion, etc) than FORTRAN, it did not become
popular. If those who choose languages are better informed,
better languages would be more popular.
29
Develop your own language
Are you kidding? No. Guess who
developed:
– PHP
– Ruby
– JavaScript
– Perl
Done by smart hackers like you
– in a garage
– not in academic ivory tower
Our goal: learn good academic lessons
– so that your future languages avoid known
mistakes
3
0
Slide from Ras
Ability to Design New Languages
• You may need to design a special purpose language
to enter the commands for a software that you
develop.
– A language for an robotics interface
31
Language Evaluation Criteria
The main criteria needed to evaluate
various constructs and capabilities of
programming languages
• Readability
• Writability
• Reliability
• Cost
32
33
Language Evaluation Criteria
The main criteria needed to evaluate
various constructs and capabilities of
programming languages
• Readability
• Writability
• Reliability
• Cost
34
Readability
Ease with which programs can be read and understood
• in the early times, efficiency and machine readability was
important
• 1970s-Software life cycle: coding (small) + maintenance
(large)
Readability is important for maintenance
• Characteristics that contribute to readability:
– Overall simplicity
– Orthogonality
– Control statements
– Data types and structures
– Syntax Considerations
35
Overall Simplicity
• A manageable set of features and constructs
– Large number of basic components - difficult to learn
• Minimal feature multiplicity
– Feature multiplicity: having more than one way to
accomplish an operation
• e.g. In Java
count = count + 1
count += 1
count ++
++count
37
Overall Simplicity
• Minimal operator overloading
– Operator overloading: a single operator symbol has more than
one meaning
– This can lead to reduced readability if users are allowed to create
their own and do not do it sensibly
Example:
• using + for integer and floating point addition is
acceptable and contributes to simplicity
• but if a user defines + to mean the sum of all the elements
of two single dimensional arrays is not, different from
vector addition
• Simplest does not mean the best
– Assembly languages: Lack the complex control statements, so
program structure is less obvious
38
Orthogonality
• 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.
• Example:
– Four primitive data types : integer, float, double and
character
– 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
– However, if pointers were not allowed to point to arrays, many
of those useful possibilities would be eliminated
39
Orthogonality
• Example : Adding two 32-bit integers residing in memory or
registers, and replacing one of them with the sum
43
Syntax considerations
• Identifier Forms:
– restricting identifier length is bad for readability.
• FORTRAN77 identifiers can have at most 6 characters.
• ANSI BASIC : an identifier is either a single character or a single character
followed by a single digit.
– Availability of word concatenating characters (e.g., _ ) is good
for readability.
• Special Words: Readability is increased by special words(e.g.,
begin, end, for).
– In PASCAL and C, end or } is used to end a compound statement. It is
difficult tell what an end or } terminates.
For example,
sin(x) => should be the sine of x,
not the sign of x or cosign of x.
• grep is hard to understand for the people who are
not familiar with using regular expressions
grep : g/reg_exp/p
=> /reg_exp/ : search for that reg_exp
g: scope is whole file , make it global
p:print
45
Language Evaluation Criteria
The main criteria needed to evaluate
various constructs and capabilities of
programming languages
• Readability
• Writability
• Reliability
• Cost
46
Writability
• Ease of creating programs
• Most of the characteristics that contribute to readability
also contribute to writability
• Characteristics that contribute to writability
– Simplicity and Orthogonality
– Support for abstraction
– Expressivity
• Writability of a language can also be application
dependent
47
Writability
• Simplicity and orthogonality
– Few constructs, a small number of primitives, a small set of rules
for combining them
• Expressivity
– A set of relatively convenient ways of specifying operations
– Strength and number of operators and predefined functions
48
Simplicity and orthogonality
• Simplicity and orthogonality are also good for writability.
• When there are large number of constructs, programmers
may not be familiar with all of them, and this may lead to
either misuse or disuse of those items.
• A smaller number of primitive constructs (simplicity) and
consistent set of rules for combining them (orthogonality)
is good for writability
• However, too much orthogonality may lead to undetected
errors, since almost all combinations are legal.
49
Support for abstraction
• Abstraction: ability to define and use complicated structures
and operations in ways that allows ignoring the details.
• PLs can support two types of abstraction:
– process
– data
• Abstraction is the key concept in contemporary
programming languages
• The degree of abstraction allowed by a
programming language and the naturalness of its
expressions are very important to its writability.
50
Process abstraction
• The simplest example of abstraction is subprograms
(e.g., methods).
• You define a subprogram, then use it by ignoring
how it actually works.
• Eliminates replication of the code
• Ignores the implementation details
– e.g. sort algorithm
51
Data abstraction
• As an example of data abstraction, a tree can be
represented more naturally using pointers in nodes.
• In FORTRAN77, where pointer types are not available, a
tree can be represented using 3 parallel arrays, two of
which contain the indexes of the offspring, and the last
one containing the data.
52
Expressivity
• Having more convenient and shorter ways of
specifying computations.
• For example, in C,
count++;
is more convenient and expressive than
count = count + 1;
54
Reliability
Reliable: it performs to its specifications under all
conditions
• Type checking
– Testing for type errors
• Exception handling
– Intercept run-time errors and take corrective measures
• Aliasing
– Presence of two or more distinct referencing methods for the same memory
location
• Readability and writability
– The easier a program to write, the more likely it is correct.
– Programs that are difficult to read are difficult both to write and modify.
55
Type Checking
• Testing for type errors in a given program either by the
compiler or during program execution
• The compatibility between two variables or a variable and
a constantthat are somehow
related (e.g., assignment, argument
of an operation, formal and actual
parameters of a method).
• Run-time (Execution-time) checking is expensive.
• Compile-time checking is more desirable.
• The earlier errors in programs are detected, the less
expensive it is to make the required repairs
56
Type Checking
• Original C language requires no type checking neither in
compilation nor execution time. That can cause many problems.
– Current version required all parameters to be type-
checked
• For example, the following program in original C compiles and
runs!
foo (float {
a) %g and square(a): %g\n”, a,a*a);
} printf (“a:
main () {
char z =
‘b’;
foo(z);
}
• Output is : a: 98 and square(a):
9604 57
Language Evaluation Criteria
The main criteria needed to evaluate
various constructs and capabilities of
programming languages
• Readability
• Writability
• Reliability
• Cost
60
Cost
• Types of costs:
1. Cost of training the programmers: Function
of simplicity and orthogonality, experience of
the programmers.
2. Cost of writing programs: Function of the
writability
Note: These two costs can be reduced in a good
programming environment
3. Cost of compiling programs: cost of compiler,
and time to compile
• First generation Ada compilers were very costly
61
Cost
4. Cost of executing programs: If a language requires
many run-time type checking, the programs written
in that language will execute slowly.
– Trade-off between compilation cost and execution
cost.
– Optimization: decreases the size or increases
the execution speed.
• Without optimization, compilation cost can be reduced.
• Extra compilation effort can result in faster execution.
• More suitable in a production environment, where
compiled programs are executed many times
62
Cost
5. Cost of the implementation system. If expensive or
runs only on expensive hardware it will not be widely
used.
6. Cost of reliability – important for critical systems such
as a power plant or X-ray machine
7. Cost of maintaining programs. For
corrections, modifications and additions.
• Function of readability.
• Usually, and unfortunately, maintenance is done by people
other that the original authors of the program.
• For large programs, the maintenance costs is about 2 to 4
times the development costs.
63
Other Criteria for Evaluation
• 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
64
Language Design Trade-Offs
• Reliability vs. cost of execution
– Example: Java demands all references to array
elements be checked for proper indexing, which
leads to increased execution costs
6
How does Zen of Python relate to Language Evaluation 6
Programming Domains
• Scientific Applications (first digital computers –1940s)
– Large floating-point arithmetic, execution efficiency, arrays and matrices,
counting loops
– Examples: FORTRAN, ALGOL 60, C
• Artificial Intelligence
– Symbolic programming (names rather than numbers, linked lists rather than
arrays)
– Examples: LISP(1959),PROLOG(early1970s)
67
Programming Domains (cont’d.)
• Systems Programming
– System software: Operating system and all of the programming support tools
of a computer system
– Efficient and fast execution, low-level features for peripheral device drivers
– Examples: PLS/2(IBM Mainframe), BLISS (Digital), C (Unix)
• Scripting Languages
– List of commands (Script) to be executed is put in a file.
– Examples:sh, csh, tcsh, awk, gawk, tcl, perl, javascript
• Special-Purpose languages
– Examples: RPG (Business Reports), SPICE (Simulation of Electronic Circuitry),
SPSS (Statistics), Latex (Document preparation). HTML, XML (web prog.)
68
Language Categories
• Imperative
– Central features are variables, assignment
statements, and iteration
– Include languages that support object-oriented
programming
– Include scripting languages
– Include the visual languages
– Examples: C, Java, Perl, Visual BASIC .NET, C++
• Functional
– Main means of making computations is by applying
functions to given parameters
– Examples: LISP, Scheme, ML, F#
• Logic
– Rule-based (rules are specified in no particular order)
– Example: Prolog
• Markup/programming hybrid
– Markup languages extended to support some
programming 69
– Examples: JSTL, XSLT
“Hello World” in different languages
https://www.geeksforgeeks.org/hello-world-in-30-different-languages/
70
Java
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
71
Assembly Language
bdos equ 0005H ; BDOS entry point
start: mvi c,9 ; BDOS function: output string
lxi d,msg$ ; address of msg
call bdos ret ; return to CCP
msg$: db 'Hello, world!$'
end start
72
FORTRAN
PROGRAM
HELLO
WRITE(*,10)
10 FORMAT('Hello, world!')
STOP
END
73
COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-
WORLD. ENVIRONMENT
DIVISION. DATA
DIVISION.
PROCEDURE DIVISION.
DISPLAY "Hello, world!".
STOP RUN.
74
Ada
with Ada.Text_Io;
procedure Hello is
begin
Ada.Text_Io.Put_Line ("Hello, world!");
end Hello;
75
C
#include <stdio.h>
int main()
{
printf("Hello, world!\n");
return 0;
}
76
C++
#include <iostream>
int main()
{
std::cout <<
"Hello, world!\
n";
}
77
C#
using System;
class HelloWorldApp
{
public static void Main()
{
Console.WriteLine("Hello, world!");
}
}
78
Scala
object HelloWorld extends App {
println("Hello, World!")
}
79
LISP
(format t "Hello world!~%")
80
PERL
print "Hello, world!\n";
81
Prolog
write('Hello world'),nl.
82
Python
print("Hello World!")
83
Swift
import Swift
print(“Hello World!”)
84
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hello, world!</title>
<meta http-equiv="Content-Type“ content="text/html;
charset=UTF-8">
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
85
Summary
• The study of programming languages is valuable for a number
of reasons:
– Increase our capacity to use different constructs
– Enable us to choose languages more intelligently
– Makes learning new languages easier
86
An optional exercise
List three new languages, or major features added to established major languages, that have appeared in the last
seven years. For each language, answer with one sentence these questions:
• Why did the languages appear? Or, why have these features been added? Often, a new language is motivated by
technical problems faced by programmers. Sometimes the motivation for a new feature is cultural, related to,
say, the educational background of programmers in a given language.
• Who are the intended users of this language/feature? Are these guru programmers, beginners, end-users (non-
programmers)?
• Show a code fragment that you find particularly cool. The fragment should exploit the new features to produce
highly readable and concise code.
Links that may help you start your exploration of the programming language landscape:
• http://lambda-the-ultimate.org/
• http://bit.ly/ddH47v
• http://www.google.com