Pascal a programming language , its history and some example code.

Pascal Programming Language

Pascal Programming Language

Pascal is just one of many programming languages that you can select in order to learn programming skills and then for developing professional applications.

This Wiki page details much about the language of Pascal , Pascal was named in honour of the French mathematician and philosopher Blaise Pascal, it was developed by Niklaus Wirth, who had previously helped with the development a language called ALGOL. You can check out the full details on the link.

I have had a long involvement with Pascal and still love coding in it today, it has had a long development path moving from a structural languages into object orientated coding methods. Today you can program in pascal using visual aids such a Delphi or/and Lazarus, programming interfaces that allow you to design an application starting from the screens that you will present to the user of your finished application, I will post on these methods of coding in the future.

I personally like Pascal a lot, one of the main reasons is that it is a very highly structures and direct language, both to code with and also read through in order to make later changes. Finding coding bugs long forgotten about and maybe only just discovered is helped very much when the language used is very clear in its syntax.

Pascal was developed in the same era as c/C++ and uses much of the same methods , such as external libraries of predefined code ( Units in Pascal, Libs in c++ ).

Pascal more than c++ is a very clear and clean language with fully descriptive commands and statements , C++ is much more symbolic !


user input and output commands in c++ :

cout << “Enter the temperature in Celsius:”;
cin >> celsius;

user input and output in Pascal :

writeln('Enter the temperature in Celsius : ";

It’s not that c++ is impossible to read ,once you fully understand all its syntax its just that its not as easy !

When you have large programs to read through, it becomes much clearer as to why a less symbolic and a more linguistic language is easier to follow and to debug than a sometimes highly symbolic language like C++ .

Student(char *pName, int xfrHours, float xfrGPA)
cout << “constructing student “ << pName << endl;
strncpy(name, pName, MAXNAMESIZE);
name[MAXNAMESIZE - 1] = ‘\0’;
semesterHours = xfrHours;
gpa = xfrGPA;

The only down side to this, as far as a language like pascal is concerned is that you do have to use the keyboard much more when you are writing the actual code in the first place, with each command being written with a much longer form of syntax.

Example pascal code

Below I have uploaded a basic Pascal program , it is designed to request two numbers from the console in Linux or the command line in window and then tell the user which of the two numbers entered is the largest – Simple YES !!!

Simple right !! but you would be amazed just how often that these very simple routines are used in a application, e.g. for sorting large volumes of data or making basic decisions, most of the time computers do not do very interesting things , they just do them very quickly and very often!

Finding the larger of two Numbers

The following is an example of a free pascal program, it includes all the following lines,
I have included a full description in the program comments .

Program exFunction;

(* This program requests two numbers from the user and
   returns the highest of these two values    

    Nigel Borrington 2015     *)


(* Integer Variables =
*   firstnum , the first value entered by the user
*   secondnum , the second value entered by the user 
*   ret , the value used to contain the highest value returned from max

	firstnum, secondnum, ret : integer;
(* function definitions *)

(* Function 'max' tests for the highest of two numbers 
	 passed to it and returns the resulting highest value .			*)
function max(num1, num2: integer): integer;

	(* Local variable declaration *)

	result: integer;
	if (num1 &gt; num2) then
		result := num1
		result := num2;
	max := result;

(* Procedure definitions *)

(* Procedure getvalues prompts the user for two values
   and gets the values of 'a' and 'b' from the keyboard *) 

Procedure getvalues();

	writeln('Please enter your first value');
	writeln('Please enter your second value');

(** main program body **)

	firstnum := 0;
	secondnum := 0;
	(*call the function max to retrieve the maximum of the two values*)
		ret := max(firstnum, secondnum);
		writeln('The maximum value entered was : ', ret);

I intend to come back to this program and use it with other programming languages to show the basic differences between them all ……

In my next post I am going to return to the Pi-face digital devices, installed on the ‘raspberry pi 2’ credit card sized pc, and introduce the python language used to control the (Piface digital 2 i/o board and Piface CAD LCD screen ) …….

This entry was posted in Computer History, Development Languages, Pascal, Programming skills and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

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

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

Facebook photo

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

Connecting to %s