In Modula-2 and Oberon each module and procedure declaration must end with the name of the module or procedure. It is not needed in Pascal. I have never really understood the motivation for this. Can someone enlighten me?
2 Answers
After reading some (I am not an expert) I would wager this is just a syntax demand of the function for better readability.
I'll go one step further, and say in large, old, badly written procedures/function in other languages, this is sometimes done without the language requiring it. I've often seen:
int veryLongC++Function() {
...
...
... 3000 code lines
} //veryLongC++Function
So a reader jumping near the end knows what in the mess they are looking at. August mentions in the comment this is much less robust when not enforced by the compiler - in case of a name change.
Another important aspect is nested procedures - here the explicit ending makes things much more readable - checkout chapter 7 for an example - a nested procedure is declared between a declaration and before the BEGIN
. The syntax makes this looks much better (in my opinion).
So long story short - I think the main benefit is readability.

- 24,623
- 6
- 41
- 74
-
2I have also read somewhere that it makes it easier for the compiler to point out the (approximate) location of an unbalanced END keyword in a statement sequence. – August Karlstrom May 29 '18 at 15:22
-
1I your C++ example there is also a positive probability that a person changing the name of the function will forget to change the comment at the end. Then the comment creates more problems than it solves. – August Karlstrom May 29 '18 at 15:28
-
@AugustKarlstrom I agree, that's why enforcing it through compilation is more robust. – kabanus May 29 '18 at 16:11
-
@AugustKarlstrom Modern editors have search & replace. It's not changing the name of a function in its source that's a problem. It's changing its name in all the files that call it. – shawnhcorey May 30 '18 at 12:11
-
1@shawnhcorey If you forget to change the name in a procedure call the compiler will let you know. The compiler can do nothing about out of sync comments, however. – August Karlstrom May 30 '18 at 12:33
-
@AugustKarlstrom The problem with that is the compiler will spew out a whole bunch of errors. Making changes one at a time means waiting for the compiler a lot. – shawnhcorey May 30 '18 at 16:03
-
1@AugustKarlstrom "I have also read somewhere that it makes it easier for the compiler to point out the (approximate) location of an unbalanced END keyword in a statement sequence." A CS professor of mine stated explicitly that this was the reason. Some languages (I don't recall if Oberon is one) require "end if" and "end while" as well, and that also helps, and certainly when I programmed in Pascal and C in the 90s, before the common tools would highlight matching begin/end statements, I had issues figuring out what I had left off where. I loved Modula-2 if only for that reason alone. – John Perry Sep 26 '18 at 16:32
It's possible you get something like this:
MODULE A;
...
PROCEDURE B;
...
PROCEDURE C;
...
BEGIN (* C *)
...
END C;
BEGIN (* B *)
...
END B;
BEGIN (* A *)
...
END A.
In that case, for readability you have three bodies (and more if you have defined nested procedures and functions) at the end of your code. In order to see which one is the one ending in the END
clause, it's better if the compiler can check that you ar closing things correctly (as you see, I even put it ---as a comment, but would be nice if the compiler accepted it as a valid identifier and checked just to be sure things match correctly--- at the start BEGIN
body clause)

- 10,974
- 1
- 16
- 31