[fpc-devel] Multiple variable initialization - YES

Péter Gábor ptrg at freemail.hu
Mon Apr 2 15:38:32 CEST 2018


Hi!

I have bean read all of the emails in this topic and now I have to write
:) :

If multiple type declaration (A, B: Integer) are allowed then this new
feature would not make difficulty to learn. Especially if we compare it
to generics, what is already in the language and required/requires to
learn a new (and non-conventional) syntax.

If the question is (as Jonas said) that "Is it really necessary to allow
this"? - NOT necessary, we can live without it BUT...

BUT if ask the sub-questions (by Jonas):
- Does it make things much easier to read? - YES
- Less error prone to write? - YES
- Increase productivity a lot? - YES

Sum of answers are absolutely YES!
The requested language feature is a good idea that can make our favorite
language better in all manners.

You can see it if you (all) take a look at at the examples (from Ondrej)
below:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -

OLD:

  procedure Test(const A: Integer = 0; const B: Integer = 0; const C:
Integer = 0; const D: Integer = 0);

NEW:

  procedure Test(const A, B, C, D: Integer = 0);

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -

OLD:

  procedure Test;
  var
    A, B, C, D, E, F: string;
  begin
    A := '';
    B := '';
    C := '';
    D := '';
    E := '';
    F := '';
  end;

NEW:

  procedure Test;
  var
    A, B, C, D, E, F: string = '';
  begin
  end;

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -

OLD-MIXED:

  procedure Test(const A: Integer = 0; const B: Integer = 0; const C:
Integer = 0; const D: Integer = 0);
  var
    E, F, G, H,,I, J: string;
  begin
    E := '';
    F := '';
    G := '';
    H := '';
    I := '';
    J := '';
  end;

NEW-MIXED:

  procedure Test(const A, B, C, D: Integer = 0);
  var
    E, F, G, H, I, J: string = '';
  begin
  end;

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -

And again, the requested language feature is a good idea that can make
our favorite language better in all manners.



2018-03-24 11:46 keltezéssel, Ondrej Pokorny írta:
> Is there a reason why multiple variable initialization is forbidden?
>
> program Test;
> var
>   A: Integer = 0;    // allowed
>   B, C: Integer = 0; // not allowed
> begin
> end.
>

Regards

-- 
Péter Gábor
ptrg at freemail.hu





More information about the fpc-devel mailing list