- DelphiTools - https://www.delphitools.info -

Möbius: Pascal without begin/end?

Möbius strip [1]One recent announce of MSELang [2] by Martin Schreiber reminded me of something I’ve been mulling over, code name “Möbius” which would be Pascal without begin and/or end.

Before you prepare the tar and feathers, read on, and vote at the bottom, if you get there 😉

Pascal is a verbose language, that’s why we like it, but sometimes it can be a bit too verbose with the begin/end, and some format conventions (with begin/end on their own line) make it huge. Personally I was raised on C, so I use the C-like format (with begin at the end of the previous line) which is a bit more compact, but still verbose

Also it’s not very consistent. Some constructs require begin/end for multiple lines (while, for, if/then/else), while others don’t (repeat until, case of else, try except, try finally, class declarations, record declarations).

The cases where begin is optional are those where you can get away with a single statement, but they break the visual balancing of indentation.

To get rid of the begin/end, there are basically two coherent ways:

  1. drop the “begin”, but make “end” compulsory, this is the route Martin chose for MSElang, and it has merit. Everything stays well balanced. The inconsistencies are gone, and it adds very little “end” verbose-ness in practice while eliminating a lot of “begin” verbose-ness
    while whatever do
       ...something...
       if someTest then
          ...do something...
       else
          ...do something else...
       end;
    end;
    ...further code...
  2. got for indentation-based blocks (like Python), where a block of code is determined by its indentation, rather than delimiters.
    while whatever do
       ...something...
       if someTest then
          ...do something...
       else
          ...do something else...
    ...further code...

One refinement that the first form (drop begin, keep end) allows is to qualify the end, f.i. rather than just “end” the compiler could allow “end while” for a “while” block, “end for“, “for” a for block, etc. The syntax could be extended to existing begin-less constructs (“end except“, “end case“, etc.)

For small blocks such qualifications are useless, but in more complex cases, they can come in handy, and avoid the (too often misleading) practice of adding a comment after the “end” for qualification purposes.

So what say you?

Pascal without begin or end

  • Heretic! I can't live without begin/end (51%, 168 Votes)
  • Dropping the "begin" could be nice (35%, 116 Votes)
  • No begin or end, indentations ala Python (14%, 48 Votes)

Total Voters: 332

Loading ... Loading ...