Forum > FPC development

Variables everywhere - is it good idea?

(1/6) > >>

moskalenco_a:
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?

Never:
these expresions are currently illegal the above code will not compile...
if this is a suggestion imho : no thank you very much
this a nice way to lose the eggs and the basket in 10 lines of code

moskalenco_a:
Yes,it's suggestion.

Nitorami:
This is useless. In a construct like

for var i := 1 to 10 do

what is "var" good for ? It has no meaning. In Basic, you can omit it competely

for i = 1 to 10 do ...

In C, you need to specify the type of variable

for (int i=1; i <=10; i++)

Pascal forces you to specify it beforehand, and that is intended.


--- Code: ---var a,i,c:Integer;
begin
a:=0;
for i:=1 to 10 do
 begin
  c:=i*2;
  a:=a+c;
 end;
Writeln(a);
Readln;
end.

--- End code ---

marcov:
It can be used to disambiguate that you really want to create a variable in that scope, overriding a possible local variable called I.

That being said with most current IDE having shortcuts to properly declare variables, I think it is an outdated concept.

It was probably important to micromanage stack depth in the C of 1970, but nowadays barely anything is dynamically allocated from the stack anymore (alloca in C), and most big types are not allocated from the stack.

Navigation

[0] Message Index

[#] Next page

Go to full version