Turbo Pascal is one of the languages I really wanted to include in my online IDE for retro programmers, along with a personal favourite of mine, Turbo C, and the ever-popular QBasic.
But why?
Many programming languages have shaped the way we think about coding, and Pascal is one of those.
Despite being created over 50 years ago, its influence continues in both education and certain technical domains today.
Whether you're a beginner or simply interested in the history of programming, understanding Pascal offers valuable insights into the roots of modern software development.
Why Is Pascal Important?
Pascal holds a special place in the history of programming for several reasons:
While BASIC was incredibly successful at introducing regular folks to the world of programming, Pascal was specifically designed as a teaching language to introduce students to good programming.
Niklaus Wirth, inventor of Pascal, helped shape many future languages, including Modula-2 and Ada. He sadly passed away January 2024.
Although created in the 1960s, it became the standard language for teaching computer science in the 1980s, and perhaps as a consequence it was used in real-world commercial software like early computer games (e.g., Crisis Mountain, Gravity Wars), and desktop applications on the Apple Mac, such as Adobe Photoshop!
Today, although its popularity has declined, Pascal (and it's Object relatives) remains relevant, especially in educational settings and niche projects. Its clear syntax and strong structure make it a useful language for learning core programming concepts.
Getting Started with Pascal
To begin coding in Pascal:
Install a Modern Compiler: The Free Pascal Compiler (FPC) is a free, open-source command-line tool available for tons of operating systems that allows you to compile and run Pascal programs. Not sure why it is over 1gb though!
Delphi and Lazarus: While you can write Pascal code in any text editor, IDEs like Lazarus provide helpful features like syntax highlighting and easy debugging.
Use my Online IDE: As mentioned, I have a free online development environment built especially around the goal of giving people the tools to code in retro languages and for classic computers!
Your First Program: "Hello, World!"
Here's a simple example to get you started.
program HelloWorld;
begin
writeln('Hello World!');
writeln('Press any key to continue...');
readln;
end.
program
marks the beginning of the program.begin
andend.
wrap the program's executable statements.WriteLn
outputs text to the screen, andreadLn
reads input from the console.
Variables and Constants
Pascal is strongly typed, meaning each variable must have a defined type, similar to C or TypeScript. Examples include Integer
, Boolean
, String
, and user-defined types.
- Constants: Immutable data (unchanged once set):
const Pi = 3.14159;
- Variables: Changeable data, with explicit types:
var count: Integer; name: string;
Functions vs Procedures
- Functions: Perform calculations or operations and return a value.
function IsEven(num: Integer): Boolean;
begin
Result := (num mod 2 = 0);
end;
- Procedures: Execute actions without returning a value.
procedure PrintMessage(message: string);
begin
WriteLn(message);
end;
Here's how to use these in your program:
var number: Integer; evenCheck: Boolean;
begin
number := 10;
evenCheck := IsEven(number);
PrintMessage('Number is even: ' + BoolToStr(evenCheck, True));
end.
Creating Custom Data Types
Pascal supports creating complex data structures using records, similar to structs in C:
type Person = record
Name: string;
Age: Integer;
end;
var person1: Person;
begin
person1.Name := 'Alice';
person1.Age := 30;
WriteLn('Name: ', person1.Name, ', Age: ', person1.Age);
end.
Building and Executing Pascal Programs
Once your code is ready:
Compile it using the Free Pascal Compiler (FPC).
The compiler transforms your source code into an executable file.
Run the compiled program on your operating system to see results.
For example:
fpc myprogram.pas ./myprogram
Final Thoughts
Pascal remains a notable milestone in the history of programming. It demonstrates how thoughtful language design can influence education, software development, and even hardware. If you're interested in learning programming fundamentals or exploring the roots of many modern languages, getting familiar with Pascal offers a lot of fun and rewards.
Pascal's clarity and structure, along with modern tools, continue to make it a valuable language, especially for people desiring to understand core programming concepts.
Resources for Getting Started
Free Pascal Compiler (FPC): https://www.freepascal.org/
Lazarus IDE: https://www.lazarus-ide.org/
We used Pascal in a computer programming class I had in high school. As I recall, Pascal was used a lot for creating BBS door games, too.
Oh I didn't know that! I know a lot of Apple folks were big on Pascal for a long time, whereas I mainly knew it as a university thing until Delphi
Pascal was never one that we had to learn way back when I was in university. I have a feeling it was already on the way out by that time in the late 90's? If I had stuck with one language to focus on and get good at, I wish I would have studied SQL more. It's still relevant today as a quite marketable skill I think.
I did some Pascal on my electronics degree using the Polytechnic mini. Later I used Turbo Pascal that was one of the first real IDEs I used. I loved the Borland stuff back then. I've not really used it since, but I like to think it gave me a good start in structured programming, including OOPS.
That brought back memories! Haven't coded in Pascal or Delphi in over 20 years (more like 25).
Looking at the code snippets, I want to mention something for anyone reading them and who might get the wrong impression.
Pascal (and any of its variants, including Delphi) is not case sensitive, unlike C/C++.
So, for example
var person1: Person;
is syntactically identical tovar person1: person;
in Pascal, and you can't have something likevar person: Person;
, because you can't have the variable name identical to the record name (they are case insensitive). That's different than in C, where something like this is perfectly ok:struct Person { int age; char name[50]; }; int main() { struct Person person; return 0; }
Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!
Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).
Consider setting @stemsocial as a beneficiary of this post's rewards if you would like to support the community and contribute to its mission of promoting science and education on Hive.