What about ObjectPascal?
What about it? The fact that I'm getting back into Python again, doesn't imply that I've lost my love for ObjectPascal.
As some people that have been following me over the years may have noticed, I was rather huge on ObjectPascal, using it through FreePascal, and building desktop applications, command-line applications, and even web applications with using the spectacular Lazarus IDE. One day, I will be writing about my various projects, but in this post, I'd like to discuss why I'm not done with ObjectPascal.
Where Object Pascal Thrives
ObjectPascal to a lot of modern developers is a so-called dead programming language, but it isn't dead, it's just not as popular as say Rust or Go when it comes to a compiled language. Some might also argue that C and C++, developed around the same time as the original Pascal need to be shelved, but both still remain in very active use. While a lot of developers have indeed moved on from ObjectPascal and Delphi, which is also around and actively being developed. While in some cases, the ObjectPascal language is still around and being maintained for legacy reasons, this isn't the whole story. If that were indeed the case, then why would modern FreePascal and Delphi be adding more modern features to the language all these decades later? Did you know that Delphi can actually have a single Pascal code base that can target a lot of targets, which includes not only the desktop, but now the web, Android, and iOS. And these mobile apps aren't just stupid WebView wrappers, Delphi will actually compile native code against the Android NDK, and the apps will be entirely native, creating a much better overall user experience. Delphi can not only provide performance in desktop apps, but also now in mobile apps, which is nothing short than amazing.
Pascal Compiles Too Fast
Dislike those ultra long compile times? Well, one of the original selling points of Borland's Turbo Pascal line back in the 80s and 90s, which continued to the Delphi was the incredibly fast compile times. This is still very true with the modern FreePascal and Delphi compilers. Not only does it compile fast, but these compilers also produce very compact native code binaries which also execute fast! It is incredibly sad that ObjectPascal is always overlooked despite some of it's advantages.
Memory Management in Pascal
Something that nobody ever seems to really talk about is how memory is managed in the Pascal language. Since Pascal has it's own runtime, separate from the C runtime library, it also has it's own memory manager. There is also the ability to effortlessly plug in your own memory manager by creating a new object class, and pointing Pascal to it. As you might have expected, there is actually a Pascal unit which can be easily added to your project which will have your Pascal programs use the C memory manager instead, the unit is called cmem, and as a result, it will then link against the C runtime libraries itself, and call the standard malloc functions, among all the others to transparently manage memory through C instead of using Pascal's built-in one.
One really interesting aspect about Pascal memory management, especially with modern Object Pascal, which even existed back in the first Delphi release, was the concept of automatic memory management, which is usually only available through interpreted languages with garbage collectors. In Object Pascal, it is entirely the developer's choice if they want to manage some memory themselves, or let the Pascal runtime handle those details for them. You can enable any class you create yourself this magic ability, but it's not really magic, and I'll briefly explain how it works. Here is how memory can be managed manually in Pascal:
type PMyStruct = ^TMyStruct; TMyStruct = record title: string[60]; desc: string; end;var mydata: PMyStruct;begin New(mydata); with mydata^ do try title:='A Title'; desc:='Some description Text'; finally Dispose(mydata) end;end;
This is by far a very crude example, but displays manual memory management, you as the developer need to keep track of this memory you manually allocated through this pointer, and make sure you free it after you are done using it. To turn this into a auto memory managed program, it could be written as such, again a very crude example:
type TMyComponent = class(TComponent) public title: string[60]; desc: string; end;var Application: TApplication; // Usually created behind the scenes during project creation for most project types. MyData: TMyComponent;begin MyData:=TMyComponent(Application); // Sets the owner of your new class instance to the Application itself. with MyData do title:='Fancy Title'; desc:='Some description'; end; // More code and logic. Application.Free; // Usually called behind the scenes in most project types, will free all it's children components.end;
With components in Object Pascal, you set a class instance which will own your component, this can be the Application instance itself, or another component in your application which depends on the component you are creating. Once that parent component is freed by Object Pascal, either by the development, or behind the scenes because of a user interaction like closing a window, or navigating to a different part of the application, each sub-component which it owns will also be freed. Once you understand the actual mechanics of how this sort of memory management works, it's really easy to create really complex applications with a lot of custom components that are all managed by the runtime itself. Furthermore, if you need to perform certain duties before your component instance is freed, there is a method you can override which can perform various actions, such as freeing any manually managed memory that this component may have allocated itself for whatever reason. This makes memory management much easier to manage, and puts direct control with the developer, on if they want to manually manage a piece of critical memory themselves through the application's lifecycle, or have the runtime manage it for them.
Procedural, Modular, and Object-Oriented
Why choose just a single programming paradigm, when you can have them all, and choose which one works best for a given problem? A very little talked about language feature of Object Pascal is that you don't need to choose how to program, you just need to know which paradigm is the best solution for any given problem you need to solve. Some other languages also support this, so it's not entirely new, or a concept that's unheard of in other programming languages. I thought it would be nice to note here however regardless, as I feel this is a good developer choice to have.
One of Object Pascal's greatest architectural strengths is its uncompromised multi-paradigm design. It does not force you into a single way of thinking. Instead, it seamlessly blends procedural logic, strict modular boundaries, and robust object-oriented programming (OOP) into a single source file.
While many developers assume this flexibility belongs only to interpreted scripting languages like Python, Object Pascal achieves this as a fully compiled, high-performance language. When you look at the broader landscape of popular compiled languages, you quickly see how unique and elegant Pascal's approach truly is:
- Java and C# (The Strict OOP Dictators): These languages force you to use classes for everything. In Java or C#, you cannot simply write a standalone utility function; it must be wrapped inside a class structure, even if it is just a "static helper" class. Object Pascal frees you from this boilerplate by letting functions exist natively outside of classes.
- C++ (The Powerful but Messy Overlord): Like Object Pascal, C++ natively supports procedural, modular, and OOP styles. However, C++ historically relied on fragile, text-inclusion header files to manage modules, which can lead to messy dependencies. While modern C++ has introduced an official module system, Object Pascal has offered clean, native, and safely isolated "Units" since its inception.
- Rust (The Modern Challenger): Rust is incredibly powerful and handles modular programming beautifully. However, it completely rejects traditional class-based inheritance and polymorphism, opting instead for data structs and traits. Object Pascal offers a more familiar, traditional OOP model with clear visibility inheritance that many developers find more intuitive for rapid application development.
By retaining its clean procedural roots, enforcing strict file-based modules via Units, and layering a modern object-oriented model on top, Object Pascal gives developers a rare power: the ability to choose the exact right tool for the job, minute by minute, without the language getting in the way.
Incredibly Structured
Some to shame Pascal for being too overly structured, but I see it as a good thing, as it enforces a very strict structure on each and every program and unit created in the language, making it very predictable on locating the information you need is without having to jump between multiple sections of the same file, or around to multiple files. Each unit file in Pascal is required to have a strictly defined interface section, and then an implementation section. The modern Pascal IDEs like Lazarus and Delphi can manage this entirely for you with no additional effort, just add your classes or methods into the interface section, then ask the IDE to generate all the implementation parts automatically. It's really quick and painless. This also makes it very clear to any developer who might be using your unit in their own programs which classes, methods, constants, and even variables are available to them for use in their own unit or program. Furthermore, if the implementation details are not licensed to be disclosed, then a simple copy and paste of the interface section is all that is needed to be provided to any third-party developers. Borland did this back in the day with their own units which didn't ship with their source code, instead the developers were just given an exact copy of the interface section.
One of the downsides in a way some might argue is the use of begin and end keywords instead of { and }, but if you are looking at source code all day, it can actually be easier to locate a begin and end, over a lot of nested brackets... So, this is more of a preference than anything, or merely a hallow complain as to only takes jabs at a programming language nobody seems to truly understand.
Personal Use-cases
Now that all of that is out there, let me explain why I will still continue using Object Pascal, and where exactly I will be incorporating it. Firstly, I most likely won't be using it in a workplace, and will instead opt for other more known solutions such as Python for similar tasks.
For my personal and hobby projects, here is where I'll continue using it:
- Building Desktop Applications: This is where both Delphi and Lazarus really thrive. They have a great IDE, a nice set of components, and it's really trivial to develop additional components, visual or not. Developing Desktop Applications in Python is a pain, and difficult to port and get running on other platform, and on top of that, Python ships with a large runtime. In contrast, a Desktop Application build in Object Pascal is a small native binary with very little external dependencies, making it ideal for this use-case.
- Building Local Daemons and Console Programs: The added security of a compiled program when developing system-level daemons is a nice feature. It means that the program is much more resistant to external tampering than say if I built a system-level daemon in Python.
- Single Page Applications: I haven't took the time to learn React yet, but might one day, I just don't like how overly complex the build environment and build processes are for it. But pas2js works really well as a web application framework, while retaining all of the advantages I mentioned about the Object Pascal language.
Where Pascal isn't Great
When it comes to server-side web application development, this is where it seems that Object Pascal isn't the best at, as it's not quite as mature as the competitors, at least with the server-side offering within the free software community. I'm not sure how well Delphi has solved this problem, but from what I've read, Delphi actually has some rather impressive technology in this department.
This is where this post will soon some to an end, as it is the final explanation and a natural conclusion to why my website is now powered once again by Python. Python has been tested in the field, and has a lot of very mature server-side web frameworks. Furthermore, with it's dedicated WSGI server technology, it allows Python server-side web applications to easily scale in production environments.
Probably the most promising server-side web project on the Object Pascal front is the REST API Server, which can effortlessly expose an entire database, along with having strict business logic to ensure that data is accessed properly. This is one part which I will be keeping a keen eye on with Object Pascal, as we move more towards single page applications using front-end development like React, a good stable, and scalable back-end will always be needed.
