Why Pascal is a good language

I recently stepped back into doing a bit of programming in Pascal, the first language I learned. What I realized is that Pascal is an inherently learnable language. Why? Because the novice programmer can get a feeling of what’s happening in a program, just by looking at it. There is a easier learning curve, because for the most part, the novice programmer is able to transfer knowledge they already have to the programming realm. Take for example the following Pascal program which calculates a factorial, n!:

program factorial;
var i, n, fact : integer;
    writeln('Enter a number: ');
    fact := 1;
    for i := 2 to n do
        fact := fact * i;
    write(n,'! = ', fact);

It is easy to look at the program, and get a sense of what is happening, despite the fact that it has no comments. Firstly, it tells you it’s a program, which is always nice, and it gives the program a name. Then it uses the keyword var to denote that the variables are to be created. It the creates i, n, and fact as integers. It’s nice that it uses the full word, integer, as the programmer, doesn’t have to worry that they have the right abbreviation. Pascal deals with four basic data types: integer, real, char and boolean, although the latest implementations have added extended data types.

Next it uses the delimiters begin and end to define the “programming block”, where the action will occur. This is seemingly better than the non-descriptive use of { and } in C. Input and output are provided by the read/write pair. Assignment turns the clock back to a time when := was used for assignment, which isn’t such a bad idea, leaving = for equality, thereby reducing the confusion created by the =/== pair. Even the for loop tells you straight away that i has a value from 2 to n, with an assumed increment of 1. All-in-all a much more readable program, and language.

So what makes Pascal a good language?

  • It is a very clean language, with a natural English language-type syntax.
  • Arrays aren’t limited to being indexed from 0, which can be useful for implementing some algorithms.
  • Pascal has a data structure called sets, which allow you to do really nice things.

Many will argue that Pascal was only ever an educational language. There is no doubt that is true, but what’s wrong with that? Learning to program means learning the structures needed to implement an algorithm, for example a loop. It doesn’t really matter what language is used, but a more usable language for novice programmers is obviously better. People would better understand programming concepts with a simple language.



One thought on “Why Pascal is a good language

  1. codeinfig says:

    n := (“Enter a number: “); prints; lineinput; int
    fact := 1;

    for i := 2, n, 1
    now := fact times i; swap now, fact

    write n; str; plus “! = “; prints
    write fact; prints

    # except for the for/next block, all leftmost tokens are variable names (and zero when they 1) start a line and 2) do not contain an array.)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s