Object Pascal for Raspberry PI
Recently I visited the Raspberry PI community on Facebook. A great group with many exciting DIY projects of all shapes and sizes. Personally I have bought two Raspberry PI (short: RPI) for various purposes; first of all retro gaming through MAME, and secondly more serious stuff like ownCloud and a private build server for freepascal.
And this is what I want to present to the Raspberry PI community, because the moment I began to talk about pascal – I was met with a near hostile attitude. Both on the official Raspberry PI forum as well as the community driven Facebook group. I found it baffling that someone could get upset, or use hostile language towards someone, over a programming language. I use many languages, including scripting engines, they are all part of my toolbox. But the language I use the most is object pascal, because it’s quite frankly so much better than the alternatives. It is so productive, easy to use and powerful that I almost dont know where to begin.
To Quote Linux Journal:
Lazarus may be the most native cross-platform development environment
running on Linux, Windows and Mac OS X. -Source: Linux Journal
It is such a shame that so many young programmers have been completely hoodwinked by hype and marketing, that they actually believe that a scripting engine such as python, or a bytecode virtual machine like Java, can even be compared to Object Pascal or C/C++. Python and Perl have their uses in the IT landscape and are brilliant dispatch and processing languages, but they are just scripting engines, written in a language which paradoxically is not python or pearl. Which is just one of the ironies we face when discussing what the nature of a “real” programming language is (one of the base criteria is being able to compile itself once the bootstrap is written for a particular platform). Many of these teenage programmers quite frankly don’t understand the distinction and really believe that python is en-par with C++ or object pascal. I’m sorry to burst your bubble, but compared to C++ or Object Pascal — python is nothing but a toy.
I have coded my own scripting engines (quite a few actually), so I know perfectly well how much work is involved. Writing a script engine or a compiler is probably one of the most technically challenging topics you can visit; but at the end of the day none of these systems can compare to a real language; neither in depth, technical excellence, dependencies, ease of distribution, speed or possibilities.
And in the case of Object Pascal, the language is no harder to use than python, so the argument of complexity and time-to-market is null and void.
Object Pascal? But isn’t that old and outdated?
Absolutely not. It’s younger than C/C++ and is in constant development, just like C++. In fact, on the Windows platform C++ builder and Delphi are companion products which are binary compatible, meaning that you can share compiled code between them. This is also scheduled for OS X and (in a couple of years) Linux. But freepascal which is the open-source, free alternative to Delphi, have been on these platforms for a long time already.
What you will find if you take the time to investigate Object Pascal, is a well thought-out language which has withstood the test of time, based on a rock-solid software patterns and built around an architecture which is scalable, agile and extremely productive. It is used by millions of individuals around the world on a daily basis, both large and small companies (including several fortune 500 companies) and has a history of delivering stable and robust software.
Skype, Nero Burning Rom, Help and Manual, Dark Basic, Jotta Backup — these are just some of the well known applications out there that are all written in object pascal. So the argument that one guy cam up with, which was “I have never used a single Delphi program ever” is as null and void as the time-to-market rubbish. If you havent tried Skype, or for some reason believe it’s of lesser quality – then you should get your head checked.
Let’s have a look at what object pascal can do for Raspberry PI by establishing a couple of facts.
Raspberry PI is not a power-house of processing power. It has a low-end ARM CPU which, if over-clocked (forced to run faster than it was designed for), delivers roughly the same power as the now 15 year old Pentium III. This means that if you hope to use the Raspberry for anything useful, especially if your target audience are young teenagers or kids eager to learn how to program — you want to chose a language which has the following qualities:
- Runs fast, a Pentium III needs all the help it can get
- The less dependencies (libraries) the better
- Is platform independent
- Scalable learning curve
- Support for modern constructs, like generics
- Has plenty of examples, books, websites and videos going for it
- Costs little or nothing
- Provides good income when mastered
In other words, if you want to build applications which executes extremely fast, even faster than C/C++ in some cases, then you could not find a better language for the Raspberry PI than object pascal. The reason for this choice is again backed by facts, not preference:
- Object Pascal was taught in european schools as late as 2005
Object Pascal was made with teaching in mind
- Object Pascal was designed to replace C/C++ and is more mature
- Object Pascal is much easier to master than C/C++
- Object Pascal code runs en-par with C/C++ but often surpasses it in terms of speed
- The generated executable code is highly optimized
- The generated executable has no dependencies. Everything is compiled to a single binary
- Full support for external libraries (and also packages)
- The compiler supports every chipset and operating system on the market (and then some)
- Both compiler and source RTL is well maintained and up-to-date (VCL, LCL, VJL, FMX)
- Object Pascal has a thriving community with millions of users
- There is a proverbial ocean of examples, components and frameworks available
- Object Pascal supports inline assembler
- Pascal has delivered commercial applications for 20+ years
- Pascal has produced brilliant software engineers for 20+ years
- Delphi programmers are in high demand!
So the reality of it all is, that if someone wanted to create a processing language like python, they would pick a real language to implement it, like C/C++ or object pascal. This is a fundamental difference which is extremely important to understand: Namely that a real language, one which is compiled into executable machine code, cannot be compared to an interpreted script language. It’s like comparing a bicycle to a racing car. It’s two completely different worlds. For instance, how many python compilers have you found that was written in python? Or how many python or pearl runtime environments have you used which surpasses the speed and technical advantages of C++ or Object Pascal? It is a fact, that native executable code will always be faster than interpreted AST (abstract symbol tree) execution, even when JIT technology is involved.
There are far to many resources for learning object pascal than can be listed on this website (let alone this article), but if you are interested in having a look, i have provided you with a handful of links below:
- The Lazarus / freepascal IDE and compiler suite (free)
- Embarcadero Delphi, the commerical object pascal suite
- Delphi Basics – Learn object pascal
- Delphi feeds
- Torry’s Delphi Pages
- Developer Express VCL Components
- TMS software
If you visit Google Code or SourceForge, search for “Delphi” or “FPC” (freepascal) you will find thousands of big and small projects ready for Download. Everything from operative systems coded from scratch in freepascal or large scale web services to handle thousands of connections, database servers written in Delphi, database engines, games, multimedia — the works.
Oh, and the Raspberry PI disk-image writer for OS X was written in freepascal, you can download that here (much easier than the guide on the official website).
If you are serious about programming, especially on embedded systems, then object pascal is probably the best choice you can make. It’s easier to learn than C/C++, has all the features of C/C++ (with the exception of multiple ancestors. Object Pascal enforces linear inheritance to avoid ambiguity in the VMT [virtual method table] should identical members collide, which is the problem of multiple ancestors for a class), has no dependencies (so your programs dont need a second library file to run), is highly optimized, scales from low-level procedural or assembly-language programming – to high level object orientation; the list goes on.
To install on the PI, simply open terminal and type:
- sudo apt-get install fpc
- sudo apt-get install lazarus
As for platform support, you have a lot to choose from. FreePascal provides the following:
- OS X (Intel, PPC)
- Classic Mac OS PPC
- Spark Solaris
- Amiga (68k, PPC)
- Aros (intel)
- MorphOS (PPC)
- iOS (ARM)
- Android (ARM)
- Raspberry PI
- Nintendo DS
- Nintendo Wii
- .. and more
Happy Raspberry PI coding!