[fpc-devel] "Blank slate" next version of FPC

Anton Shepelev anton.txt at gmail.com
Sat Mar 9 19:06:20 CET 2019


Sven Barth:

> Pascal is a language where declaration and use of
> variables is separated.  It makes it easy to see what
> variables are declared and what type they are.  Inline
> variables mess this up as a variable can be declared
> somewhere inside the code.  I use C++ to earn my living. I
> know why I'm not a fan of inline variables as I've been
> biten by them often enough already.

I agree for my own reasons.

As Wirth himself pointed out in the title of a book,
programs comprise two conceptually separate parts: data
structures and algorithms that work on them.  The separation
of variable declaration and their use follows this view, so
that every Pascal routine has a data declaration/definition
section and an executable begin..end block.  This beautiful
concept forms a cornerstone of all Wirth languages and is
certainly worth keeping.

I find code with intermixed variable declarations less
readable because the declaraions no longer stand out but are
buried within imperative statements.  In order to navigate
to a variable declaration from the point of its use other
than the first one, the reader must scan the whole
subprogram upwards, rather than the small declaration
section.

Intermixed variable declarations harm perception.  When
reading an algorithm, I am focused on what it does.
Whenever I encounter a new variable declared in the middle
of a function body, I have to perform a mental context
switch and update the data model associated with the
algorithm.

Whenever the programmer grows annoyed of jumping to the
declaration section and back to code, he knows it is time to
cut his spaghetti into more manageable parts.

Inline variables are simply ugly, disrupting the aesthetical
rhythm of code:

  a := a + Func1( b );
  int b := Func2( a );
  a := a - Func3( b );

Also worth reference are Bart's thoughts on the subject, in
two parts:

  http://al.howardknight.net/msgid.cgi?ID=155215407800
  http://al.howardknight.net/msgid.cgi?ID=155215418300

Please, do not turn Pascal into another C# or Java.

-- 
Please, do not forward replies to my e-mail.




More information about the fpc-devel mailing list