Role of Programming Languages: Revathy D R
Role of Programming Languages: Revathy D R
MODULE 1
Programming Domains
1. Scientific Applications
The first digital computers, which appeared in the late 1940s and early 1950s, were
invented and used for scientific applications.
Typically, the scientific applications of that time used relatively simple data
structures, but required large numbers of floating-point arithmetic computations.
The most common data structures were arrays and matrices; the most common
control structures were counting loops and selections.
Fortran was the first language for scientific computing and is still used today.
2. Business Applications
3. Artificial Intelligence
4. Systems Programming
The operating system and the programming support tools of a computer system are
collectively known as its systems software.
Early languages: PL/S (IBM), BLISS (Digital), Extended ALGOL (Burroughs).
Most system software is now written in more general programming languages,
such as C and C++.
The UNIX operating system is written almost entirely in C.
5. Web Software
1. Readability
ii. 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 these primitives is valid and
meaningful.
▪ It makes the language simpler and easier to learn because there are
fewer exceptions to rules.
▪ In an orthogonal language, you can use the same instruction to add
two numbers, whether they are stored in memory or registers. In a
non-orthogonal language, you might need different instructions for
each case.
▪ VAX vs. IBM Assembly Language:
• VAX uses a single instruction (ADDL) to add two numbers,
regardless of whether they are in memory or registers.
• IBM requires two different instructions (A and AR) depending
on where the numbers are stored.
• VAX is more orthogonal and easier to use.
REVATHY D R
iii. Data Types
▪ The presence of adequate facilities for defining data types and data
structures is crucial for improving readability in a programming
language.
▪ For example, suppose a numeric type is used for an indicator flag
because there is no Boolean type in the language.
▪ Timeout=1
▪ The meaning of this statement is unclear, whereas in a language that
includes Boolean types, we would have the following:
▪ Timeout = true
▪ The meaning of this statement is perfectly clear.
iv. Syntax Design
▪ Special words: Languages like C use braces for statement groups,
which can be confusing. Ada and Fortran 95 improve readability
with distinct closing syntax (e.g., end if, end loop).
▪ Form and meaning: Syntax should indicate semantics. For example,
C's static keyword has different meanings based on context, adding
complexity.
2. Writability
Implementation Methods
1.Compilation
Compilation is the process of translating a high-level programming language (like C, Java,
etc.) into machine language (binary code) that the computer can directly execute.
🔹 How it works:
• The compiler reads the entire source code and translates it into machine code
(usually an executable file like .exe or .out).
• After compilation, the program can be run any number of times without the source
code.
REVATHY D R
✅ Advantages:
• Fast execution: Code runs directly on the hardware.
• Optimized code: Compilers can improve performance.
• Error detection: Many errors are caught before execution.
❌ Disadvantages:
• Slow compile time: May take time to compile large programs.
• Less flexibility: Hard to modify on-the-fly.
• Platform dependency: Binary code may only work on the target machine.
2. Pure Interpretation
In pure interpretation, the program is executed line by line using an interpreter. No
separate machine code is produced.
🔹 How it works:
• Source code → Interpreter → Execution
• Each instruction is analyzed and executed at runtime.
🔸 Examples:
• Early implementations of Python, Ruby, and LISP.
• BASIC in early computing days.
REVATHY D R
✅ Advantages:
• No compilation needed: Immediate execution.
• Easier debugging: Errors are reported with reference to source lines.
• Good for scripting and rapid development.
❌ Disadvantages:
• Slow performance: Each line is re-parsed and re-executed.
• Higher memory usage: Interpreter and source must be in memory.
• Not suitable for performance-critical applications.
🔹 How it works:
1. The source code is first compiled into an intermediate form (often called bytecode).
2. Then the bytecode is executed by a virtual machine (VM) or interpreter.
🔸 Examples:
• Java: Compiled to bytecode by javac, then executed by the Java Virtual Machine
(JVM).
• Python (modern): Source → Bytecode → Python Virtual Machine
REVATHY D R
✅ Advantages:
• Improved performance compared to pure interpretation.
• Platform independence: Bytecode can run on any machine with the appropriate VM.
• Good balance between speed and flexibility.
❌ Disadvantages:
• Still slower than fully compiled languages.
• Additional layer (the VM) is required.
REVATHY D R
Names & Variables
📊 Comparison Table
Feature Static Binding Dynamic Binding
int main() {
func(); // prints 1
func(); // prints 2 (value is retained)
return 0;
}
2. Stack-Dynamic Variables
• Definition: Storage is bound at runtime when the function is called. Deallocated
when the function exits.
• Lifetime: Duration of the function/method call.
• Use Case: Local variables inside functions without the static keyword.
✅ Advantages:
• Supports recursion.
• Memory is reused efficiently via the stack.
❌ Disadvantages:
• Slower access (indirect addressing).
• Cannot retain history across calls.
📌 Example (C++):
void demo() {
int x = 0; // Stack-dynamic variable
x++;
std::cout << x << std::endl;
}
Each call to demo() resets x to 0.
🔁 Summary Table
Bound Example
Type Lifetime Language
Time
Bound Example
Type Lifetime Language
Time
Explicit C++
Runtime Until manually
Heap- (new/delete)
(manual) deallocated
Dynamic
Implicit Python,
Runtime
Heap- Until garbage collected JavaScript
(auto)
Dynamic
procedure add
x := x + y
procedure first
y : integer := 6
second(add)
REVATHY D R
first()
write integer(x)
• Global Variables: x = 3, y = 4
• Procedure add modifies x by adding y.
• Procedure second(P) declares a local x = 5 and calls procedure P.
• Procedure first declares a local y = 6.