Chapter 2 - Language Design Issues
Chapter 2 - Language Design Issues
Petros Belachew
Topics Covered
2
Introduction: Design Goals
• There are several design goals considered whenever a new
language is to be designed.
•Utility - Is a feature often useful? Can it do important things
that cannot be done using other features of the language?
•Convenience - Does this feature help avoid excessive
writing? Does this feature add or eliminate clutter (code
untidiness) in the code?
•Efficiency - Is it easy or difficult to translate this feature? Is
it possible to translate this feature into efficient code? Will its
use improve or degrade the performance of programs?
•Portability - Will this feature be implementable on any
platform?
•Readability - Does this form of this feature make a program
more readable? Will a programmer other than the designer
understand the intent easily?
3
Introduction
• There are several design goals considered whenever a new
language is to be designed.
• Modeling ability - Does this feature help make the
meaning of a program clear? Will this feature help the
programmer model a problem more fully, more precisely, or
more easily?
• Simplicity - Is the language design as a whole simple,
unified, and general, or is it full of dozens of special-
purpose features?
• Semantic clarity - Does every legal program and
expression have one defined, unambiguous meaning? Is the
meaning constant during the course of program execution?
4
Programming Environment
• Is a collection of tools used in software
development
• Can be separate file system, text editor, linker, compiler
• UNIX is an older programming environment and
provides a variety of powerful tools where all of its tools
were accessed separately.
• Can also be a large collection of integrated tools, each
accessed through a uniform graphical user interface
(Visual Studio, NetBeans)
5
Source Source Source
code code code
Object files
Linker
Loader
Memory
6
Virtual Computers
• A virtual machine (VM) is a software implementation of a
machine (i.e. a computer) that executes programs like a
physical machine
• A virtual machine is less efficient than a real machine
because it accesses the hardware indirectly
• Virtual machines are separated into two major categories,
based on their use and degree of correspondence to any
real machine
• System virtual machine
• Multiple OS environments can co-exist on the same
computer, in strong isolation from each other
• Example: VMware workstation
7
Virtual Computers
• Process virtual machine
• A process VM, sometimes called an application virtual
machine
• runs as a normal application inside a host OS and
supports a single process.
• Example: Java Virtual Machine
• A process VM is created when that process is started and
destroyed when it exits
• Its purpose is to provide a platform-independent
programming environment
• abstracts away details of the underlying hardware
or operating system, and allows a program to
execute in the same way on any platform.
8
Binding Times
• A binding is an association between an attribute and an entity, such as
between a variable and its type or value, or between an operation and a
symbol.
• Binding time is the time at which a binding is created.
• Basically, binding times are of two types, Static and Dynamic (Early and Late)
• Static and Dynamic are very general terms to talk about binding times
• In general, early binding is associated with greater efficiency and late binding
is associated with greater flexibility
9
Binding Times - Terminology
• Tradeoff: In general,
11
Binding Times
• Compile time
• Compilers choose the mapping of high-level constructs to
machine code, including the layout of statically defined
data in memory.
• Link time
• Most compilers support separate compilation (compiling
different modules of a program at different times)
• The linker chooses the overall layout of the modules with
respect to one another.
• Inter-module references resolved here
• When a name in one module refers to an object in
another module, the binding between the two is
performed by the linker.
12
Binding Times
• Load time
• Load time refers to the point at which the operating system loads the
program into memory.
• A variable may be bound to a storage cell when the program is loaded into
memory
• Translate virtual memory addresses into physical memory addresses.
• Run time
• Most modern operating systems distinguish between virtual and physical
addresses.
• Virtual addresses are chosen at link time; physical addresses can actually
change at run time.
• The processor’s memory management hardware translates virtual addresses
into physical addresses during each individual instruction at run time.
13
Binding Times
Consider the following Java assignment statement:
count = count + 5;
•Some of the bindings and their binding times for the
parts of this assignment statement are as follows:
• The type of count is bound at compile time.
• The set of possible values of count is bound at compiler
design time (Implementation time)
• The meaning of the operator symbol + is bound at compile
time, when the types of its operands have been
determined.
• The internal representation of the literal 5 is bound at
compiler design time.
• The value of count is bound at execution time with this
14
statement.
15
Binding Times
• Meaning of +
• was defined (as numerical addition) when the language was
defined
• The specific addition operation (float, double, int, etc.),
however, cannot be determined until program translation time.
• Literal 23
• The meaning of literal 23 as the int value representing the
number 23 is fixed at language definition time.
• However, the actual representation (sequence of bits) for the
int value 23 can vary on different platforms, and it is not
bound until the language implementation (compiler design) is
performed.
16
Binding Times
17
Binding: Type Binding
Before a variable can be referenced in a program, it must be bound to
a data type
The two important aspects of this binding are how the type is specified
and when the binding takes place
Static type binding
Declaration is a static type binding
Explicit declaration
listing variable names and specifies that they are a
particular type
Example: int x,y; float radious;
Implicit declaration
Means of associating variables with types through default
conventions
done by the language processor, either a compiler or an
interpreter
18
Binding: Type Binding
Implicit declaration
Several different bases for implicit variable type bindings.
1. Naming Conventions: FORTRANIf the identifier begins with one
of the letters I, J, K, L, M, or N, or their lowercase versions, it is
implicitly declared to be Integer type; otherwise, it is implicitly
declared to be Real type.
Big damage to reliability because they prevent the
compilation process from detecting some typographical and
programmer errors
2. Type inference (Context)
type of the value assigned to the variable in a declaration
statement will be the type of the variable.
Example: in C# a var declaration of a variable must include
an initial value, whose type is made the type of the variable
24
Storage Bindings and Lifetime
Stack-Dynamic variables
Advantage: recursive subprograms require some form of
dynamic local storage so that each active copy of the recursive
subprogram has its own version of the local variables
Stack trace
25
Storage Bindings and Lifetime
Stack-Dynamic variables
Advantage: Subprograms share the same memory space for
their locals (Compare with Static variables)
Disadvantage:
Run-time allocation/deallocation overhead
Slower accesses because indirect addressing is required
Subprograms cannot be history sensitive (no static
variables)
26
Storage Bindings and Lifetime
Explicit Heap-Dynamic Variables
Abstract memory cells that are allocated and deallocated by
explicit run-time instructions written by the programmer.
Allocated from and deallocated to the heap
heap is a collection of storage cells whose organization is
highly disorganized due to the unpredictability of its use.
Can only be referenced through pointer or reference
variables
Created by either an
operator (as in C++)
The new keyword
call to a system subprogram provided for that purpose (as
in C).
The malloc subprogram
Type binding is static (Compile time)
27
Used to create dynamic structures, such as linked lists and
trees, that need to grow and/or shrink during execution
Storage Bindings and Lifetime
Explicit Heap-Dynamic Variables
Deallocating or destroying Explicit Heap-Dynamic Variables
Explicit: by using operators (Example C++)
Non-local
local
30
Scope
Static scope
the scope of a variable can be statically determined
—that is, prior to execution.
There are two categories of static-scoped languages
those in which subprograms can be nested, which
creates nested static scopes
those in which subprograms cannot be nested
static scopes are also created by subprograms but
nested scopes are created only by nested class
definitions and blocks
Information: Ada, JavaScript, Common LISP, Scheme,
Fortran 2003+, F#, and Python allow nested
subprograms, but the C-based languages do not.
31
Scope
Static scope
Consider languages that allow nested subprograms
big
sub1
var x = 7;
sub2();
sub2
var y = x;
var x = 3;
sub1();
33
Scope
Blocks
Many languages such as Java and C++ allow new static scopes to
be defined in the midst of executable code.
Allows a section of code to have its own local variables whose
scope is minimized
Such variables are typically stack dynamic, so their storage is
allocated when the section is entered and deallocated when the
section is exited
The C-based languages allow any compound statement to have
declarations and thereby define a new scope.
Such compound statements are called blocks. Consider the following
example and assume list was defined to be an array of integers:
35
Scope: Dynamic scope
Consider the two different call sequences
for sub2 in the example.
1. big calls sub1, which calls sub2. In this
case, the search proceeds from the
local procedure, sub2, to its caller,
sub1, where a declaration for x is
found.
So, the reference to x in sub2 in
this case is to the x declared in
sub1.
2. sub2 is called directly from big. In this
case, the dynamic parent of sub2 is
big, and the reference is to the x
declared in big.
Note that if static scoping were used, in either calling sequence
discussed, the reference to x in sub2 would be to big’s x.
36
Scope and Lifetime
Sometimes related
Consider a variable a declared within a method which have
no method calls.
In this case the lifetime and the scope of the variable
is the same.
Scope:- Spatial
Lifetime:- Temporal
37
Scope and Lifetime
Sometimes not related
Consider a variable declared in a function using the specifier
static in C++
Statically bound to the scope of that function
Statically bound to storage
So, its scope is static and local to the function
But its lifetime extends over the entire execution of
the program of which it is a part
Also unrelated when subprogram calls are involved
38
Scope and Lifetime
Sometimes not related
The scope of the variable sum is completely contained within
the compute function.
It does not extend to the body of the function printheader,
although printheader executes in the midst of the execution of
compute.
However, the lifetime of sum extends over the time during
which printheader executes.
Whatever storage location sum is bound to before the call to
printheader, that binding will continue during and after the
execution of printheader.
compute printheader
…
Variable sum is not visible
int sum;
… … in printheader function
Printheader()
39 ….
Referencing Environment
The referencing environment of a statement is the collection of
all variables that are visible in the statement
40
Named constants
are variables that are bound to values only once
are useful as aids to readability and program reliability.
Readability can be improved, for example, by using the name pi instead
of the constant 3.14159265.
Another important use of named constants is to parameterize a
program. Compare the following codes.
41
Named constants
Binding to values can also be dynamic:
Imperative 1 17 16 20
programming
Object-oriented 10 2 14
programming
Concurrent 15 9 3
programming
Functional 13 8 4 19
programming
Logic programming 7 5 18
Scripting paradigm 6 12 11
44
Group Assignment ( 10 %)
Evaluate the basic language constructs of the given
programming paradigms using the following
characteristics and criteria.
45
Instruction and marking for Individual
Assignment
You have to select at least two programming languages((except the languages
that are analyzed on the book)
Note that a specific programming language in that paradigm should have to be
analyzed by only one student . Example if mr X is working on C++ and Java, and
also mr Y is working on Java and C. Java programing language will not be
marked for both X and Y. So, discuss in your group while selecting
programming languages in order to minimize the conflict.
Check the paradigm that is assigned to you.
Each programing language has to be analyzed with the given constructs
Comparison of each programming language with the given metrics
Take time to read each of the concepts before start working the assignment
Marking
Each language analyses (3)x2=6
Comparison of the two=4
Make each of your analysis clear and free from ambiguity.
46
Instruction and marking for Group
Assignment
You have to select at least four programming languages(except the
languages that are analyzed on the book) one from each individual
member. (Use the PL that you have used for assignment 1)
Each programing language has to be analyzed with the given
constructs(from individual assignment) and roles specified.
Comparison of each programming language with the given metrics
Take time to read each of the concepts before start working the
assignment
Marking
Each language analyses =6
Comparison of the two=4
Make each of your analysis clear and free from ambiguity.
47
Individual assignment : two weeks(Dec 7,2022)
Group Assignment: Four weeks( Dec 23,2022)
48