Yup, it’s one of those posts again. Somehow I just can’t stop advocating programming languages that are, let’s say, underrepresented in today’s professional environment. This time, it’s Pascal (cue melodramatic shuddering in the audience). No, not the Pascal you’ve learnt at school, but modern dialects such as the ones implemented in FreePascal.
It’s an interesting language. Simple yet powerful. A basic comparison with C makes it look like just the same thing, just with different syntax and names. All the usual suspects are there: Basic data types, if/then/else, loops (for, while, repeat/until), pointers, arrays, structures (records). Just that you use a different assignment operator and “begin”/”end” instead of curlies. Then you compile to native code, use a debugger, a profiler and whatnot to tune your program. Same old, eh?
But there are bigger differences, of course (why else would I bother writing about it?). Strings, for example. You get a full Unicode string datatype, with reference counting so you don’t have to take care of releasing memory yourself. Somewhat like C++ strings, but with readable error messages if you screw up. And Pascal’s unit concept is so much better than C/C++ header files. One logical block of code, one file. No screwing around with pragmas and header protection. Files are much more readable.
The screaming I hear in the background must be the C guys calling Pascal an abomination. Sure, you have to do more typing. Sure, variables have to be declared at the beginning of a procedure instead of inline at the site of first use. The horror. Heads up: Making your procedures small enough for that not to matter is good code style anyway. Oh, and typing “begin” and “end” is sooooo much more work than pressing two keys. But guess what: Once you write a slightly longer piece of code, this just stops being relevant. It’s more the hassle of using a syntax you’re not accustomed to than a real problem. Source code is read way more often than written anyway. Man up and learn more than one programming language.
OK, so we have nice Unicode strings and a better code unit concept. What else do we get? Damn fast compilation. Classes with all the standard OO style goodies. Sure, it’s not really object oriented, but neither are C++, Java and C#. Real OOP in the original sense is something only provided by Smalltalk and Common Lisp anyway. And Erlang, with some artistic freedom. But FreePascal at least provides classes with virtual methods, interfaces, generics, RAII (!) and the freedom to decide when to use OOP and when to just stick to classic structured programming. No more Java/C# style “everything has to be inside a class hurr durr”. I like.
And the kicker: Lazarus. A free Delphi like environment, a giant standard library, great tools and portability between the three big ones (Windows, Linux, Mac OS). What’s not to like?
Yeah, what do we miss? A real standard, for one. As with Perl (and many other languages), the main implementation is the standard. Portability is not that great, either; you can’t just run your code on a microcontroller with FreePascal the way you can with the dozens of C compilers. But to be fair, when I look at the microcontroller C compilers of today, with all their deviations from the standard, the portability issues, all the bugs still present in 2014, no matter that the compiler still only supports a (large) subset of C89… argh. There is not a single compiler I’m really, truly happy with. Still, C is omnipresent, FreePascal is not.
But don’t think C and C++ are the only languages that translate to assembly in a more or less straightforward way. Hell, with the FreeBasic compiler, even Basic has evolved into something to be taken seriously now.