COMMUNITY

Using local var inside its initialization

Hej Mario,
Thanks for your little and very clear example !
Yes I understand better now.
But why it should still behave like this is shadowing variables wasn’t allowed please ?
(I’m sorry I love understand things in their “atomic” way…)

Mostly because to me the meaning of var a = <init expression> is "first compute <init expression> then create a variable a and assign the computed value to it.

This might be subjective preference but it’s also how most other languages I’ve used have worked. There’s objective value in being consistent with what most users will expect.

At first I was going to say that this is also about preventing errors regarding using unassigned variables but those could be caught by the compiler anyway, so that might not be a good argument.

2 Likes

Why not pass the object into the callback?

var questionsListing = new Listing<Question>(  
[
	...
	ELMove((_, l) ->l.lastReq.ord == "ord" ),
	...
]);