J-F Bilodeau's Blog @ chronogears.com

Wednesday, March 19, 2008

Why I (Still) Love the Pascal Programming Language

Day-to-day, I use Java, C++, Python and a host of other programming languages. I like my modern programming languages. However, my first programming language love refuses to die -- Pascal.

Pascal is not a perfect language. For that matter, there are no perfect language. However, some languages can arguably be said to be better than others. This said, I will readily accept that Pascal has important flaws, which I will discuss later. However, here are the reason why I like Pascal, and why I think you should give it a spin:

Available on Most Platform
The Free Pascal and GNU Pascal compiler is available for most platforms, including most *NIX, Macs and Windows. Heck, you can even write code for the GameBoy DS! Furthermore, the code is usually portable with minimal or no changes.
The Free Pascal motto is 'Write Once, Compile Anywhere.'

Compiled
It's not interpreted. It doesn't use bytecode or IL. It's compiled straight to machine code. Thus, your Pascal applications can run as fast as any C application.

Lightning Fast Compiler
That's one cool thing about (most) Pascal compilers I've used. It's blazingly fast. This greatly reduces the write-compile-debug cycle.

Still Active
Though far from being as popular as C or Java, there is still strong support for the language. I don't think we can consider it a 'dead' language yet.

Structured
I think many people may disagree with me, but I like Pascal's strict structure. It forces me to think my code through a bit before I hack away. Also, once the code is written, I find it's usually very readable. Nicely written Pascal code can be close to English.

Native Data Structure
Arrays and numbers with any lower and upper bounds, sets and enumeration native to the language make Pascal a lot of fun to play with. You don't even has a set data structure in .NET 2.0!

Pascal also has a fairly complete collection of basic data types, and they're all first-class citizens. In other words, they are not classes that implement the functionality. Thus, they can be optimized by the compiler.

Multiple Paradigm
Pascal supports procedural programming and object-oriented programming, and the two can coexists peacefully.

LCL
Though not a standard part of Pascal, the LCL (Lazarus Component Library) is strongly supported by the Free Pascal community. It's a wonderful way of building GUI application and is available of all major platforms (Linux (GTK2, QT), Mac OS X & Windows)

As I mentionned above, Pascal is not perfect. The language was created in 1970 and was originally designed to encourage structured programming (no gotos).

Here are some of the things I would like to see improved in modern Pascal:

Precedence of Operators
Pascal has only four level of precedence of operators, which makes writing some conditional statements (and, or, etc) ackward. Brackets can be used, but they can also make the code more difficult to read.

Garbage Collection
The memory management is Pascal is up to the programmer. Being a C++ developer, I like manual memory management is some context. However, being also a Java developer, I would like to take advantage of automatic garbage collection. It would be nice if I could choose the memory management strategy for my application.

Templates / Generics
C++, Java and .NET supports Generics. They can same a lot of dynamic casting while making your application type-safe. By eliminating dynamic typecast, the execution speed can be improved.

I would love to have a generic TList or TMap.

True Platform Independent VCL
The VCL (Visual Component Library) was born out of Delphi -- a beautiful competitor to Visual Basic that never enjoyed the success it deserved. The VCL was created on Windows for Windows and during a very short time, ported to Linux.

The Lazarus project recreated (and expanded) most of the VCL called the LCL (Lazarus Component Library, but aimed to retain compatibility with the VCL. This is great if one is developing on Windows, but makes it ackward on other platform like Gtk2 (Gnome), QT (KDE) or Carbon (Mac OS X). This is due to the fact that the (V|L)CL refers to Windows API and constants by name. A layer of abstraction between the LCL and the underlying system would make the code look native on any platform.

Furthermore, having dynamic layouts like Java that adapt themselves automatically to the platform would be almost essential.

Object Oriented Version of String, Array, Set, Enumeration, etc...
Using strings or array remains procedural. I would love to have a compatible but object-oriented version of the build-in data types (I know that seems to contradict one of my points above, but they could remains 'compiler' classes). A simple solution would be to make a string class, and recreate the string functions to call the method on the string class, thus preserving backwards compatibility.

Pascal has survived nearly 40 years mostly unchanged. There has been refinements, additions and extensions added to the language. However, a Pascal program written 30 years ago may still compile in a modern Pascal compiler.

Though nowhere near as popular as C/C++, Java or .Net, I think that Pascal has a lot to offer. If you've never used Pascal before, consider downloading Lazarus to help you get started. There are plenty of great Pascal tutorial available on the web.

Happy coding!

Labels: , , ,

1 Comments:

  • Programming tends to be a very abstract, open-ended activity. A very specialized language is used to communicate with a machine that understands a very limited, but powerful, mathematical model (i.e. ones and zeros). These machines have their own language, one that does not translate well into verbal or human terms.

    By Anonymous chicago information technology master degree, At February 9, 2010 1:50 PM  

Post a Comment



Links to this post:

Create a Link

<< Home