97
Can we get an option to initialize variables to a certain value?

Something like this:

var
MyInt: Integer = 10;
MyGuid: Guid = {cbbd84dc-84f8-4ca4-88dc-9a526dbf88d0};
Category: Development
STATUS DETAILS
Under Review

Comments

A

Is there already an Idea for inline declaration of variables? Or are we piggy backing it on this Idea?

Category: Development

A

I would rather support inline declaration, instead of the old var block, e.g.

local procedure Foo()
begin
var Bar: Boolean := SomeComplexBunchOfTestsAndCalls();

if Bar then
Flump();
end;

Category: Development

A

Would this also apply to e.g. arguments and return values?
procedure Foo(a: Text = 'bar'; b: Integer = 1): Boolean = true

I'm also thinking, since only primitive/simple values (literals) can be supported, do we need the value type name?
procedure Foo(a: 'Bar'; b: 1): true

I'd think that would at least make overloading somewhat more straightforward too.

I'm also wondering what your suggestion would be for single-line-declarations:
a, b, c: Integer;

Were you thinking about something like:
a = 1, b = 2, c = 3: Integer; // each declaration has an independent optional default value
or even:
a: 1; b: 2; c: 3; // the literal implies it's an Integer type

or
a, b, c: Integer = 1; // all same-line declarations have the same default value
or even:
a, b, c: 1;

Btw. I also really like the const idea by Arend-Jan Kauffmann.

Category: Development

A

I would like to see inline declaration of variables rather than the VAR section (ala C# et al)

Category: Development

A

Or similar to how labels are locked:

var
MyGuid: label '{cbbd84dc-84f8-4ca4-88dc-9a526dbf88d0}', Locked = true; // This is possible already! Better than a procedure that exists this Guid, but
MyGuid: Guid '{cbbd84dc-84f8-4ca4-88dc-9a526dbf88d0}', Locked = true; // would be more consistent
MyInt: Integer 10, Locked = true; // (the same for an integer)

Category: Development

A

Wish I could vote for this one more than once!
Would also agree about the constant idea (with associated codecop rules)

Category: Development

A

Optionally add the option to make the variable constant. Like:

var
MyInt: Integer = 10;
const MyGuid: Guid = {cbbd84dc-84f8-4ca4-88dc-9a526dbf88d0};

or

var
MyInt: Integer = 10;

const
MyGuid: Guid = {cbbd84dc-84f8-4ca4-88dc-9a526dbf88d0};

Category: Development