KEMBAR78
Principles of Programming Language - Chapter 1 | PDF | Computer Program | Programming
0% found this document useful (0 votes)
10 views31 pages

Principles of Programming Language - Chapter 1

Deduced from concepts of programming language book by Robert Sebesta

Uploaded by

likhi4951
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views31 pages

Principles of Programming Language - Chapter 1

Deduced from concepts of programming language book by Robert Sebesta

Uploaded by

likhi4951
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Chapter 1

1.1 Reasons for Studying Concepts of


Programming Languages
Why Study Programming Languages?
Many students wonder why they should learn about different programming
languages.

There are already so many topics in computer science, and not enough
time in a college course to learn them all.

But understanding programming language concepts gives you many


benefits:

1. Increases How Well You Can Express Ideas


Just like language affects how deeply we think, programming languages
affect how deeply we can design and write software.

If a programmer only knows limited ways to express logic, they’ll be stuck


with limited ideas and solutions.

Learning new language features helps you:

Think more broadly

Solve problems more creatively

Design better algorithms

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.

2. Helps You Choose the Right Language for the Job


Many programmers use the language they're most comfortable with, even if
it's not the best one for the project.

This usually happens because:

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.

3. Makes It Easier to Learn New Languages


Programming languages keep evolving, and you’ll need to keep learning
new ones during your career.

If you understand the basic concepts of how languages work (like


variables, control flow, data types, etc.), learning new ones becomes much
easier.

Example: If you know about Object-Oriented Programming (OOP), picking


up a new OOP language like Ruby is easier.

Just like knowing grammar helps with learning a new spoken language,
knowing programming concepts helps with learning new coding languages.

4. Helps You Understand Programming Language Trends


Languages go in and out of popularity.

In 2017, Java, C, C++, and C# were among the most used, but there were
dozens of others also widely used.

As a programmer, you should be ready to learn new languages based on


current needs.

5. Teaches You to Read and Compare Languages


Programmers often read language documentation, comparisons, or
promotional material for tools and compilers.

To understand these documents, you need to know basic programming


language concepts and vocabulary.

6. Gives You Insight Into Language Implementation

Chapter 1 2
Understanding how a language works internally helps you use it better.

You’ll learn:

Why certain features exist

Why some things are slow or buggy

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.

Example: If you know that calling a small function repeatedly is inefficient,


you might avoid it in performance-heavy code.

7. Helps You Use Languages You Already Know More


Effectively
Most modern languages have many features that most programmers don’t
use or even know about.

Studying language design helps you discover these features, making you
more efficient.

8. Contributes to the Progress of Computing


Just because a language is popular doesn't mean it's the best.

Some powerful languages were ignored simply because developers didn’t


understand their benefits.

Example: ALGOL 60 was elegant and powerful, but it didn’t become as


popular as Fortran because:

Programmers found it hard to read

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.

1.2 Programming Domains


What Are Programming Domains?

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.

1.2.1 Scientific Applications


The first computers (late 1940s–1950s) were built mainly for scientific and
engineering tasks.

These tasks usually needed:

Simple data structures like arrays or matrices

Lots of mathematical calculations — especially floating-point


arithmetic

To support this, early languages for science focused on speed and


efficiency.

Key Language: FORTRAN


FORTRAN (short for "Formula Translation") was the first high-level
programming language for scientific applications.

Later languages like ALGOL 60 were also used in science, but FORTRAN
remained dominant.

Even today, FORTRAN is still used in some science fields where


performance is critical.

1.2.2 Business Applications


In the 1950s, businesses began using computers for:

Payroll

Billing

Report generation

Accounting

Chapter 1 4
These tasks needed features like:

Accurate decimal number handling

Character data storage

Fancy report formatting

Key Language: COBOL


COBOL (Common Business-Oriented Language) was the first major
business programming language.

Released in 1960, COBOL is still widely used in banks, insurance, and


government systems.

It is especially good at generating detailed reports and handling financial


data.

1.2.3 Artificial Intelligence (AI)


AI is a field that uses symbols and names (not just numbers) to represent
data.

AI programs need to manipulate symbolic information — things like rules,


logic, and relationships.

Because of this, AI prefers languages that support:

Symbolic computation (working with names and structures, not just


numbers)

Flexible data structures (like linked lists)

Key Languages: Lisp and Prolog


Lisp (1959): One of the first and most important AI languages.

Based on functions and lists

Used widely for AI research in the 1960s–80s

Prolog (1970s): A logic programming language used for rule-based AI


systems.

Modern AI sometimes uses languages like Python, because it is flexible


and easy to read.

Chapter 1 5
1.2.4 Web Software
The World Wide Web introduced a new type of programming need —
interactive websites and online applications.

This brought together:

Markup languages (to structure content)

Scripting languages (to add interactivity)

General-purpose languages (for backend processing)

Common Web Technologies


HTML: A markup language for web page structure (not a programming
language).

JavaScript: Adds interactivity to web pages (e.g., popups, animations, form


validation).

PHP: A server-side scripting language used to create dynamic web content.

Java: Often used in large web applications or Android development.

Other hybrid languages mix content and logic together.

1.3 Language Evaluation Criteria


Why Do We Need Evaluation Criteria?
To judge how good or bad a programming language is, we need a set of
evaluation standards.

These standards help us compare languages and understand their


strengths and weaknesses.

However, not everyone agrees on which features are most important.

Still, there are a few widely accepted criteria that are used to evaluate most
programming languages.

✅ Main Evaluation Criteria:


Chapter 1 6
1. Readability – How easy it is to read and understand code written in the
language.

2. Writability – How easy it is to write code in the language.

3. Reliability – How well the language performs under different conditions


without bugs or crashes.

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.

In the past, code was written mainly to be understood by computers. Now,


it’s written mostly for humans, especially for maintenance.

Readable code is critical for:

Debugging

Team collaboration

Making future updates

✅ What Affects Readability?


1. Overall Simplicity
Fewer, more consistent features = easier to read.

Too many options can be confusing — especially if people use different


features in different ways.

Example: In Java, you can write count++ , ++count , count += 1 , or count = count + 1

— they all do the same thing but can confuse beginners.

2. Orthogonality (simple but powerful combinations)

Chapter 1 7
A language is orthogonal if a small number of features can be combined in
consistent ways to do many things.

Good orthogonality = fewer special rules and exceptions, making the


language easier to learn and read.

Example:

In a good orthogonal language, any data type can be used anywhere


(like in arrays, pointers, etc.), unless there's a clear reason not to.

Bad orthogonality = more restrictions and exceptions, which makes things


harder to predict.

3. Data Types
Clear and proper data types help readability.

Example:

flag = true is more understandable than flag = 1 , because it shows clear


intent.

Languages with Boolean types are easier to read in this way.

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).

Reusing keywords for multiple meanings can be confusing.

Example: In C, static means different things depending on where you


use it.

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.).

✅ What Affects Writability?


1. Simplicity and Orthogonality
Just like readability, writability improves when the language has fewer,
simpler, and consistent rules.

Too many features or rules = more confusion and more mistakes.

2. Expressivity
A language is expressive if it lets you write more using less code.

Examples:

count++ is shorter than count = count + 1

for loops in Java are shorter and easier than writing a full while loop

In Ada, and then supports short-circuit evaluation (efficient boolean


logic)

1.3.3 Reliability

What Is Reliability?
A program is reliable if it behaves correctly under all conditions.

A reliable language helps programmers write correct code and catch


mistakes early.

✅ What Affects Reliability?


1. Type Checking
Type checking = checking that variables and expressions are used with the
correct data types.

Chapter 1 9
Best done during compile time (before the program runs) to avoid run-time
errors.

Example: Java checks almost everything during compilation — this avoids


many bugs.

In early C, you could accidentally pass an int to a function expecting a float ,


causing weird behavior.

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.

Languages without it (like C) are more error-prone.

3. Aliasing
Aliasing means having two different names that refer to the same
memory.

Example: Two pointers pointing to the same variable.

This can cause confusion and bugs if one name changes the value without
the other name knowing.

Good languages limit or control aliasing to improve reliability.

4. Readability and Writability


The easier it is to read and write code, the less likely it is to contain bugs.

Bad code is hard to fix and easy to break — leading to reliability issues.

1.3.4 Cost

What Is the “Cost” of a Programming Language?


Cost doesn’t just mean money — it includes time, effort, and resources.

✅ 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.

A good language and a good programming environment (like an IDE) can


reduce this.

3. Execution Cost
How fast or slow the program runs after it’s written.

Some languages are faster than others.

Java is slower than C because it checks more things during execution.

4. Cost of Poor Reliability


If your code fails in real life (like in medical or banking software), the results
can be very expensive — even deadly.

5. Maintenance Cost
Most of a program’s life is spent being maintained (fixed, updated,
modified).

Readable code makes maintenance easier and cheaper — especially if the


person doing it is not the original author.

Other Criteria to Consider


Portability: How easily the code can run on different machines and
systems.

Generality: How well the language works across different domains (e.g.,
web, AI, business).

Well-definedness: How clear and complete the official documentation is.

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.

Language Designers aim to make the language elegant, efficient, and


widely usable.

1.4 Influences on Language Design


What Affects the Way Programming Languages Are
Designed?
The design of a programming language is influenced by many factors.

Two of the most important ones are:

1. Computer Architecture – How computers are built

2. Programming Design Methodologies – How people organize and write


software

1.4.1 Computer Architecture

What Is Computer Architecture?


Computer architecture refers to how a computer’s hardware is organized
and how it works.

The most common type is called the von Neumann architecture (named
after John von Neumann).

Von Neumann Architecture: Key Features


Programs and data are both stored in the same memory.

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.

How This Affects Programming Languages

Chapter 1 12
Since this is how real computers work, early programming languages were
designed to match this structure.

These languages are called imperative languages.

Features that match the von Neumann model include:

Variables – to represent memory cells

Assignment statements – to move data

Loops (iteration) – the most efficient way to repeat steps in memory

Why Recursion Is Less Used in This Model


Iteration (like for and while loops) is faster and easier to implement on von
Neumann machines.

Recursion (when a function calls itself) is sometimes more natural but uses
more memory and is slower here.

The Fetch-Execute Cycle (How Instructions Run)


This is how the CPU runs programs stored in memory:

1. Start with the first instruction (pointed to by the Program Counter).

2. Fetch the instruction from memory.

3. Decode the instruction (figure out what it means).

4. Execute the instruction.

5. Repeat for the next instruction.

Why Functional Languages Are Not a Natural Fit


Functional languages (like Lisp or Scheme) don’t use variables or
assignments the same way.

They don’t match the von Neumann model closely, which makes them less
efficient on most real computers.

Unless we build non–von Neumann machines, imperative languages will


likely remain more common.

Chapter 1 13
1.4.2 Programming Design Methodologies

What Are Design Methodologies?


These are structured ways to plan, organize, and write software programs.

Over time, programming became more complex and needed better methods
to manage big projects.

Structured Programming (1960s–70s)


Before this, many programs used goto statements, which made them
messy and hard to follow.

Structured programming introduced cleaner concepts like:

Loops instead of goto

If-else structures

Clear function breakdowns

This shift influenced languages to provide better control structures and


type checking.

Top-Down Design and Stepwise Refinement


Large problems are broken into smaller parts (top-down).

Each part is refined step by step until full code is written.

Languages began to support these concepts with better syntax and


structure.

Data-Oriented Programming (Late 1970s)


Focus shifted from just procedures to data design.

The idea of Abstract Data Types (ADTs) became important.

Abstract Data Types (ADTs)


ADTs allow you to group data and the operations on it into one structure.

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.

Object-Oriented Programming (1980s Onward)


Built on top of ADTs by adding two key ideas:

1. Inheritance – Reuse code from existing classes

2. Dynamic Method Binding – Decide which function to call at run time

OOP made it easier to:

Organize large programs

Reuse code

Build scalable software

Languages That Support OOP


Smalltalk: One of the first full OOP languages.

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.

Concurrency and New Research Areas


In recent years, concurrency (running multiple parts of a program at the
same time) became more important.

Languages like Java and C# added built-in support for concurrency.

These research developments influence how new languages are designed


today.

Summary of This Section


Programming languages are shaped by:

The machines we run them on

The ways we design software

As both evolve, so do the languages we use.

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.

1.5.1 Imperative Languages

What Are Imperative Languages?


The imperative programming model is based on the von Neumann
architecture, which is the basic design of most computers.

In this model, a program is made up of instructions that change the values


stored in memory.

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:

Assigning values to variables

Using loops ( for , while )

Calling functions or procedures

Examples of Imperative Languages


FORTRAN, ALGOL, C, Ada, and Java are all examples of imperative
languages.

Even though languages like Java and Ada support object-oriented


programming, they are still fundamentally imperative because they use the
same basic structure of step-by-step instructions.

Chapter 1 16
1.5.2 Functional Languages

What Are Functional Languages?


Functional programming is based on mathematical functions, which are
similar to functions in algebra.

In these languages, the main way to build programs is by combining


functions rather than using variables or changing values in memory.

Key Characteristics
In functional programming:

Functions are treated as first-class citizens, meaning they can be


stored in variables, passed as arguments, and returned from other
functions.

There is no need for assignment — instead of changing values, new


values are calculated and returned.

Programs avoid side effects (unexpected changes in variables or


state).

Examples of Functional Languages


Lisp was one of the first functional languages.

Others include:

Scheme

ML

Haskell

F#

1.5.3 Logic Programming Languages

What Are Logic Programming Languages?


Logic programming is based on formal logic, specifically predicate logic.

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:

Facts ( Socrates is a man )

Rules ( All men are mortal )

Questions ( Is Socrates mortal? )

The language uses these facts and rules to answer queries automatically,
using a process called resolution.

Example of a Logic Language


Prolog (short for Programming in Logic) is the most well-known logic
programming language.

1.5.4 Markup/Programming Hybrid Languages

What Are Markup/Programming Hybrids?


These are languages that combine markup (used for formatting content)
with programming features.

They are commonly used in web development where you need both:

Content formatting (text, layout)

Dynamic behavior (interactivity, logic)

Key Characteristics
These languages were created to allow programmers to write code inside
documents or web pages.

They usually contain:

Markup language parts (like HTML or XML)

Scripting parts (like JavaScript or PHP)

Chapter 1 18
Examples
JavaScript – A client-side scripting language often embedded within HTML
pages.

PHP – A server-side scripting language that’s also mixed with HTML.

ASP.NET – A Microsoft technology used to write dynamic websites.

These languages are not purely programming languages but are hybrids
because they handle both display and logic.

1.6 Language Implementation Methods


What Does "Implementation" Mean in Programming
Languages?
After a programming language is designed, we need to build software tools
so that people can actually use the language.

These tools are usually either a compiler or an interpreter.

There are three main ways a programming language can be implemented:

1. Compilation

2. Pure Interpretation

3. Hybrid Implementation (a mix of both)

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).

How Compilation Works (Step-by-Step)


1. The compiler takes the source program (written in a high-level language).

Chapter 1 19
2. It analyzes it in multiple steps (called phases).

3. It translates it into a machine language program.

4. The machine program is saved as a separate file and can be run later.

What Happens When You Run the Program?


Once compiled, you don’t need the compiler anymore.

The CPU (processor) runs the compiled machine code directly.

Advantages of Compilation
Programs run very fast, because they’re already in machine code.

No need to translate code again during execution.

Disadvantages
You can’t run the program until the entire code is compiled — this takes
time.

If you make a small change, you need to recompile before testing.

Compilation errors can be hard to understand, especially for beginners.

Examples of Compiled Languages


C, C++, Fortran, Ada — all use compilation as their main method.

1.6.2 Pure Interpretation

What Is Pure Interpretation?


In pure interpretation, the program is not translated into machine code
ahead of time.

Instead, an interpreter runs the program line by line or statement by


statement.

How Interpretation Works


1. You write your program in a high-level language.

Chapter 1 20
2. The interpreter reads the code one part at a time.

3. It analyzes and executes each part immediately, without creating a


separate machine code file.

Advantages of Interpretation
You don’t need to wait for compilation — you can run the code right away.

Great for testing small pieces of code quickly.

Easier to use in educational settings or for beginners.

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.

Examples of Interpreted Languages


Scheme, SNOBOL, and early versions of BASIC are purely interpreted.

Also, Python is often interpreted, although it may be compiled behind the


scenes too.

1.6.3 Hybrid Implementation Systems

What Is a Hybrid Implementation?


Hybrid systems combine compilation and interpretation.

They first translate the source code into an intermediate form (not full
machine code), and then interpret that form.

What Is Intermediate Code?


It is a code that’s easier for the machine to understand than high-level
language, but still not full machine language.

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.

2. This intermediate code is run using an interpreter or virtual machine.

Why Use Hybrid Systems?


This method balances speed and flexibility.

You get faster execution than pure interpretation and more flexibility than
full compilation.

Examples of Hybrid Languages


Java: Compiled into bytecode, then run by the Java Virtual Machine
(JVM).

C#: Compiled into Common Intermediate Language (CIL), then run by the
.NET CLR (Common Language Runtime).

1.7 Programming Language


Environments
What Is a Programming Environment?
A programming environment is the complete setup you use to write, test,
and run programs in a particular language.

It usually includes:

The compiler or interpreter

Editor to write code

Debugger to find and fix errors

Tools for compiling, executing, and sometimes visualizing code

Why Are Environments Important?


A programming language by itself is just a set of rules and syntax.

Chapter 1 22
The environment provides the actual software and tools to use that
language effectively.

Without a good environment, even a well-designed language is hard to use.

Types of Language Environments

1. Batch Environments

What Is a Batch Environment?


In a batch system, you write your program in a text file and submit it to the
compiler or interpreter as a single job.

The program is compiled and run all at once — you get your output at the
end.

What It Looks Like


You don't interact with the program while it runs.

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.

Still used today in situations where:

Programs are large

Inputs and outputs are known ahead of time

User interaction is not needed

2. Interactive Environments

What Is an Interactive Environment?


In this setup, you write and run code one part at a time — often in a
command line or terminal window.

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.

Many modern languages include interactive shells or REPLs

(Read–Eval–Print Loop: type a command → get a result → repeat).

3. Integrated Development Environments (IDEs)

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

Compiler/interpreter – to translate code

Debugger – to find and fix problems

Project management tools

Often includes syntax highlighting, auto-completion, and error messages


while you type

Examples of IDEs
Eclipse – Java, C++, and others

Visual Studio – C#, C++, and many other languages

PyCharm – Python

NetBeans – Java

Dev-C++ – C/C++

Xcode – Apple’s IDE for Swift and Objective-C

Chapter 1 24
Why IDEs Are Popular
Everything is in one place — no need to switch between tools.

Makes development faster, easier, and more organized.

1.8 Programming Language Syntax and


Semantics
What Do "Syntax" and "Semantics" Mean in Programming?
Just like in spoken or written languages, programming languages have
rules for structure (syntax) and meaning (semantics).

To understand a programming language well, you need to understand both.

1.8.1 Syntax

What Is Syntax?
Syntax refers to the form or structure of programs written in a language.

It tells you how to write statements correctly — like punctuation, order of


words, brackets, etc.

If the syntax is wrong, the program will not compile or run.

Parts of Syntax Rules


There are two levels of syntax:

1. Lexical Structure (Low-Level Syntax)


Deals with basic elements of a program, such as:

Keywords ( if , while , int , etc.)

Identifiers (names for variables, functions)

Operators ( + , , == )

Punctuation ( ; , , , { , } )

Chapter 1 25
This level is handled by the lexical analyzer (a part of the compiler).

2. Grammar Structure (High-Level Syntax)


Describes how tokens are combined into valid statements and program
structures.

Uses formal grammar rules (like BNF – Backus-Naur Form or similar


notations) to define:

How to write loops, conditionals, function calls, etc.

Example:

if (x > y) {
max = x;
}

– This is syntactically correct in C-like languages.

1.8.2 Semantics

What Is Semantics?
Semantics refers to the meaning of the syntax — what the code does
when it runs.

Even if a program is syntactically correct, it might not make sense


semantically.

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.

It explains how the computer executes each statement step by step.

Example:

Chapter 1 26
In operational semantics, the meaning of:

x = x + 1;

is explained by saying:

First, get the value of x

Add 1 to it

Store the result back into x

It's like acting out the instructions.

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:

If x was 4 before, then after the statement, x must be 5.

It uses logical statements to prove correctness.

3. Denotational Semantics
This method maps each part of a program to a mathematical object
(usually a function).

It focuses on the meaning of code in terms of pure mathematics.

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.

Which Semantic Method Is Used Where?

Chapter 1 27
Operational semantics is used when building or explaining how an
interpreter or virtual machine works.

Axiomatic semantics is useful in formal verification — to prove that a


program does what it's supposed to do.

Denotational semantics is more theoretical and used in language design


and mathematics of computation.

Why Semantics Matter


Understanding semantics helps:

Avoid bugs in logic

Know what your code actually does

Design better programming languages

1.9 Language Design Trade-Offs


What Are Design Trade-Offs?
When designing a programming language, not all goals can be achieved at
once.

Sometimes, making one feature better means sacrificing another.

These are called design trade-offs — choices between two or more


competing goals.

Why Are Trade-Offs Important?


Language designers must carefully balance things like:

Performance vs. Ease of use

Safety vs. Flexibility

Expressiveness vs. Simplicity

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

1. Readability vs. Writability


Some language features that make code easy to write can also make it
harder to read.

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.

2. Flexibility vs. Safety


Giving the programmer more power (like low-level access to memory) can
reduce the safety of the language.

Example:

In C, pointers give you direct control over memory, which is powerful.

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.

3. Execution Speed vs. Error Checking


Some safety features check for errors at runtime, which slows the program
down.

Example:

Array index checking ensures you don’t go beyond array bounds.

But checking every index at runtime uses extra CPU time.

Languages like C skip these checks to be faster, while languages like Java
include them to be safer.

4. Expressiveness vs. Simplicity

Chapter 1 29
A language can be expressive by offering many powerful features and
shortcuts.

This means you can do more with fewer lines of code.

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.

5. Compilation Speed vs. Run-Time Performance


Some language designs allow faster compilation but result in slower
runtime performance.

Others take longer to compile but produce very fast executable code.

Designers must choose where to place the emphasis:

Fast compile time is better for rapid development.

Fast execution is better for high-performance tasks.

6. Portability vs. Low-Level Control


Languages like C allow low-level operations, such as pointer arithmetic and
hardware control.

These are powerful but make the code dependent on specific


machines or operating systems.

Portable languages like Java aim to run the same way everywhere — but
they hide or restrict access to system-level features.

7. Powerful Features vs. Security


Advanced features (like reflection or dynamic code execution) can create
security risks if not handled properly.

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.

There is no perfect language — each one makes different compromises


depending on its goals and target users.

Understanding these trade-offs helps you:

Appreciate why languages are the way they are

Choose the right language for each task

Avoid design mistakes in your own programs or tools

Chapter 1 31

You might also like