Sign in Join
Wiki copytemporary

Why Pascal is Not My Favorite Programming Language: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11"Why Pascal is Not My Favorite Programming Language" is an article (can be found [here](http://www.lysator.liu.se/c/bwk-on-pascal.html)) written about by Brian W. Kernighan, April 2, 1981. The article is often used in language comparison discussions even today, typically by critics of the Pascal-family, despite the fact that the article is talking about a version of Pascal that has been superseded. The description of the language that B Kernighan is referring to in the article can be found [here](http://web.archive.org/web/20210718153204/http://pascal-central.com/docs/pascal1973.pdf).
22
33The purpose of this page, is to show that the article is quite outdated. People who are still trying to refer to the article are unaware of the capabilities of current Pascal (Delphi/FPC) implementations.
44
55## Genesis
66
77## Article
88
99### Types and Scopes
1010
11-`Integer variables may be declared to have an associated range of legal values, and the compiler and run-time support `\
12-`ensure that one does not put large integers into variables that only hold small ones.  This too seems like a service,`\
13-`although of course run-time checking does exact a penalty. `
11+```text
12+Integer variables may be declared to have an associated range of legal values, and the compiler and run-time support
13+ensure that one does not put large integers into variables that only hold small ones. This too seems like a service,
14+although of course run-time checking does exact a penalty.
15+```
1416
1517It needs to be noted here, that compiler allows to remove the range run-time check completely.
1618
1719### The size of an array is part of its type
1820
1921Without quoting of the article - the complain is about an arrays of different size (though still the same type) are considered a different type. Since Pascal is strict type routines cannot be shared among array of different size. The task of sorting is used as an example in the article.
2022
2123The 1985 Ansi/ISO standards have an (optional) section about conformant arrays fixing this. Currently neither FPC (ISO mode) nor Borland derivatives implement it.
2224
2325[Dynamic](http://www.freepascal.org/docs-html/ref/refsu18.htm) and [Open arrays](http://www.freepascal.org/docs-html/ref/refsu64.html) were introduced in Delphi that overcomes the limitation at the cost of the lower bound always being 0. The desired result could be achieved even back at the time, using pointers.
2426
2527### There are no static variables and no initialization
2628
2729As well as Static variables are just "implementation"-only variables per unit. Global variable initialization were added in some version of Delphi, as well as type constants (which are variables) requires the initialization to be present.
2830
2931Also, each unit provides an initialization section (which is executed in run-time), that provides a very flexible and convenient way for initialization (of dynamic storages).
3032
3133### Related program components must be kept separate
3234
3335No such strict order limitation in Object Pascal.
3436
3537### There is no separate compilation
3638
3739Fixed mid eighties by the module(ISO)/units(UCSD/Borland) system in a way that doesn't need a separate interpreter (make) to manage building and without the infinate header reparsing problem that causes C and C++ compilers to be relatively slow in practice.
3840
3941### Some miscellaneous problems of type and scope
4042
41-`It is not legal to name a non-basic type as the literal formal parameter of a procedure; `
43+``` pascal
44+It is not legal to name a non-basic type as the literal formal parameter of a procedure;
45+```
4246
4347This is actually still true.
4448
45-`It is nice to have the declaration 'var' for formal parameters of functions and procedures; `\
46-`the procedure clearly states that it intends to modify the argument.  But the calling program `\
47-`has no way to declare that a variable is to be modified - the information is only in one place,`\
48-`while two places would be better.`
49+``` pascal
50+It is nice to have the declaration 'var' for formal parameters of functions and procedures;
51+the procedure clearly states that it intends to modify the argument. But the calling program
52+has no way to declare that a variable is to be modified - the information is only in one place,
53+while two places would be better.
54+```
4955
5056[const](http://www.freepascal.org/docs-html/ref/refsu63.html) is available to identified unmodified parameter and passing a parameter by reference (where applicable)
5157
52-`Pascal's 'set' construct seems like a good idea, providing notational convenience and some free type checking.  `\
53-` For example, a set  of tests like`\
58+``` pascal
59+Pascal's 'set' construct seems like a good idea, providing notational convenience and some free type checking.
60+ For example, a set of tests like
5461
55-`    if (c = blank) or (c = tab) or (c = newline) then ...`\
62+ if (c = blank) or (c = tab) or (c = newline) then ...
5663
57-` can be written rather more clearly and perhaps more efficiently as`\
64+ can be written rather more clearly and perhaps more efficiently as
5865
59-`    if c in [blank, tab, newline] then ..`
66+ if c in [blank, tab, newline] then ..
67+```
6068
6169And [they're](http://www.freepascal.org/docs-html/ref/refsu20.html)!
6270
6371### There is no escape
6472
6573Type casting is available (and causing issues for some developers)
6674
6775## Control Flow
6876
69-`There is no guaranteed order of evaluation of the logical operators 'and' and 'or' - nothing like && and || in C.  `\
70-`This failing, which is shared with most other languages, hurts most often in loop control:`\
77+```text
78+There is no guaranteed order of evaluation of the logical operators 'and' and 'or' - nothing like && and || in C.
79+This failing, which is shared with most other languages, hurts most often in loop control:
7180
72-`    while (i <= XMAX) and (x[i] > 0) do ...`
81+ while (i <= XMAX) and (x[i] > 0) do ...
82+```
7383
7484Conditions are [short-cut evaluated](http://www.freepascal.org/docs-html/ref/refsu53.html). Thus loops can be implemented the way above without a risk breaking out of the range.
7585
76-`With no 'break' statement...`
86+```text
87+With no 'break' statement...
88+```
7789
7890There's [break](http://www.freepascal.org/docs-html/ref/refsu57.htm)
7991
80-`The increment of a 'for' loop can only be +1 or -1, a minor restriction.`
92+```text
93+The increment of a 'for' loop can only be +1 or -1, a minor restriction.
94+```
8195
8296Still true.
8397
84-`There is no 'return' statement, again for one in-one out reasons. `
98+```text
99+There is no 'return' statement, again for one in-one out reasons.
100+```
85101
86102There's Exit statement (FPC only Exit() ) available.
87103
88-`The 'case' statement is better designed than in C, except that there is no 'default' clause and the behavior `\
89-`is undefined if the input expression does not match any of the cases.  This crucial omission renders the 'case' construct `\
90-`almost worthless.`
104+```text
105+The 'case' statement is better designed than in C, except that there is no 'default' clause and the behavior
106+is undefined if the input expression does not match any of the cases. This crucial omission renders the 'case' construct
107+almost worthless.
108+```
91109
92110There's [else (or otherwise)](https://www.freepascal.org/docs-html/current/ref/refsu56.html#x166-19000013.2.2) in case statement.
93111
94112## The Environment
95113
96114No problems with using System APIs and any I/O routines provided by an underlying environment.
97115
98116## Cosmetic Issues
99117
100-`But if something must be inserted before b, it no longer needs a semicolon, because it now precedes an 'end': `
118+``` pascal
119+But if something must be inserted before b, it no longer needs a semicolon, because it now precedes an 'end':
120+```
101121
102122A statement before "end" might have or not have a semicolon. Not-having a semicolon is not enforced.
103123
104-`C and Ratfor programmers find 'begin' and 'end' bulky compared to { and }.`
124+``` pascal
125+C and Ratfor programmers find 'begin' and 'end' bulky compared to { and }.
126+```
105127
106128Is still true and there're no plans to change that.
107129
108-`A function name by itself is a call of that function; there is no way to distinguish such a function call from a simple variable `\
109-`except by knowing the names of the functions`
130+``` pascal
131+A function name by itself is a call of that function; there is no way to distinguish such a function call from a simple variable
132+except by knowing the names of the functions
133+```
110134
111135Is still true, except for FPC/objFPC mode, where a function call must come with ()
112136
113-`In particular, there are no bit-manipulation operators (AND, OR, XOR, etc.).  `\
114-`I simply gave up trying to write the following trivial encryption program in Pascal:`\
137+``` pascal
138+In particular, there are no bit-manipulation operators (AND, OR, XOR, etc.).
139+I simply gave up trying to write the following trivial encryption program in Pascal:
115140
116-`    i := 1;`\
117-`    while getc(c) <> ENDFILE do begin`\
118-`            putc(xor(c, key[i]));`\
119-`            i := i mod keylen + 1`\
120-`    end`
141+ i := 1;
142+ while getc(c) <> ENDFILE do begin
143+ putc(xor(c, key[i]));
144+ i := i mod keylen + 1
145+ end
146+```
121147
122148Bit-manipulation [operators](https://www.freepascal.org/docs-html/current/ref/refsu45.html) are available.
123149
124-`There is no null string, perhaps because Pascal uses the doubled quote notation to indicate a quote embedded in a string`\
125-` `\
126-`   'This is a '' character'`\
150+``` pascal
151+There is no null string, perhaps because Pascal uses the doubled quote notation to indicate a quote embedded in a string
152+
153+ 'This is a '' character'
127154
128-`There is no way to put non-graphic symbols into strings.  In fact, non-graphic characters are unpersons in a stronger `\
129-`sense, since   they are not mentioned in any part of the standard language.  Concepts like newlines, tabs, and so on `\
130-`are handled on each system in an  'ad hoc' manner, usually by knowing something about the character set `\
131-`(e.g., ASCII newline has decimal value 10)`
155+There is no way to put non-graphic symbols into strings. In fact, non-graphic characters are unpersons in a stronger
156+sense, since they are not mentioned in any part of the standard language. Concepts like newlines, tabs, and so on
157+are handled on each system in an 'ad hoc' manner, usually by knowing something about the character set
158+(e.g., ASCII newline has decimal value 10)
159+```
132160
133161Escape characters are available.
134162
135-` 'new line'#13#10`
163+```text
164+ 'new line'#13#10
165+```
136166
137167Needless to say, that Unicode escaping is available too.
138168
139-`There is no macro processor.`
169+```text
170+There is no macro processor.
171+```
140172
141173God bless Pascal!
142174
143-`The 'const' mechanism for defining manifest constants takes care of about 95 percent of the uses of simple `\
144-`#define statements in C, but more involved ones are hopeless.  It is certainly possible to put a macro `\
145-`preprocessor on a Pascal compiler.  This allowed me to simulate a sensible 'error' procedure as`\
175+``` pascal
176+The 'const' mechanism for defining manifest constants takes care of about 95 percent of the uses of simple
177+#define statements in C, but more involved ones are hopeless. It is certainly possible to put a macro
178+preprocessor on a Pascal compiler. This allowed me to simulate a sensible 'error' procedure as
146179
147-`    #define error(s)begin writeln(s); halt end`
180+ #define error(s)begin writeln(s); halt end
181+```
148182
149183Obviously the error(s) should implemented as a function. Since nothing is executed after Halt(). Though these days "raising" an exception might be a better approach.
150184
151-`The language prohibits expressions in declarations, so it is not possible to write things like `\
152-`  const   SIZE = 10;`\
153-`  type    arr = array [1..SIZE+1] of integer;`
185+``` pascal
186+The language prohibits expressions in declarations, so it is not possible to write things like
187+ const SIZE = 10;
188+ type arr = array [1..SIZE+1] of integer;
189+```
154190
155191[Constant expressions](http://www.freepascal.org/docs-html/ref/refse9.html) are allowed as value of an expression.
156192
157193## Perspective
158194
159-`To close, let me summarize the main points in the case against Pascal. `\
160-`1. 2. 3. 4. 5. 6. 7. 8.  ...`\
161-`9. There's no escape `\
195+``` pascal
196+To close, let me summarize the main points in the case against Pascal.
197+1. 2. 3. 4. 5. 6. 7. 8. ...
198+9. There's no escape
162199
163-`This last point is perhaps the most important.  The language is inadequate but circumscribed, because there `\
164-`is no way to escape its limitations.  There are no casts to disable the type-checking when necessary.  `\
165-`There is no way to replace the defective run-time environment with a sensible one, unless one controls `\
166-``` the compiler that defines the ``standard procedures.'' The language is closed. ```
200+This last point is perhaps the most important. The language is inadequate but circumscribed, because there
201+is no way to escape its limitations. There are no casts to disable the type-checking when necessary.
202+There is no way to replace the defective run-time environment with a sensible one, unless one controls
203+the compiler that defines the ``standard procedures.'' The language is closed.
204+```
167205
168206Modern Pascals are easily extensible, but still, if you don't like the run-time environment. You can introduce your own. After all, FPC is open source.
169207
170208---
171209*From the Free Pascal wiki, page "Why Pascal is Not My Favorite Programming Language", as it stood on 2023-11-27 after a change by N7800, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
172210Category: Promotion

Back to history