Use of redundant var
f.cooney at gmx.co.uk
Sat Aug 23 06:25:07 PDT 2008
Ingvar von Schoultz wrote:
> you sprinkle your declarations all over the code, with redundant
> repetitions if you like. Block scope should be available also with
> this usage pattern, in my view.
Jon Zeppieri wrote:
> I do know, however, that I don't like this.
> I think you, Ingvar, are the lone champion of redundant variable
> I'm not sure who the champions of var hoisting are. (In another
> thread, Brendan referred to hoisting as a wart.)
Yuh-Ruey Chen wrote:
> Actually, I'm pretty sympathetic to redundant variable declarations, [...]
I'm also in favour of multiple, "redundant" vars. I use them semantically
and as a discipline.
var x = 1;
: : :
var x = 2;
: : :
When I write the above pattern you won't see x being used outside those
inner blocks. The two vars are my way of saying that they are independant
'x's, although the same name would be being used because they have the same
If I want to use x after in the outer scope then I'll use
x = 1;
: : :
x = 2;
: : :
I know that the language makes this unnecessary but I've always considered
hoisting to be, if not a bug, then an undesirable necessity. That is, it's
undesirable to me as I prefer everything to be block scoped and not hoisted,
but necessary in a language which doesn't require pre-declared variables.
I've always secretly hoped that the "bug" would be "fixed" but, of course,
backward compatibility means that it can't. The feature of block scoping is
a very welcome addition, hence me giving a bit of energy to promoting "here"
over "let". ;-)
More information about the Es-discuss