Principles of Programming Language - Chapter 1
Principles of Programming Language - Chapter 1
There are already so many topics in computer science, and not enough
time in a college course to learn them all.
Even if your current language doesn't support a certain feature, you can
often simulate it based on what you've learned from other languages.
Chapter 1 1
They only learned one or two languages during training or work.
They were trained long ago and haven’t learned newer languages.
If you're familiar with more languages and their features, you can choose
the one that fits your project best.
While some features can be "faked" in other languages, it's usually better to
use a language where those features are built-in.
Just like knowing grammar helps with learning a new spoken language,
knowing programming concepts helps with learning new coding languages.
In 2017, Java, C, C++, and C# were among the most used, but there were
dozens of others also widely used.
Chapter 1 2
Understanding how a language works internally helps you use it better.
You’ll learn:
How to write better code using what the language is designed for
Knowing how the language is implemented can even help you find and fix
bugs that others might miss.
Studying language design helps you discover these features, making you
more efficient.
They didn’t understand its benefits, like block structure and recursion
If more developers had known about language design, better choices might
have been made.
Chapter 1 3
A domain is a specific area where a programming language is used.
Since computers are used in many different fields, we also have different
programming languages for different purposes.
Each domain has its own needs and priorities — so languages are designed
to match those needs.
Later languages like ALGOL 60 were also used in science, but FORTRAN
remained dominant.
Payroll
Billing
Report generation
Accounting
Chapter 1 4
These tasks needed features like:
Chapter 1 5
1.2.4 Web Software
The World Wide Web introduced a new type of programming need —
interactive websites and online applications.
Still, there are a few widely accepted criteria that are used to evaluate most
programming languages.
4. Cost – The total cost (time, money, effort) of using the language in real-
world projects.
1.3.1 Readability
What Is Readability?
Readability means how easily a programmer (including someone other than
the original writer) can understand code.
Debugging
Team collaboration
Example: In Java, you can write count++ , ++count , count += 1 , or count = count + 1
Chapter 1 7
A language is orthogonal if a small number of features can be combined in
consistent ways to do many things.
Example:
3. Data Types
Clear and proper data types help readability.
Example:
4. Syntax Design
Syntax is the form or structure of the code.
Good syntax makes the meaning of code clear just by looking at it.
Important factors:
Special words: Reserved words like while , end if , loop , etc. help group
and separate code blocks.
Languages like Ada use end if , end loop — which are clearer than just
} (used in C-like languages).
1.3.2 Writability
Chapter 1 8
What Is Writability?
Writability means how easy it is to write code — especially for solving real
problems in a specific domain (like business, science, etc.).
2. Expressivity
A language is expressive if it lets you write more using less code.
Examples:
for loops in Java are shorter and easier than writing a full while loop
1.3.3 Reliability
What Is Reliability?
A program is reliable if it behaves correctly under all conditions.
Chapter 1 9
Best done during compile time (before the program runs) to avoid run-time
errors.
2. Exception Handling
Exception handling = dealing with run-time errors (like dividing by zero,
invalid input, etc.) safely.
Languages like Java, C++, Ada, and C# have built-in support for catching
and fixing errors during execution.
3. Aliasing
Aliasing means having two different names that refer to the same
memory.
This can cause confusion and bugs if one name changes the value without
the other name knowing.
Bad code is hard to fix and easy to break — leading to reliability issues.
1.3.4 Cost
✅ Types of Cost
Chapter 1 10
1. Training Cost
How long it takes to learn the language.
Simpler languages with clean designs are easier and cheaper to teach.
2. Development Cost
How long it takes to write a program using the language.
3. Execution Cost
How fast or slow the program runs after it’s written.
5. Maintenance Cost
Most of a program’s life is spent being maintained (fixed, updated,
modified).
Generality: How well the language works across different domains (e.g.,
web, AI, business).
Chapter 1 11
Different Perspectives Matter
Language Implementers care about how hard it is to build the language.
Language Users care more about how easy it is to write and read code.
The most common type is called the von Neumann architecture (named
after John von Neumann).
There is a CPU (Central Processing Unit) that does the work of executing
instructions.
Instructions and data have to be moved between the memory and the CPU.
Chapter 1 12
Since this is how real computers work, early programming languages were
designed to match this structure.
Recursion (when a function calls itself) is sometimes more natural but uses
more memory and is slower here.
They don’t match the von Neumann model closely, which makes them less
efficient on most real computers.
Chapter 1 13
1.4.2 Programming Design Methodologies
Over time, programming became more complex and needed better methods
to manage big projects.
If-else structures
SIMULA 67 was the first language to support this idea, though it wasn’t
widely used at the time.
Chapter 1 14
ADTs later became a foundation for Object-Oriented Programming.
Reuse code
C++, Java, and C#: Popular imperative languages that added support for
OOP.
Even functional languages like F# and logic languages like Prolog++ added
OOP features later.
Chapter 1 15
1.5 Language Categories
Different Types of Programming Languages
Over the years, many programming languages have been created.
Although each one is unique in its own way, most languages fall into one of
several main categories based on their core design and purpose.
Key Characteristics
Programs in this category are written as a series of steps or commands
(just like giving instructions to a computer).
These steps update the program’s state (the values in memory) using
operations like:
Chapter 1 16
1.5.2 Functional Languages
Key Characteristics
In functional programming:
Others include:
Scheme
ML
Haskell
F#
Chapter 1 17
In this approach, you don’t give step-by-step instructions — instead, you
write rules and facts, and the computer figures out how to apply them to
reach a goal.
Key Characteristics
A program is made up of logical statements like:
The language uses these facts and rules to answer queries automatically,
using a process called resolution.
They are commonly used in web development where you need both:
Key Characteristics
These languages were created to allow programmers to write code inside
documents or web pages.
Chapter 1 18
Examples
JavaScript – A client-side scripting language often embedded within HTML
pages.
These languages are not purely programming languages but are hybrids
because they handle both display and logic.
1. Compilation
2. Pure Interpretation
1.6.1 Compilation
What Is Compilation?
In compilation, the entire program is translated into machine code before it
is run.
A program called a compiler reads the source code (your code) and
creates a machine code file (often called an executable or binary).
Chapter 1 19
2. It analyzes it in multiple steps (called phases).
4. The machine program is saved as a separate file and can be run later.
Advantages of Compilation
Programs run very fast, because they’re already in machine code.
Disadvantages
You can’t run the program until the entire code is compiled — this takes
time.
Chapter 1 20
2. The interpreter reads the code one part at a time.
Advantages of Interpretation
You don’t need to wait for compilation — you can run the code right away.
Disadvantages
Programs run much slower than compiled code, because each line is being
analyzed while the program is running.
Interpreter must stay loaded the whole time, using more memory.
They first translate the source code into an intermediate form (not full
machine code), and then interpret that form.
This code is often stored in virtual machine format, which is then run by a
virtual machine (VM).
Chapter 1 21
How Hybrid Implementation Works
1. The source code is compiled into intermediate code.
You get faster execution than pure interpretation and more flexibility than
full compilation.
C#: Compiled into Common Intermediate Language (CIL), then run by the
.NET CLR (Common Language Runtime).
It usually includes:
Chapter 1 22
The environment provides the actual software and tools to use that
language effectively.
1. Batch Environments
The program is compiled and run all at once — you get your output at the
end.
You may have to wait a long time to find out if it worked or failed.
Used In
Early systems and older programming languages like FORTRAN.
2. Interactive Environments
You can see the result immediately and change things as you go.
Chapter 1 23
Key Features
You can test and debug your code quickly.
It’s good for learning, trying things out, and writing short programs.
Used In
Python, Lisp, Scheme, MATLAB, and early versions of BASIC.
What Is an IDE?
An IDE (Integrated Development Environment) combines all programming
tools in one single software.
Features of an IDE
Editor – to write code
Examples of IDEs
Eclipse – Java, C++, and others
PyCharm – Python
NetBeans – Java
Dev-C++ – C/C++
Chapter 1 24
Why IDEs Are Popular
Everything is in one place — no need to switch between tools.
1.8.1 Syntax
What Is Syntax?
Syntax refers to the form or structure of programs written in a language.
Operators ( + , , == )
Punctuation ( ; , , , { , } )
Chapter 1 25
This level is handled by the lexical analyzer (a part of the compiler).
Example:
if (x > y) {
max = x;
}
1.8.2 Semantics
What Is Semantics?
Semantics refers to the meaning of the syntax — what the code does
when it runs.
Types of Semantics
There are three types of semantic definitions:
1. Operational Semantics
Describes the meaning of code by describing how it runs on a machine.
Example:
Chapter 1 26
In operational semantics, the meaning of:
x = x + 1;
is explained by saying:
Add 1 to it
2. Axiomatic Semantics
Describes program meaning using mathematical logic and proof rules.
Focuses on what must be true before and after a piece of code runs.
Example:
If a program says x = x + 1; , we can express that:
3. Denotational Semantics
This method maps each part of a program to a mathematical object
(usually a function).
How It Works:
Every construct (like a loop or assignment) is assigned a function that
represents its effect.
You can build the meaning of a full program by combining these functions.
Chapter 1 27
Operational semantics is used when building or explaining how an
interpreter or virtual machine works.
If they focus too much on one aspect, the language may become harder to
use or less efficient in other ways.
Chapter 1 28
Common Language Design Trade-Offs
Example:
Operator overloading in C++ lets you define new meanings for symbols
like + or .
This can make the code shorter to write, but confusing to read,
especially if the operators don’t behave as expected.
Example:
But this also means it’s easy to make mistakes like accessing invalid
memory or causing crashes.
Safer languages like Java restrict such features to prevent errors, but at the
cost of some flexibility.
Example:
Languages like C skip these checks to be faster, while languages like Java
include them to be safer.
Chapter 1 29
A language can be expressive by offering many powerful features and
shortcuts.
But more features can make the language more complex to learn and
understand.
Example:
A highly expressive language like Perl lets you write very compact
code.
But such code may be hard to read, especially for beginners or team
projects.
Others take longer to compile but produce very fast executable code.
Portable languages like Java aim to run the same way everywhere — but
they hide or restrict access to system-level features.
Chapter 1 30
More power often means more responsibility — and more chances for
abuse or errors.
Conclusion
Every programming language is the result of many trade-offs.
Chapter 1 31