Hey boy! What you coding for? :: A Pascal odyssey

Amongst my many geeky pursuits, I love programming.
I don’t claim to be particularly good at it, but sitting down at a PC and creating a small program or piece of software is kinda liberating.
I was asked by a friend recently what I find so enjoyable about it, so thought that I’d answer it here.

I grew up around the time that 8-bit home computers were becoming popular. Everyone had a Spectrum or, in my case, a Commodore 64  hooked up to a cathode ray television. The games took 10 minutes to load and were pretty samey, shoot the aliens, rescue the princess etc, but over time games started to appear that were different and fun.
Revenge of the Mutant Camels, International Karate + and Paradroid, all drained my time and I started to notice that some of these games were mostly written by a single person. Names like Jeff Minter, Andrew Braybrook  and Rob Hubbard  kept cropping up and the realisation started to hit that you didn’t need a ‘software development team’ to create a game.
Most computer magazines at that time usually came with a cassette tape of game demos sellotaped to the front cover and a couple of pages of programming tutorials included inside.
My generation learned to code by typing out the BASIC programs listed in magazines, then playing around with the results (owning a computer back then, it was taken for granted that you would write your own software as well as buying it).

I re-jigged the code in the BBC Micros at school to make them spit out reams of dot-matrix printed paper and hacked together a game that ‘sorta’ played like Space Invaders, but that was all at that point.

Fast forward a couple of years and after leaving school I started a course in Pascal  programming. Using Turbo Pascal 5  , I learned about pseudo-code and structured, procedural programming. This was when I started hanging out with other ‘geeks’, C++ programmers and hackers who could make a 386 sing. I loved writing programs that entertained me and only me, and talking trash with people who could debate the finer points of Babylon 5 and pointer arrays with equal energy.

After leaving that course, for a while I got caught up in the whole Microsoft ecosystem of PC’s as business tools only. Consoles were for fun and computers were for spreadsheets and word processing. That’s how it remained until 2002 when, after hearing about this thing called GNU/Linux, I downloaded a copy of SuSE 8.0 and dove straight in.
Linux reminded me of why I got interested in computers in the first place, the whole GNU philosophy was about empowering people to use their computers for whatever the hell they wanted. The computer as the tool rather than the people who used them.

Around this time I picked up and played around with several programming languages but nothing really sparked my imagination in the same way that tapping away in a blue text-mode editor did.
Free Pascal IDE










I stopped programming for a few years, since I didn’t need to as part of my job and I had plenty of other hobbies and pursuits to keep me occupied.
Then one day I read that Embarcadero were freely giving away some of Borlands old software, including the Turbo Pascal version that I’d once used.

It inspired me to take a look how the language had progressed since then. Up until that time I’d assumed that the language had kinda faded away but Object Pascal was still being used under the hood of the Delphi IDE as well as being improved in Free Pascal and Lazarus.
Without realising it, I’d been using software written in Pascal every day.

Ubuntu Control Center
Kingsoft Office
PhpED from NuSphere
Fruity Loops-Digital Audio Workstation
Transmission Remote GUI
Age Of Wonders II
CoffeeCup HTML Editor
Morfik WebOS AppsBuilder

I downloaded a copy of Lazarus and, after following a few tutorials, I was able to create a simple text editor in only a few minutes. Just by dragging and dropping a few components onto a form and writing some simple commands (I’d apparently retained quite a bit of Pascal knowledge, somewhere in the darker, unused portions of my brain over the years.).
The syntax is simple, a basic example of a currency conversion program (one of the first things I always write in a new language… it’s kinda like my ‘Hello World’) looks like this:


program exchange1;

  rate = 5.6;

   amount, result : real;

  result := 0;
  write ('Enter amount in GBP £');
  read (amount);
  result := amount * rate;
  writeln ('Amount is ',result:4:2,'zł');

And that’s all it takes to convert an amount from British pounds to Polish złoty. If you want to go a step further and have the program get the latest exchange rates online so that the result is more accurate then:


{$mode objfpc}{$H+}

uses fphttpclient, fpjson, jsonparser;

  S : String;
  J: TJSONData;
  initialAmount, endAmount, rate: real;

  With TFPHttpClient.Create(Nil) do
    J:= GetJSON(S);
    rate := J.FindPath('rates.PLN').AsFloat;
    writeln ('Current exchange rate of GBP to Polish złoty: ',rate:2:2);
    write ('Enter initial amount in GBP £');
    readln (initialAmount);
    endAmount := initialAmount * rate;
    writeln ('Is equal to zł',endAmount:2:2);    

It’s only slightly longer and maybe not as easy to read at first glance, although that’s mainly due to the exchange rates being in the JSON format.

Now, most people that I know use their PC to access Facebook or to watch YouTube videos and that’s pretty much it. Computer code looks so arcane that they think that they ‘don’t have the right kind of brain’ to be able to understand it, or they just don’t see any reason to learn it.
It’s a great feeling though, to write a few lines of code and create something that didn’t exist before.

There’s the challenge of learning something new together with having a piece of software at the end of it that you created.
I seriously recommend taking the time to learn a little about coding, whether it’s Javascript and PHP for web development or Scratch so that you can sit down with your kids and make a simple animation or game.

The next time that you’re using a program and think ‘It would be so much easier if it did things this way’, consider making those changes yourself and submitting them back to the community.

So why do I enjoy it?
Because it’s fun, creative and there are no limits to what you can come up with.

….some days

2 states of every programmer