Forum > FPC development

Variables everywhere - is it good idea?

<< < (2/6) > >>

Nitorami:
Interesting. But within a function or procedure, any var declaration is allocated on the stack, isn't it ? What is the difference to alloca then ?

Leledumbo:

--- Quote from: FPC on March 15, 2015, 08:02:45 pm ---Hi all.What do you think about this idea?Example,

--- Code: ---begin
var a:Integer;
a:=0;
for var i:=1 to 10 do
 begin
  var c:=i*2;
  a:=a+c;
 end;
Writeln(a);
Readln;
end.
--- End code ---
Is it good idea or is it bad?

--- End quote ---
Bad, but if you want, try GNU Pascal. They already have it implemented. I don't think FPC will ever implement it, though.

marcov:

--- Quote from: Nitorami on March 15, 2015, 10:52:07 pm ---Interesting. But within a function or procedure, any var declaration is allocated on the stack, isn't it ? What is the difference to alloca then ?

--- End quote ---

There is no need to actually also implement it in a nested way. (since that would only generate more instructions). And afaik alloca can take a variable count.

alcalde:

--- Quote from: FPC on March 15, 2015, 08:02:45 pm ---Hi all.What do you think about this idea?Example,

--- Code: ---begin
var a:Integer;
a:=0;
for var i:=1 to 10 do
 begin
  var c:=i*2;
  a:=a+c;
 end;
Writeln(a);
Readln;
end.
--- End code ---
Is it good idea or is it bad?

--- End quote ---

If anything it's still too verbose.  :D There was no need to even declare the "a" variable first since it was assigned the value 0. But otherwise, yes, it's a good first step towards bringing Pascal up to date with modern "best practices" in language design.. I can dig up a computer science paper in which it states that "it's now universally accepted that variables should be declared as close as possible to where they were first used". Pascal's declare everything ahead syntax was motivated by Wirth's single-pass compiler design, which was itself motivated by extreme memory limitations at the time. As he put it, when he designed Pascal, "the memory of mainframes was measured in kilobytes".  Over the years Pascal users have invented all sorts of reasons why things were designed the way they were, but the reality is generally that the oddities of Pascal were all the result of the single pass compiler, not because they conferred some sort of benefit to coding.

alcalde:

--- Quote from: Leledumbo on March 16, 2015, 04:40:46 am ---Bad, but if you want, try GNU Pascal. They already have it implemented. I don't think FPC will ever implement it, though.

--- End quote ---

Why do you believe it's bad? I've done a formal review of languages for two start-ups, and I don't recall seeing a single statically-typed language created in the 21st century (2000-) that didn't use type inference. In computer science it's considered universally true that a variable should be declared as close as possible to where it is first used (in Pascal it's the old page-up, page-up, page-up... sigh). Pascal's declare-everything-upfront design was necessitated by Wirth's use of a single-pass compiler design to save memory. There's simply no need in 2015 to clutter code by pedantically declaring every variable and the good old page-up, page-down (no, IDE improvements should not be used to cover up language shortcomings).

If you think of languages as organisms that evolve and pass on their good ideas to future languages, then the notion of defining every variable in a pre-defined section was an evolutionary dead end. Other than COBOL and close Pascal cousins ADA and Eiffel, absolutely no language in decades adopted the notion. Certainly no popular language today uses it. If you were trying to convince a C++, Ruby, Java developer to use Pascal, how would you answer them when they asked why they had to declare all of their variables beforehand, especially when they point out that the Handley-Millner type inference algorithm has existed for 30 years? And if we can't answer, where does the next generation of Pascal developers come from?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version