[fpc-devel] Multiple variable initialization

Jonas Maebe jonas at freepascal.org
Sat Mar 24 16:53:42 CET 2018


On 24/03/18 16:20, Ondrej Pokorny wrote:
> On 24.03.2018 15:46, Alexander Grotewohl wrote:
>> The patch is to put them on separate lines. Preferably with meaningful 
>> comments for each. If FPC was changed at the whim of every programmer 
>> we'd end up with a huge mess that no longer resembles pascal.
> 
> Please tell me who decides about the borderline between whim and 
> usefulness.

It's in the eye of the beholder. Personally, I don't think it's a good 
extension either. Variable lists followed by a type are a fundamental 
part of the language and appear everywhere (variable lists, field 
declarations, parameter lists). On the other hand, a single constant 
that initialises multiple variables in a single statement does not exist 
anywhere else in the language. Therefore, adding it in one place would 
definitely be the wrong way to go about it. You'd also have to support 
it at least for record field initialisers and default parameters.

When seeing that compound initialisation/declaration statement for the 
first time, my first reflex was to interpret the initialisation as only 
applying to the final variable, no matter how useless that would make 
the language extension. As someone else posted, even languages that do 
allow multiple variables to be assigned in a single statement use a 
different syntax than the one to indicate that all variables have the 
same type. Having to switch your frame of mind when reading one 
particular family of expressions is bad for productivity. Everything 
should be as consistent as possible.

In the end, pretty much every extra language feature makes both the 
compiler and the language more complex. Therefore, I think the question 
for language extensions should never be "is there a good reason not to 
allow this", but "is it really necessary to allow this"? I.e., does it 
make things much easier to read, less error prone to write, and/or 
increase productivity a lot. I don't think the answer is "yes" for any 
of these questions as far as this extension is concerned.


Jonas



More information about the fpc-devel mailing list