> "If we wish to count lines of code, we should not regard them as 'lines produced' but as 'lines spent.'"
Learning Objectives
- Explain why Pascal was created and what problems Niklaus Wirth was trying to solve
- Identify at least three advantages of learning programming with Pascal vs other languages
- Describe the modern Pascal ecosystem (Free Pascal, Lazarus, Delphi)
- Compare Pascal's approach to programming with Python, C, and Java
- Articulate why strong typing and structured programming are features, not limitations
In This Chapter
Chapter 1: Why Pascal? The Language Designed to Teach Programming Right
"If we wish to count lines of code, we should not regard them as 'lines produced' but as 'lines spent.'" — Niklaus Wirth
1.1 The Problem with Learning to Program
Something is broken in the way we teach programming.
Every year, millions of students around the world enroll in introductory computer science courses. They arrive eager, curious, ready to learn the skill that powers the modern world. And every year, a staggering number of them fail. Drop rates in CS1 courses hover between 30 and 50 percent at many institutions. Of those who survive, a troubling proportion emerge with what we might call "copy-paste fluency" — they can make code run, but they cannot explain why it runs. They can follow a tutorial, but they cannot solve a novel problem. They have learned a language without learning to think.
This is not the students' fault. It is, in large part, the fault of the tools we hand them.
Consider the landscape of introductory programming languages in the 2020s. Python dominates, used by over 80 percent of US universities in their introductory courses. Its appeal is obvious: minimal syntax, a gentle on-ramp, a vast ecosystem of libraries. You can write a working program in a single line. You can build a web scraper in fifteen minutes. You can import TensorFlow and feel like you are doing machine learning before you understand what a loop does.
And that, precisely, is the problem.
Python's permissiveness — its dynamic typing, its implicit conversions, its "we're all adults here" philosophy — means that students can produce programs that work without ever understanding the foundations those programs rest on. A student can concatenate strings and integers without understanding type systems. They can use list comprehensions without understanding iteration. They can call library functions without understanding what a function is. The language does not force them to confront these concepts because the language was designed for rapid prototyping by experienced programmers, not for teaching beginners to think rigorously.
C, at the other extreme, confronts students with everything at once. Pointers, manual memory management, undefined behavior, segmentation faults — all in the first few weeks. Students learn fear before they learn fundamentals. The language was designed for systems programmers who already understood computation; it expects that understanding rather than building it.
Java imposes an enormous amount of ceremony — public static void main(String[] args) — before a student can write "Hello, World." The object-oriented paradigm is powerful, but it is not where beginners should start. You do not teach someone to drive by explaining the internal combustion engine.
JavaScript is a language born of compromise, full of quirks that even its creator acknowledges as mistakes. Brendan Eich famously built the first version in ten days. Teaching programming with JavaScript is like teaching music theory on an instrument that is occasionally out of tune in ways no one can predict.
The consequences of these mismatches between teaching goals and tool design are not abstract. They show up in concrete, measurable ways. Students who learn Python first frequently cannot implement basic algorithms from scratch — they reach for sorted() instead of writing a sort, for len() instead of tracking a count, for list comprehensions instead of understanding loop mechanics. Students who learn C first often develop a fear of programming itself, associating the craft with frustration and cryptic error messages. Students who learn Java first develop a cargo-cult relationship with boilerplate, writing public static void incantations they cannot explain. And students who learn JavaScript first absorb a model of computation so idiosyncratic that it actively interferes with understanding other languages.
These are not failures of the students. They are failures of the tools. We would not blame a carpentry student for making crooked cuts if we handed them a warped saw. We should not blame programming students for developing weak foundations when we hand them languages that were never designed to build foundations.
💡 Intuition: The Goldilocks Problem The ideal teaching language is not the easiest, not the hardest, but the one that introduces concepts in the right order, at the right level of abstraction, with the right amount of structure. It should be simple enough that beginners are not overwhelmed, but rigorous enough that the habits they form will serve them for decades. This is the Goldilocks problem of CS education, and it is the problem that Pascal was explicitly designed to solve.
We are not arguing that Python, C, Java, and JavaScript are bad languages. They are extraordinary tools, each brilliant in its domain. We are arguing that they are the wrong first language for someone who wants to learn to program well — the same way that a Formula One car is a terrible vehicle for learning to drive, even though it is one of the finest machines ever built.
There is a language that was designed, from its very first line of specification, to be the ideal teaching language. A language created by one of the most important computer scientists who ever lived, for the explicit purpose of teaching structured programming and algorithmic thinking. A language that is simple, readable, strongly typed, compiled to native code, and still very much alive.
That language is Pascal. And this book will show you why it remains the best way to learn to program.
1.2 Niklaus Wirth and the Birth of Pascal
📜 Historical Context: The Man Who Believed in Simplicity
To understand Pascal, you must understand the man who created it and the world he was reacting against.
Niklaus Wirth was born in 1934 in Winterthur, Switzerland. He studied electrical engineering at ETH Zurich, earned a master's degree at Laval University in Canada, and completed his PhD at the University of California, Berkeley in 1963. After brief stints at Stanford and the newly formed University of Zurich computer science department, he returned to ETH Zurich in 1968, where he would spend the rest of his career.
By the late 1960s, Wirth was already a prominent figure in programming language design. He had contributed to the development of Algol W, a dialect of the influential Algol 60 language. But Wirth was growing increasingly frustrated with the direction the field was taking.
The problem was complexity. The Algol 68 specification, which Wirth had been involved in debating, had grown into what he considered a baroque monstrosity — a language so complex that it took years to build a compiler for it and even experienced programmers struggled with its full feature set. The PL/I language, IBM's attempt at a "do everything" language, was even worse: a sprawling behemoth that tried to combine the features of FORTRAN, COBOL, and Algol into a single specification. Meanwhile, the GOTO statement — the ability to jump to arbitrary points in a program — was producing "spaghetti code" that was nearly impossible to read, debug, or maintain.
In 1968, Edsger Dijkstra published his famous letter "Go To Statement Considered Harmful," arguing that the GOTO was a fundamental obstacle to writing correct programs. Wirth agreed completely. But where Dijkstra was primarily a theorist, Wirth was a builder. He did not just want to argue that programming should be more structured — he wanted to create a language that made it structured.
In 1970, Wirth published the specification for Pascal.
📜 Historical Context: Why "Pascal"? The language is named after Blaise Pascal (1623–1662), the French mathematician and philosopher who built one of the first mechanical calculators, the Pascaline, in 1642. Wirth chose the name to honor a pioneer who combined mathematical rigor with practical engineering — exactly the combination Wirth valued.
The design goals were radical in their clarity:
-
The language should be suitable for teaching programming as a systematic discipline. Not as a vocational skill, not as a bag of tricks, but as a way of thinking.
-
The language should be efficient to implement on existing computers. A teaching language that required a supercomputer to run would be useless.
-
The language should enforce structured programming. No GOTO (well, Pascal technically includes it, but the entire design discourages it). Programs should be built from procedures, functions, and well-defined control structures:
if-then-else,while,for,repeat-until,case. -
The language should have strong, static typing. Every variable should have a declared type, checked at compile time. The compiler should catch errors before the program runs, not after.
-
The language should be readable. Code should read almost like English, with
beginandendinstead of cryptic braces, with keywords likeprocedure,function,var,const, andtypethat say exactly what they mean. -
The language should be small. A student should be able to learn the entire language in a single semester. No dark corners, no features that require years of experience to understand.
These were not just aesthetic preferences. Wirth believed — and history has largely vindicated him — that the qualities of a programming language shape the thought patterns of the programmers who use it. A language that tolerates sloppiness produces sloppy thinkers. A language that demands discipline produces disciplined thinkers.
💡 Intuition: Wirth's Law Niklaus Wirth is also famous for "Wirth's Law," his observation that software is getting slower more rapidly than hardware is getting faster. This was not a joke — it was a complaint about the bloat and inefficiency that result from languages and tools that make it too easy to be careless. Pascal was his antidote.
Pascal was an immediate success. Within a few years of its publication, computer science departments across Europe and North America were adopting it for their introductory courses. The reasons were exactly the ones Wirth intended: the language was small enough to teach in a single semester, structured enough to enforce good habits, and readable enough that students could understand each other's code.
By the mid-1970s, Pascal had become the dominant teaching language in universities worldwide. The UCSD Pascal system, developed at the University of California San Diego, made it available on microcomputers by compiling to an intermediate "p-code" that could run on different hardware — a precursor to Java's virtual machine concept, decades before Java existed. Kenneth Bowles and his team at UCSD created an entire operating system in Pascal, demonstrating that the language was not limited to toy programs.
But the real revolution came in 1983, when Borland International released Turbo Pascal for the IBM PC at the astonishing price of $49.95. At a time when most professional compilers cost hundreds or thousands of dollars, Turbo Pascal democratized programming. It compiled so fast that students could experiment rapidly, correcting errors and re-running programs in seconds rather than the minutes or hours that mainframe compilers required. The integrated editor — primitive by today's standards but revolutionary at the time — meant that you could write, compile, and run code without leaving a single program. Turbo Pascal sold hundreds of thousands of copies and created a generation of programmers who cut their teeth on Pascal.
By the 1980s, Pascal was the language of choice for the AP Computer Science exam in the United States. It was the language in which a generation of programmers — including many who went on to create the technologies we use today — first learned to think computationally.
📜 Historical Context: Anders Hejlsberg and the Pascal Legacy Anders Hejlsberg, who wrote Turbo Pascal for Borland, later created Delphi (an object-oriented Pascal) and then went to Microsoft, where he designed C#. The fingerprints of Pascal are all over C#'s type system and its emphasis on readability and safety. When you write C#, you are writing in a language shaped by Pascal's philosophy.
Wirth continued to refine his ideas after Pascal. He created Modula-2 (1978), which added modules for large-scale programming, and Oberon (1987), an even more minimal language. But Pascal remained his most influential creation. He received the Turing Award — computing's Nobel Prize — in 1984, with Pascal cited as a major contribution.
Niklaus Wirth passed away on January 1, 2024, at the age of 89. His legacy is not just the languages he created but the principle that animated all of them: simplicity is not the absence of power — simplicity is power.
1.3 What Makes Pascal Special?
Let us be concrete. What are the specific features of Pascal that make it superior as a teaching language? We will examine six.
1.3.1 Strong, Static Typing
In Pascal, every variable must be declared with a type before it is used. If you declare var age: Integer;, then age can hold integers and nothing else. If you try to assign a string to age, the compiler will refuse to compile your program. Not at runtime, when the program is in a user's hands — at compile time, before the program ever runs.
This is not a limitation. This is a safety net.
Consider what happens in Python:
age = 25
age = "twenty-five" # Python allows this — no error
result = age + 10 # Runtime crash: cannot add string and int
The error in the third line is a consequence of the permissiveness of the second line. Python trusts you to keep track of what types your variables hold. This is fine for an experienced programmer. For a beginner, it is a trap. The program appears to work until it suddenly does not, and the error message points to the wrong line.
In Pascal:
var
age: Integer;
begin
age := 25;
age := 'twenty-five'; { Compiler error — caught BEFORE the program runs }
end.
The compiler catches the mistake immediately, with a clear error message pointing to the exact line. The student learns, from day one, that variables have types and types matter. This lesson transfers directly to C, C++, Java, C#, Rust, Go, TypeScript, and every other typed language they will encounter in their career.
💡 Intuition: The Compiler as Teacher Think of Pascal's compiler as an extremely patient teaching assistant who reads your homework before you submit it and circles every mistake in red. Python's interpreter, by contrast, is like a teaching assistant who lets you submit your homework and only tells you about mistakes when the professor is grading it — at runtime, when the cost of errors is much higher.
1.3.2 Structured Programming by Design
Pascal provides exactly the control structures you need — and no more:
- Sequence: Statements execute in order.
- Selection:
if-then-elseandcasestatements. - Iteration:
for,while, andrepeat-untilloops. - Procedures and functions: Named blocks of code that encapsulate behavior.
There is no goto in practice (it exists in the language specification but is universally discouraged and essentially never used in modern Pascal). There are no implicit fallthrough cases. There are no clever tricks that let you write unreadable one-liners. Every Pascal program reads top to bottom, and its structure is visible in its indentation.
This forces students to think about program structure from the very beginning. When you cannot take shortcuts, you learn to design your programs properly.
The theorem that justifies this design is the Bohm-Jacopini theorem (1966), which proves that any computable function can be expressed using only sequence, selection, and iteration — no GOTO required. Pascal was one of the first languages to take this theorem seriously as a design constraint. The result is that every Pascal program can be understood by reading it from top to bottom, tracing the flow through clearly marked branches and loops. There are no hidden jumps, no surprise transfers of control, no paths through the code that you cannot see.
This has a profound effect on debugging. When a Pascal program does the wrong thing, you can trace its execution mentally, following the control structures. In a language with GOTOs — or with the implicit control flow of callbacks, promises, and async/await — tracing execution requires a fundamentally different (and much harder) mental model that beginners simply do not have.
1.3.3 Readability as a Design Principle
Pascal code reads almost like English:
program Greeting;
var
name: string;
begin
Write('What is your name? ');
ReadLn(name);
WriteLn('Hello, ', name, '! Welcome to Pascal.');
end.
Compare this to the equivalent C:
#include <stdio.h>
int main(void) {
char name[100];
printf("What is your name? ");
scanf("%99s", name);
printf("Hello, %s! Welcome to C.\n", name);
return 0;
}
The Pascal version uses begin and end instead of braces. It uses Write and WriteLn instead of printf with format specifiers. It uses := for assignment (distinguishing it clearly from = for equality comparison — a source of countless bugs in C). Variable declarations are in a clearly labeled var section. The program is named. Every element is self-documenting.
For a beginner encountering code for the first time, which version is more approachable? Which teaches better habits?
Readability is not a luxury. It is a safety feature. Code is read far more often than it is written — by the original author returning to it weeks later, by teammates trying to understand it, by students trying to learn from it. A language that optimizes for readability optimizes for the most common operation in software development. Pascal's designers understood this fifty years ago. It took the rest of the industry decades to catch up, and many languages still have not.
Consider also the cognitive load on a beginner. When a student encounters { in C, they must remember that this means "begin a block." When they encounter begin in Pascal, the meaning is self-evident. When a Python student sees significant whitespace, they must understand a rule that is invisible — the difference between four spaces and a tab can change the meaning of a program, and you cannot see the difference. Pascal's block structure is explicit and visible, reducing the cognitive overhead that distracts beginners from the actual logic of their programs.
1.3.4 The Declaration-Before-Use Principle
In Pascal, everything must be declared before it is used. Variables go in the var section. Constants go in the const section. Types go in the type section. All of these appear before the begin that starts the executable code.
This is not arbitrary bureaucracy. It teaches a fundamental discipline: think before you code. Before you write a single line of executable code, you must plan what data your program will work with, what constants it will use, and what types it will define. This front-loaded planning is exactly the habit that separates good programmers from struggling ones.
⚠️ Common Pitfall: "Pascal Is Too Verbose" New students sometimes complain that Pascal makes them write "too much" before they can start coding. This is like a piano student complaining that scales are "too boring" before they can play songs. The declaration discipline is not overhead — it is the foundation. Students who internalize it write better code in every language they subsequently learn.
1.3.5 Native Compilation
Pascal compiles to native machine code. When you compile a Pascal program, you get an executable binary — a .exe on Windows, an ELF binary on Linux, a Mach-O binary on macOS — that runs directly on the processor without any interpreter or virtual machine.
This matters for two reasons:
-
Performance. Pascal programs run fast. Not "fast enough for a teaching language" — genuinely fast. Free Pascal's generated code is typically within a small factor of hand-optimized C. This means students can tackle problems that would be impossibly slow in Python, and they develop an intuition for what "fast" means.
-
Understanding. When you compile to native code, you are one step closer to the hardware. Students learn what a compiler does: it translates human-readable source code into machine instructions. This is a fundamental concept in computer science, and it is completely invisible in interpreted languages like Python and JavaScript.
🔗 Connection: Chapter 2 In Chapter 2, you will install Free Pascal and compile your first program. You will see the compiler in action — how it reads your source code, checks it for errors, and produces a native executable that you can run, share, and inspect.
There is also a practical benefit worth mentioning: distribution. A compiled Pascal program is a single executable file. You can share it with anyone running the same operating system, and they can run it immediately — no installation of Python, no JVM, no Node.js, no package manager, no pip install. For students, this is empowering: "I made this program, and you can run it." The sense of having created something real, tangible, and shareable is a powerful motivator that interpreted languages cannot match in the same way.
In the era of AI-assisted coding, native compilation takes on additional importance. Tools like ChatGPT and Copilot can generate code in any language, but understanding what that code does — what it compiles to, how it executes, why it performs well or poorly — requires the mental model that compilation provides. Students who learn with a compiled language develop this model naturally; students who learn with interpreted languages often never do.
1.3.6 A Clean Foundation for Data Structures and Algorithms
Wirth's most famous book is titled Algorithms + Data Structures = Programs (1976). This is not a catchy slogan — it is a precise statement of his philosophy. A program is nothing more and nothing less than algorithms operating on data structures. Everything else is implementation detail.
Pascal was designed to make this equation visible. Its type system lets you define records (like C structs), arrays, sets, pointers, and linked data structures with a clarity that no other language of its era matched. When you define a linked list in Pascal, every component — the node type, the pointer type, the allocation, the traversal — is explicit and visible.
This matters enormously for learning. Data structures and algorithms courses are the heart of a computer science education, and students who first encounter these concepts in Pascal develop a deeper understanding than those who encounter them through Python's built-in lists and dictionaries, which hide the underlying mechanics.
🔗 Connection: Parts IV and V In Parts IV and V of this book, you will implement stacks, queues, linked lists, binary trees, hash tables, and graphs in Pascal. You will build them from scratch, understanding every pointer and every allocation. The skills you develop will transfer directly to C, C++, Rust, and any other language that requires explicit data structure management.
1.4 Pascal vs. The Competition: An Honest Comparison
We believe Pascal is the best first language. But we also believe in intellectual honesty. Let us compare Pascal to the four languages most commonly used in introductory courses, acknowledging both strengths and weaknesses.
1.4.1 Pascal vs. Python
Where Python wins: - Faster to get a visible result. "Hello, World" is one line in Python, five in Pascal. - The ecosystem is vast. NumPy, pandas, Django, Flask, TensorFlow — Python has a library for everything. - Industry demand is enormous. Python is the most-requested language in job postings. - Interactive REPL allows experimentation without compilation.
Where Pascal wins: - Strong typing catches errors at compile time, not runtime. - Forced declaration teaches planning before coding. - Compilation teaches what computers actually do. - Performance is orders of magnitude better for computationally intensive tasks. - Students who learn Pascal first find Python easy afterwards. The reverse is not true. - No "magic" — everything is explicit and visible.
📊 Real-World Application: The Transfer Effect Studies of CS2 performance consistently show that students who learned a typed, compiled language first perform better in data structures courses than those who learned Python first. The reason is straightforward: Pascal forces you to think about types, memory, and structure from day one. Python lets you postpone that thinking — and many students never develop it.
🔬 Deep Dive: The Hidden Cost of Python's Ease There is a subtle trap in Python's gentleness. Because Python makes the first few weeks of programming easy, students develop confidence quickly. But this confidence is often unearned — it is based on the ability to make code run, not on genuine understanding. When these students encounter harder material (data structures, algorithms, systems programming), the gap between their confidence and their competence becomes a chasm. Psychologists call this the Dunning-Kruger effect: when you do not know enough to know what you do not know. Pascal's strictness produces less initial confidence but more genuine competence, because the compiler forces students to confront their misunderstandings immediately rather than letting them accumulate.
The verdict: Python is a better productivity language. Pascal is a better learning language. In this book, we prioritize learning. Once you have mastered Pascal, Python will feel like a vacation.
1.4.2 Pascal vs. C
Where C wins: - Ubiquitous in systems programming: operating systems, embedded systems, compilers. - Maximum control over hardware: direct memory manipulation, bit-level operations. - Industry standard for performance-critical code. - Understanding C means understanding how computers work at the lowest levels.
Where Pascal wins:
- Strong typing prevents entire categories of C bugs (buffer overflows, type confusion).
- No pointer arithmetic by default — pointers are safer.
- Readable syntax: begin/end vs. {/}, := vs. =.
- Separate assignment (:=) and equality (=) operators eliminate the if (x = 5) bug.
- String handling is built-in and safe, not a minefield of char* and strlen.
- Compilation errors are clearer and more helpful.
⚠️ Common Pitfall: "C Teaches You How Computers Work" This is true, but it is the wrong argument for a first language. C teaches you how computers work at the hardware level — memory addresses, byte layouts, register usage. This is important knowledge, but it is not where beginners should start. Pascal teaches you how programs work — structure, logic, types, algorithms. Learn Pascal first, then learn C, and both lessons will be stronger.
The verdict: C is the right second or third language. Pascal is the right first language. Wirth designed Pascal precisely because he found that teaching Algol and C-like languages to beginners produced confusion, not understanding.
1.4.3 Pascal vs. Java
Where Java wins: - Object-oriented from the ground up: a natural path to enterprise software development. - Platform-independent via the JVM: "write once, run anywhere." - Enormous corporate ecosystem: Spring, Jakarta EE, Android development. - Strong community and documentation.
Where Pascal wins:
- No boilerplate. Java's "Hello, World" requires a class, a method, and a public static void main(String[] args) incantation that beginners cannot possibly understand. Pascal's requires nothing the student cannot immediately comprehend.
- Procedural first, object-oriented later. Pascal lets students master the fundamentals before introducing OOP — which is a more natural learning progression.
- Faster compilation and smaller executables.
- Free Pascal supports OOP when you are ready for it, without forcing it from day one.
💡 Intuition: Procedural First, Then Objects Object-oriented programming is a way of organizing large programs. It is not a way of thinking about computation. Computation is fundamentally about sequences of operations on data. OOP is a management strategy for when those sequences become complex enough to need organizational structure. Teaching OOP first is like teaching corporate management before teaching anyone to do a job. Pascal's approach — learn to compute first, learn to organize later — matches the natural cognitive progression. You will encounter OOP in Part V of this book, and by then you will understand why it is useful, not just how to use it.
The verdict: Java is a fine language for learning object-oriented programming. It is a poor language for learning programming. Pascal teaches the foundations that make OOP comprehensible.
1.4.4 Pascal vs. JavaScript
Where JavaScript wins: - Runs in every web browser on earth. - Full-stack development: front-end, back-end (Node.js), and mobile. - Immediate visual feedback when building web applications. - Largest npm ecosystem of any language.
Where Pascal wins:
- Consistent, predictable behavior. JavaScript has more quirks and edge cases than any other mainstream language (typeof null === 'object', anyone?).
- Strong typing vs. JavaScript's famously confusing type coercion ("" == false is true, but "" === false is false).
- Structured programming vs. callback spaghetti and async confusion.
- Pascal teaches computational thinking. JavaScript teaches web development. These are not the same thing.
The verdict: JavaScript is indispensable for web development. It is a terrible teaching language. Its quirks, its inconsistencies, and its multiple paradigms create confusion that actively interferes with learning fundamentals.
1.4.5 A Note on Newer Languages
What about Rust, Go, Swift, Kotlin, or TypeScript? These are all excellent modern languages, and several have strong typing and compilation. But none was designed as a teaching language. Rust's ownership system, while brilliant for memory safety, is widely acknowledged as having the steepest learning curve of any mainstream language. Go sacrifices expressiveness for simplicity in ways that can frustrate when teaching OOP or generics. Swift and Kotlin are tightly coupled to their respective ecosystems (Apple and Android). TypeScript is a layer on top of JavaScript and inherits many of its quirks.
Pascal remains unique: it was designed for teaching, and the evidence of five decades shows that it teaches well. The newer languages are valuable tools that you may learn after Pascal — and you will learn them faster because of the foundations Pascal provides.
1.4.6 Summary Table
| Feature | Pascal | Python | C | Java | JavaScript |
|---|---|---|---|---|---|
| Static typing | Yes | No | Yes | Yes | No |
| Compile-time error checking | Excellent | Minimal | Good | Good | Minimal |
| Readability | Excellent | Excellent | Fair | Fair | Fair |
| Beginner-appropriate | Designed for it | Accessible but permissive | Too low-level | Too much ceremony | Too many quirks |
| Native compilation | Yes | No (interpreted) | Yes | No (JVM) | No (interpreted/JIT) |
| Teaches structure | By design | By convention | By necessity | By enforcement | Barely |
| Path to data structures | Natural | Hidden by abstractions | Natural but dangerous | Verbose | Unnatural |
1.5 The Modern Pascal Ecosystem
⚠️ Common Pitfall: "Pascal Is Dead" This is the single most common misconception about Pascal, and it is flatly wrong. Pascal is not dead. It is not "only used in schools." It is a living, actively developed language with a passionate community, commercial backing, and real-world applications. Let us look at the evidence.
1.5.1 Free Pascal
Free Pascal (FPC) is an open-source, professional-grade Pascal compiler that supports multiple Pascal dialects including Turbo Pascal, Delphi, and its own extensions. It runs on and compiles for an extraordinary range of platforms:
- Operating systems: Windows, macOS, Linux, FreeBSD, iOS, Android, and others.
- Processor architectures: x86, x86-64, ARM, AArch64, PowerPC, MIPS, RISC-V, and more.
- Cross-compilation: You can compile a Windows program on a Linux machine, or an Android application on a Mac.
Free Pascal is the compiler we will use throughout this book. It is free (in both senses — free as in beer and free as in freedom), it is standards-compliant, and it produces fast native code. The current stable release, Free Pascal 3.2.2, is a mature, reliable tool that is actively maintained by a dedicated team of developers.
🏃 Fast Track If you already have programming experience and want to get started immediately, skip to Chapter 2 for installation instructions and your first program. You can always come back to this chapter later.
1.5.2 Lazarus IDE
Lazarus is a free, open-source integrated development environment (IDE) built on Free Pascal. It provides a visual form designer — drag and drop buttons, text fields, menus, and other GUI components — that is directly inspired by Delphi's legendary visual development environment. With Lazarus, you can build full cross-platform GUI applications that compile natively for Windows, macOS, and Linux from a single codebase.
Lazarus is not a toy. It is a serious development tool used for commercial software. Its component library (LCL — Lazarus Component Library) wraps each platform's native widgets, so your applications look and feel native on every operating system.
🔗 Connection: Part VII In Part VII of this book, you will use Lazarus to build the GUI version of PennyWise. By that point, you will have mastered console-based Pascal and be ready to apply your skills to graphical application development.
1.5.3 Embarcadero Delphi
Delphi is the commercial descendant of Borland's Turbo Pascal. Originally released in 1995, Delphi extended Pascal with object-oriented features, a powerful visual IDE, and a component-based architecture that was years ahead of its time. Today, Delphi is developed by Embarcadero Technologies and remains a commercially viable tool for building Windows, macOS, iOS, and Android applications.
Delphi's significance goes beyond its current user base. Its influence on software development is enormous:
- Visual component-based development: Delphi pioneered the "drag a button onto a form, double-click it to write the event handler" paradigm that Visual Basic, C# Windows Forms, and every modern GUI builder now uses.
- The VCL (Visual Component Library): A model for reusable UI components that influenced .NET's Windows Forms and WPF.
- RAD (Rapid Application Development): Delphi proved that you could build professional desktop applications quickly without sacrificing performance.
📊 Real-World Application: Software Built with Pascal/Delphi The list of notable software built with Pascal and Delphi may surprise you: - Skype (original Windows client) — built in Delphi - FL Studio — one of the world's most popular digital audio workstations, written in Delphi - Total Commander — legendary file manager, written in Delphi - Beyond Compare — professional file comparison tool, written in Delphi - HeidiSQL — popular database management tool, written in Delphi - PeaZip — open-source file archiver, written in Free Pascal/Lazarus - Double Commander — cross-platform file manager, written in Free Pascal/Lazarus - Castle Game Engine — 3D/2D game engine, written in Free Pascal - Thousands of internal business applications in finance, healthcare, manufacturing, and logistics
Pascal is not a museum piece. It is a living, working language.
1.5.4 The Community
The Free Pascal and Lazarus communities are active and welcoming:
- Free Pascal Wiki (wiki.freepascal.org): Extensive documentation and tutorials.
- Lazarus Forum (forum.lazarus-ide.org): Active community forum with quick response times.
- Pascal subreddits and Discord servers: Growing communities of enthusiasts and professionals.
- Annual conferences: PascalCon and other events bring the community together.
- GitHub: Thousands of Free Pascal and Lazarus projects, libraries, and frameworks.
🔬 Deep Dive: Object Pascal Standards For students interested in language design, the history of Pascal standardization is fascinating. ISO 7185 (1983) standardized the original Pascal. ISO 10206 (1990) standardized Extended Pascal. Borland's extensions created a de facto "Turbo Pascal" dialect. Delphi introduced "Object Pascal." Free Pascal synthesizes all of these into a remarkably complete and compatible implementation. This evolution — from a teaching language to a full production language — is itself a lesson in how languages grow.
1.6 What You'll Build in This Book
Theory is essential, but programming is ultimately a craft. You learn it by doing it. This book is organized around projects that grow in complexity as your skills develop. Let us preview the major ones.
1.6.1 PennyWise Personal Finance Manager — The Progressive Project
PennyWise is the backbone of this book. It is a personal finance management application that you will build incrementally, chapter by chapter, from a simple console program to a full cross-platform GUI application.
Let us introduce the two characters whose needs will drive PennyWise's development:
Rosa Martinelli is a 34-year-old freelance graphic designer based in Portland, Oregon. She loves her work, but managing the financial side of freelancing is a constant headache. She has income from multiple clients arriving on unpredictable schedules. She needs to track business expenses for tax deductions — software subscriptions, hardware purchases, a portion of her home office rent. She currently uses a chaotic combination of spreadsheets, sticky notes, and a shoebox full of receipts. She wants something simple, fast, and reliable — not a bloated corporate tool, not a cloud service that sells her data, just a clean program that helps her see where her money goes.
Tomás Vieira is a 20-year-old college sophomore studying biology in Austin, Texas. He is on a tight budget: a part-time campus job, a small parental allowance, and student loans. He wants to track his spending by category — food, textbooks, entertainment, rent — and get a clear picture of whether he is living within his means. He does not need invoicing or tax categories. He needs a simple tool that tells him, at a glance, how much he has spent this month and how much he has left.
Rosa and Tomás represent two very different users with two very different needs, but a well-designed system can serve both. This is a key insight of software engineering: good architecture accommodates diverse requirements.
Why two characters? Because software is ultimately about people. It is easy, when learning to program, to think only about the code — about syntax and logic and algorithms. But code exists to serve human needs. Rosa and Tomás will keep us grounded throughout this book. When we make a design decision, we will ask: "Does this serve Rosa's needs? Does it serve Tomás's needs? How?" This habit — anchoring technical decisions in human needs — is what separates programmers who build useful software from programmers who build clever software that no one uses.
You will get to know Rosa and Tomás well. Rosa is organized in her design work but chaotic in her finances; she needs structure imposed by software because she cannot impose it on herself. Tomás is careful by nature but lacks the tools to make his care effective; he needs visibility into where his money goes. Both of them need simplicity — not the false simplicity of a tool that hides complexity, but the genuine simplicity of a tool that does exactly what it should and nothing more. This, not coincidentally, is the same philosophy that animates Pascal itself.
Here is how PennyWise will evolve:
- Part I (Chapters 1–5): You learn the foundations. PennyWise exists only as a concept and some pseudocode.
- Part II (Chapters 6–11): PennyWise v0.1 — a console program that records and displays transactions. Tomás can enter his expenses and see totals.
- Part III (Chapters 12–17): PennyWise v0.5 — file I/O lets you save and load data. Categories, search, and basic reports. Rosa can track her client income.
- Part IV (Chapters 18–23): PennyWise v1.0 — arrays, records, and dynamic data structures. Sorting, filtering, and proper data management.
- Part V (Chapters 24–29): PennyWise v1.5 — object-oriented design. Transaction classes, category hierarchies, and a clean architecture.
- Part VI (Chapters 30–35): PennyWise v2.0 — advanced features. Database connectivity, error handling, and unit testing.
- Part VII (Chapters 36–40): PennyWise v3.0 — the Lazarus GUI. Rosa gets a professional-looking desktop application. Tomás gets a dashboard showing his budget at a glance.
🔗 Connection: Every Chapter Each chapter includes a "PennyWise Checkpoint" that applies the chapter's concepts to the project. By the end of the book, you will have built a real, useful application — not a toy, not an exercise, but something you might actually use.
1.6.2 Other Projects
PennyWise is the main project, but it is not the only one. Along the way, you will also encounter:
-
Crypts of Pascalia: A text-based adventure game that teaches control flow, string manipulation, and program design. You will build a dungeon with rooms, items, puzzles, and a parser that understands player commands. This project emphasizes the fun side of programming — because programming should be fun.
-
GradeBook Pro: A grade management system that teaches arrays, records, file I/O, and report generation. This is a practical tool that could be used by a real teacher (or a real student tracking their own grades).
-
MicroServe: An HTTP server built from scratch in Pascal. This advanced project, appearing in the final chapters, demonstrates that Pascal can do anything "modern" languages can do — including network programming, protocol implementation, and concurrent request handling.
1.6.3 Why Projects Matter
There is a reason we organize this book around projects rather than just concepts. Cognitive science research on learning tells us that knowledge is most effectively retained when it is applied to meaningful tasks. Isolated exercises ("write a function that reverses a string") teach syntax but not design. Projects teach both — because a project requires you to make decisions about structure, organization, and architecture that exercises never touch.
PennyWise, in particular, is designed to feel real. It is not a toy. By the end of this book, you will have a personal finance manager that you might actually use. Rosa's and Tomas's needs are not artificial — they are the kinds of needs that real people have, and solving them requires real engineering thinking. When you implement categorized transactions, you are not just learning about records and arrays — you are learning to model a domain. When you add file persistence, you are not just learning about file I/O — you are learning about data durability. When you build the GUI, you are not just learning about widgets — you are learning about user experience.
Each project also serves as a portfolio piece. By the end of this book, you will have four complete applications that demonstrate your ability to design, implement, and refine software. Whether you continue with Pascal or move to another language, these projects will demonstrate that you can build things — which is, ultimately, what programming is about.
1.7 Who This Book Is For
This book is written for three overlapping audiences:
Audience 1: The True Beginner
You have never written a line of code. Maybe you are a college freshman in your first CS course. Maybe you are a self-taught learner who has been intimidated by programming tutorials that assume too much. Maybe you are a professional in another field — a scientist, an accountant, a writer — who wants to understand the technology that increasingly shapes your work.
What you need to know: Nothing. We start from zero. Chapter 2 will walk you through installing Free Pascal. Chapter 3 will explain your first program line by line. We assume no prior knowledge of programming, computer science, or mathematics beyond basic arithmetic.
What you will gain: A rock-solid foundation in programming that will serve you no matter where your career takes you. The skills you learn in this book — thinking in types, designing with structures, solving problems algorithmically — are universal. They transfer to every language.
Audience 2: The Experienced Programmer Seeking Foundations
You already know Python, or JavaScript, or Java. You can make things work. But you have a nagging feeling that you are missing something — that your understanding is built on sand. Maybe you struggle with pointers in C. Maybe you do not really understand how a compiler works. Maybe you can use a hash map but could not implement one.
What you need to know: You can move faster through the early chapters using the "Fast Track" annotations. But do not skip too aggressively — you may be surprised by what you do not know.
What you will gain: The conceptual foundations you missed the first time around. Pascal will force you to confront types, memory, and program structure in ways that Python and JavaScript never did. You will emerge a stronger programmer in every language you use.
Audience 3: The Instructor
You teach introductory computer science, and you are looking for a textbook that takes a different approach. Maybe you are frustrated with Python's permissiveness, Java's boilerplate, or C's complexity. Maybe you remember Pascal from your own education and have been looking for a modern treatment.
What you need to know: Each chapter includes learning objectives, exercises at multiple levels (conceptual, applied, synthesis, research), quizzes with detailed answers, and two case studies. The instructor's guide (available separately) provides lecture outlines, additional exercises, and exam questions.
What you will gain: A complete, classroom-ready textbook that teaches programming the way Wirth intended — as a systematic discipline, not a collection of tricks.
A Note on Prerequisites
This book assumes:
- Mathematical: Basic arithmetic (addition, subtraction, multiplication, division). That is all. We introduce any additional mathematics (like Boolean logic) as we need it.
- Technical: You have access to a computer running Windows, macOS, or Linux, and you know how to install software and navigate your file system.
- Motivational: You are willing to do the work. Programming is a skill, like playing an instrument or learning a sport. Reading about it is not enough — you must practice. The exercises are not optional.
How to Use This Book
A few words on getting the most out of this textbook:
Read actively, not passively. When you encounter a code example, do not just glaze over it. Read each line. Predict what it does before reading the explanation. If the prediction is wrong, stop and figure out why. Active reading is slower but dramatically more effective than passive reading.
Do the exercises. Every chapter includes exercises at multiple levels: conceptual understanding, applied analysis, code writing, synthesis and critical thinking, and research. You do not need to do every exercise, but you should do at least some from each level. The code exercises (starting in Chapter 3) are especially important — you cannot learn to program by reading about programming, just as you cannot learn to swim by reading about swimming.
Build PennyWise. The progressive project checkpoints are not optional extras. They are the spine of the book. Each checkpoint applies that chapter's concepts to a real, growing application. Skipping them is like skipping the lab component of a science course — you will understand the theory but not the practice.
Use the Fast Track and Deep Dive annotations. If you are an experienced programmer, the 🏃 Fast Track annotations tell you which sections you can skim. If you are a curious beginner who wants more depth, the 🔬 Deep Dive annotations point you to extended discussions. These annotations let you customize the book to your level without losing the overall structure.
Do not skip Chapter 2. It covers installation and your first program. Even if you think you can figure it out on your own, the chapter also introduces the compilation process and the structure of a Pascal program in detail that will serve you throughout the book.
1.8 Chapter Summary
Let us retrace our path through this chapter.
We began with a problem: introductory programming courses fail too many students, and the languages we use bear much of the blame. Python is too permissive, C is too dangerous, Java is too ceremonious, and JavaScript is too chaotic.
We met Niklaus Wirth, the Swiss computer scientist who recognized this problem in the 1960s and spent his career solving it. In 1970, he created Pascal — a language designed from its very first specification to teach programming as a systematic discipline.
We examined what makes Pascal special: strong static typing that catches errors before runtime, structured programming that teaches good design, readable syntax that makes code self-documenting, declaration-before-use that teaches planning, native compilation that teaches what computers do, and a clean foundation for data structures and algorithms.
We compared Pascal honestly to Python, C, Java, and JavaScript. Each of those languages excels in its domain, but none was designed to teach. Pascal was.
We explored the modern Pascal ecosystem — Free Pascal, Lazarus, and Delphi — and saw that Pascal is not a dead language but a living, actively developed tool used in real commercial software. Skype, FL Studio, Total Commander, and thousands of other applications were built with Pascal's descendants.
We previewed what you will build: PennyWise, a personal finance manager that grows from a simple console program to a full GUI application; Crypts of Pascalia, a text adventure; GradeBook Pro, a grade management system; and MicroServe, an HTTP server. These are not toys — they are real applications that demonstrate real engineering principles.
And we identified who this book is for: true beginners, experienced programmers seeking foundations, and instructors looking for a better way to teach.
💡 Intuition: The Core Argument Here is the thesis of this entire book, stated as simply as we can: The purpose of a first programming language is not to be the language you use forever. It is to teach you to think like a programmer. Pascal does this better than any other language because it was designed — by one of the greatest computer scientists who ever lived — to do exactly this and nothing else. The discipline you learn in Pascal will make you better at every language you ever touch.
Niklaus Wirth had a favorite quotation that captures the philosophy animating this book. It comes from Antoine de Saint-Exupery, and it appears in the epigraph of Wirth's Algorithms + Data Structures = Programs:
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away."
This is the philosophy of Pascal. This is the philosophy of this book. Let us begin.
PennyWise Checkpoint: Chapter 1
Status: Concept introduced. No code yet.
In this chapter, you met Rosa Martinelli and Tomás Vieira — the two users whose needs will drive PennyWise's development. Rosa needs to track freelance business income and expenses across multiple clients. Tomás needs to track personal spending on a college budget.
What PennyWise will become: - A console application that records financial transactions (income and expenses) - Categorized tracking (food, rent, client income, business expenses, etc.) - File-based persistence (save and load your data) - Reports: monthly summaries, category breakdowns, budget vs. actual - A GUI version with dashboards and visual charts
What to think about before Chapter 2: - What data would PennyWise need to store for each transaction? (Date? Amount? Category? Description?) - How might Rosa's needs differ from Tomás's needs? - What would a "minimum viable product" look like — the simplest version that is actually useful?
These are not programming questions yet. They are design questions — and good programming always starts with good design.
🔗 Connection: Chapter 2 In the next chapter, you will install Free Pascal, configure your development environment, and write your first Pascal program. The journey from concept to code begins.