Difference between revisions of "Why use Pascal"

From Free Pascal wiki
Jump to navigationJump to search
m (Text replacement - "Object Pascal Introduction" to "Basic Pascal Introduction")
(bypass redirect Basic Pascal Introduction → Basic Pascal Tutorial/Introduction, fix a spelling mistake “informations” → “information”, expand contractions, fix typos, partially undo revision 020B43 by Trev, update external links, resolve Category: Pages using deprecated enclose attributes)
Line 2: Line 2:
  
 
== Introduction ==
 
== Introduction ==
 
 
Pascal often comes under attack as a language which should be dead, or as a language not suitable for very much.
 
Pascal often comes under attack as a language which should be dead, or as a language not suitable for very much.
  
This document will discuss these claims and add the latest informations about Pascal as of 2013 and beyond.
+
This document will discuss these claims and add the latest information about Pascal as of 2013 and beyond.
  
 
=== What is Pascal? ===
 
=== What is Pascal? ===
 
 
[[Pascal]] is a very clean programming language, which looks more like real languages in the sense that it uses real English words as keywords rather than random ASCII characters.
 
[[Pascal]] is a very clean programming language, which looks more like real languages in the sense that it uses real English words as keywords rather than random ASCII characters.
This is important in understanding existing code as well as debugging because people don't read individual characters but whole words.
+
This is important in understanding existing code as well as debugging because people do not read individual characters but whole words.
  
 
A common misconception is that Pascal started as a teaching language.
 
A common misconception is that Pascal started as a teaching language.
 
While this is partially true, the associations are usually wrong; usually that makes people expect systems like Logo, limited playing grounds for children.
 
While this is partially true, the associations are usually wrong; usually that makes people expect systems like Logo, limited playing grounds for children.
  
Pascal, like its predecessor ALGOL(-60), however was primarily designed as a language for formal specification and teaching of algorithms, mostly with future engineers and computer scientists as target.
+
Pascal, like its predecessor ALGOL(‑60), however was primarily designed as a language for formal specification and teaching of algorithms, mostly with future engineers and computer scientists as target.
Contrary to ALGOL-68, emphasis was put on simplicity.
+
Contrary to ALGOL‑68, emphasis was put on simplicity.
This turned out to be beneficial for compiler construction.  
+
This turned out to be beneficial for compiler construction.
  
 
The initial Pascal dialects had a series of serious ugliness (like untyped procedure variables) that were quickly remedied, way before the language's prime time in the eighties (revised J&W and early standardization trajectory).
 
The initial Pascal dialects had a series of serious ugliness (like untyped procedure variables) that were quickly remedied, way before the language's prime time in the eighties (revised J&W and early standardization trajectory).
  
 
Further modernization and facilities for interfacing to lower level systems were added to nearly every dialect.
 
Further modernization and facilities for interfacing to lower level systems were added to nearly every dialect.
Most of these  weren't standardized back into the language, but this was normal at the time (way before C and POSIX standards).
+
Most of these  were not standardized back into the language, but this was normal at the time (way before C and POSIX standards).
 
However the dialects were not entirely random, and could be classified into two major streams, UCSD/Borland like and ISO standards compliant, with Apple creating a hybrid between the two (UCSD in origin, but incorporating most level 1 ISO features).
 
However the dialects were not entirely random, and could be classified into two major streams, UCSD/Borland like and ISO standards compliant, with Apple creating a hybrid between the two (UCSD in origin, but incorporating most level 1 ISO features).
  
Line 32: Line 30:
  
 
=== The Readln and Writeln effect ===
 
=== The Readln and Writeln effect ===
 
 
Most developers that touched Pascal did not like the language, because they only learned some very basic commands and how to write a more structured code than their mind was thinking at the time.
 
Most developers that touched Pascal did not like the language, because they only learned some very basic commands and how to write a more structured code than their mind was thinking at the time.
  
Line 41: Line 38:
  
 
== Pros and Cons ==
 
== Pros and Cons ==
 
+
As always: Choosing what programming language to use depends on your program you would like to program.
As always: Choosing what programming language to use depends on your program you'd like to program.
 
  
 
=== Pros ===
 
=== Pros ===
 
 
==== Object oriented programming ====
 
==== Object oriented programming ====
 
+
You want Object Oriented Programming (OOP)? There you got OOP: FPC supports it: see [[Basic Pascal Tutorial/Introduction|Tutorial]].
You want Object Oriented Programming (OOP)? There you got OOP: FPC supports it: see [[Basic Pascal Introduction|Tutorial]].
 
 
In the meantime, generics (templates, usually for classes) became possible, too, though generics can be used for a wide variety of other types as well.
 
In the meantime, generics (templates, usually for classes) became possible, too, though generics can be used for a wide variety of other types as well.
  
 
==== Real assignment operator ====
 
==== Real assignment operator ====
 
 
Other languages: mathematically wrong (there are two equations):
 
Other languages: mathematically wrong (there are two equations):
 
 
<syntaxhighlight lang="C">
 
<syntaxhighlight lang="C">
 
x = 42;
 
x = 42;
 
x = 3 * 3;
 
x = 3 * 3;
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
Or even worse (<syntaxhighlight lang="C" inline>x</syntaxhighlight> on both sides):
Or even worse (<syntaxhighlight lang="C" enclose="none">x</syntaxhighlight> on both sides):
 
 
 
 
<syntaxhighlight lang="C">
 
<syntaxhighlight lang="C">
 
x = 3 * x - 1;
 
x = 3 * x - 1;
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
So, <syntaxhighlight lang="C" inline>x = 0.5</syntaxhighlight> or what (the f***)?
So, <syntaxhighlight lang="C" enclose="none">x = 0.5</syntaxhighlight> or what (the f***)?
 
  
 
Pascal does it right (there are two consecutive definitions):
 
Pascal does it right (there are two consecutive definitions):
 
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
 
x := 42;
 
x := 42;
Line 76: Line 64:
  
 
==== Strong type safety ====
 
==== Strong type safety ====
 
 
In C you can add a character to a real and interpret it as a boolean (or whatsoever).
 
In C you can add a character to a real and interpret it as a boolean (or whatsoever).
 
Why the heck should I do this?
 
Why the heck should I do this?
Line 83: Line 70:
  
 
==== Well structured ====
 
==== Well structured ====
 
 
For example a function in C look like this:
 
For example a function in C look like this:
 
 
# function signature
 
# function signature
 
# declaration of variables … and definition of function may be mixed up
 
# declaration of variables … and definition of function may be mixed up
  
 
In Pascal it is clear:
 
In Pascal it is clear:
 
 
# function/procedure signature
 
# function/procedure signature
 
# declaration of variables …
 
# declaration of variables …
Line 96: Line 80:
  
 
==== Case-insensitive ====
 
==== Case-insensitive ====
 
 
A function defined with the name getLimit will be called though you forgot the upper-case-L in the middle ( (calling getlimit()). It does not raise a compile-time-error.
 
A function defined with the name getLimit will be called though you forgot the upper-case-L in the middle ( (calling getlimit()). It does not raise a compile-time-error.
  
 
==== Principle of scope ====
 
==== Principle of scope ====
 
+
There are many chances to limit the validity of [[Identifier|identifiers]] – to limit their scope.
There are many chances to limit the validity of identifiers – to limit their scope.
+
Encapsulating functions/procedures or limiting a variable’s/constant’s/type’s scope is done implicitly: Depending where you declare such things, they are only known on the same or lower levels.
Encapsulating functions/procedures or limiting a variable's/constant's/type's scope is done implicitly: Depending where you declare such things, they are only known on the same or lower levels.
 
  
 
==== Readability ====
 
==== Readability ====
 
 
You can write Pascal as you speak (or at least it is some more natural):
 
You can write Pascal as you speak (or at least it is some more natural):
 
+
<syntaxhighlight lang="pascal">
<syntaxhighlight lang=pascal>
 
 
if x equals true then
 
if x equals true then
 
begin
 
begin
writeline, left round bracket, apostroph, hello world, apostroph, right round bracket, semicolon
+
writeline, left round bracket, apostrophe, hello world, apostrophe, right round bracket, semicolon
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
Counter example:
 
Counter example:
 
 
  if, left round bracket, x equal equal true, right round bracket
 
  if, left round bracket, x equal equal true, right round bracket
 
  left curly brace
 
  left curly brace
Line 123: Line 102:
 
  right curly brace
 
  right curly brace
  
The counter example shows that you may get lost if you don't know what brackets and braces mean.
+
The counter example shows that you may get lost if you do not know what brackets and braces mean.
Indeed, it's a weak pro-point.
+
Indeed, it is a weak pro-point.
  
 
==== Native set operators ====
 
==== Native set operators ====
 
 
Since Mr. Wirth (the father of the Pascal language) has a background in mathematics, where [[Set|sets]] (containers of units called “elements”) are a fundamental tool, he included operators for handling with sets, too.
 
Since Mr. Wirth (the father of the Pascal language) has a background in mathematics, where [[Set|sets]] (containers of units called “elements”) are a fundamental tool, he included operators for handling with sets, too.
We can check, whether an element is in a set via the <tt>in</tt> operator.
+
We can check, whether an element is in a set via the [[In|<syntaxhighlight lang="pascal" inline>in</syntaxhighlight> operator]].
We can <tt>include</tt>, <tt>exclude</tt> elements, compare sets (difference, symmetric difference), combine and intersect them.
+
We can <syntaxhighlight lang="delphi" inline>include</syntaxhighlight>, <syntaxhighlight lang="delphi" inline>exclude</syntaxhighlight> elements, compare sets (difference, [[symmetric difference]]), combine and intersect them.
 
Knowing where to use sets, makes your code incredibly more readable!
 
Knowing where to use sets, makes your code incredibly more readable!
There's no need to include any extra class or unit for that, it's already part of the language.
+
There is no need to include any extra class or unit for that, it is already part of the language.
However, FPC's current implementation of sets allows 256 elements top per set.
+
However, [[FPC]]’s current implementation of sets allows 256 elements top per set.
You can't do mathematics in a large scale with that, though.
+
You cannot do mathematics in a large scale with that, though.
  
 
=== Cons ===
 
=== Cons ===
 
 
==== Reduced popularity ====
 
==== Reduced popularity ====
 
 
Finding people for software projects who already have experience in Pascal can become difficult.
 
Finding people for software projects who already have experience in Pascal can become difficult.
 
It could be harder to find suitable library solutions for specific problems.
 
It could be harder to find suitable library solutions for specific problems.
  
 
==== More usage of reserved words than reserved characters ====
 
==== More usage of reserved words than reserved characters ====
 
+
Sometimes writing all the reserved words (like <syntaxhighlight lang="pascal" inline>begin</syntaxhighlight>, <syntaxhighlight lang="pascal" inline>end</syntaxhighlight>, <syntaxhighlight lang="pascal" inline>then</syntaxhighlight>, …) feels uncomfortable.
Sometimes writing all the reserved words (like <syntaxhighlight lang="pascal" enclose="none">begin</syntaxhighlight>, <syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight>, <syntaxhighlight lang="pascal" enclose="none">then</syntaxhighlight>, …) feels uncomfortable.
 
 
Other languages just use parentheses or curly braces – that is just a single letter.
 
Other languages just use parentheses or curly braces – that is just a single letter.
Editor functions like “match-corresponding parenthesis/brace” or in Pascal-context “match corresponding <syntaxhighlight lang="pascal" enclose="none">begin</syntaxhighlight>/<syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight>” are harder to find.
+
Editor functions like “match-corresponding parenthesis/brace” or in Pascal-context “match corresponding <syntaxhighlight lang="pascal" inline>begin</syntaxhighlight>/<syntaxhighlight lang="pascal" inline>end</syntaxhighlight>” are harder to find.
  
 
==== Language corset ====
 
==== Language corset ====
 
 
On multiple occasions programmers may encounter boundaries the language sets (e.g. the strong type safety mentioned above).
 
On multiple occasions programmers may encounter boundaries the language sets (e.g. the strong type safety mentioned above).
 
These measures were set for good reasons, though:
 
These measures were set for good reasons, though:
 
To prevent programmers from doing stupid stuff (that's actually a pro point).
 
To prevent programmers from doing stupid stuff (that's actually a pro point).
 
However, if you do not care about bad practices, you might get annoyed by that fact.
 
However, if you do not care about bad practices, you might get annoyed by that fact.
 
  
 
== See also ==
 
== See also ==
 
 
* [[FPC Advantages]]
 
* [[FPC Advantages]]
  
 
== External links ==
 
== External links ==
 +
* [https://web.archive.org/web/20211019221607/http://www.pascal-central.com/ Pascal Central], a repository with technical information, tools, references, source code, internet links, and more.
 +
* [https://www.StandardPascal.org StandardPascal.org], reference information about the ANSI ISO 7185 standard.
 +
* [https://www.ISO.org/standard/13802.html ISO 7185:1990], official normative version of the Pascal standard.
 +
* [https://www.ISO.org/standard/18237.html ISO/IEC 10206:1991]: [[Extended Pascal]] standard
  
* [http://www.pascal-central.com Pascal Central], a repository with technical information, tools, references, source code, internet links, and more.
+
[[Category: Promotion]]
* [http://www.standardpascal.org Standard Pascal], reference information about the ANSI ISO 7185 standard.
+
[[Category: Pascal]]
* [http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=13802 ISO 7185:1990], official normative version of the Pascal standard.
+
[[Category: FPC]]
* [http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=18237 ISO/IEC 10206:1991]: Extended Pascal standard
 
 
 
[[Category:Promotion]]
 
[[Category:Pascal]]
 
[[Category:FPC]]
 

Revision as of 12:25, 5 September 2022

“A low level language is one whose programs require attention to the irrelevant.”

Introduction

Pascal often comes under attack as a language which should be dead, or as a language not suitable for very much.

This document will discuss these claims and add the latest information about Pascal as of 2013 and beyond.

What is Pascal?

Pascal is a very clean programming language, which looks more like real languages in the sense that it uses real English words as keywords rather than random ASCII characters. This is important in understanding existing code as well as debugging because people do not read individual characters but whole words.

A common misconception is that Pascal started as a teaching language. While this is partially true, the associations are usually wrong; usually that makes people expect systems like Logo, limited playing grounds for children.

Pascal, like its predecessor ALGOL(‑60), however was primarily designed as a language for formal specification and teaching of algorithms, mostly with future engineers and computer scientists as target. Contrary to ALGOL‑68, emphasis was put on simplicity. This turned out to be beneficial for compiler construction.

The initial Pascal dialects had a series of serious ugliness (like untyped procedure variables) that were quickly remedied, way before the language's prime time in the eighties (revised J&W and early standardization trajectory).

Further modernization and facilities for interfacing to lower level systems were added to nearly every dialect. Most of these were not standardized back into the language, but this was normal at the time (way before C and POSIX standards). However the dialects were not entirely random, and could be classified into two major streams, UCSD/Borland like and ISO standards compliant, with Apple creating a hybrid between the two (UCSD in origin, but incorporating most level 1 ISO features).

Over the years especially the Borland stream language has matured and gained all capabilities necessary for up-to-date large scale software projects (for example the Free Pascal compiler or the Lazarus IDE).

The particular strength of Pascal is that most development time is spent on the program itself, contrary to C and C++ like languages, where the developer needs to focus on managing the memory of variables or the structure of very basic things like passing parameters and returning them back again.

As a result, Pascal developers do not have to learn a new sub-language inside the same language, like C++, STL, MFC.

The Readln and Writeln effect

Most developers that touched Pascal did not like the language, because they only learned some very basic commands and how to write a more structured code than their mind was thinking at the time.

That is, why languages such as C and Perl, for example, have tended to win the popularity contests. While Pascal seems very basic and very minimalistic, when you uncover the true language, you find that it is much easier to create a program in Pascal than in C, Java and other popular languages. Even languages such as Python, while popular and still remains structured, have many elements of a disoriented language. That issue arrives first of all from the attempt to create the most “perfect” programming language, that will be easy to use, and have the cleanest way to create things.

Pros and Cons

As always: Choosing what programming language to use depends on your program you would like to program.

Pros

Object oriented programming

You want Object Oriented Programming (OOP)? There you got OOP: FPC supports it: see Tutorial. In the meantime, generics (templates, usually for classes) became possible, too, though generics can be used for a wide variety of other types as well.

Real assignment operator

Other languages: mathematically wrong (there are two equations):

x = 42;
x = 3 * 3;

Or even worse (x on both sides):

x = 3 * x - 1;

So, x = 0.5 or what (the f***)?

Pascal does it right (there are two consecutive definitions):

x := 42;
x := 3 * 3;

Strong type safety

In C you can add a character to a real and interpret it as a boolean (or whatsoever). Why the heck should I do this? In Pascal that is not possible (only with force). The compiler will raise an error.

Well structured

For example a function in C look like this:

  1. function signature
  2. declaration of variables … and definition of function may be mixed up

In Pascal it is clear:

  1. function/procedure signature
  2. declaration of variables …
  3. definition of function/procedure/program

Case-insensitive

A function defined with the name getLimit will be called though you forgot the upper-case-L in the middle ( (calling getlimit()). It does not raise a compile-time-error.

Principle of scope

There are many chances to limit the validity of identifiers – to limit their scope. Encapsulating functions/procedures or limiting a variable’s/constant’s/type’s scope is done implicitly: Depending where you declare such things, they are only known on the same or lower levels.

Readability

You can write Pascal as you speak (or at least it is some more natural):

if x equals true then
begin
writeline, left round bracket, apostrophe, hello world, apostrophe, right round bracket, semicolon
end

Counter example:

if, left round bracket, x equal equal true, right round bracket
left curly brace
print formatted, left round bracket, inch-sign, hello world,
     backslash n, inch-sign, right round bracket, semicolon
right curly brace

The counter example shows that you may get lost if you do not know what brackets and braces mean. Indeed, it is a weak pro-point.

Native set operators

Since Mr. Wirth (the father of the Pascal language) has a background in mathematics, where sets (containers of units called “elements”) are a fundamental tool, he included operators for handling with sets, too. We can check, whether an element is in a set via the in operator. We can include, exclude elements, compare sets (difference, symmetric difference), combine and intersect them. Knowing where to use sets, makes your code incredibly more readable! There is no need to include any extra class or unit for that, it is already part of the language. However, FPC’s current implementation of sets allows 256 elements top per set. You cannot do mathematics in a large scale with that, though.

Cons

Reduced popularity

Finding people for software projects who already have experience in Pascal can become difficult. It could be harder to find suitable library solutions for specific problems.

More usage of reserved words than reserved characters

Sometimes writing all the reserved words (like begin, end, then, …) feels uncomfortable. Other languages just use parentheses or curly braces – that is just a single letter. Editor functions like “match-corresponding parenthesis/brace” or in Pascal-context “match corresponding begin/end” are harder to find.

Language corset

On multiple occasions programmers may encounter boundaries the language sets (e.g. the strong type safety mentioned above). These measures were set for good reasons, though: To prevent programmers from doing stupid stuff (that's actually a pro point). However, if you do not care about bad practices, you might get annoyed by that fact.

See also

External links