Re: Shadowing of variables..

On 28 November 2011 11:30, Geert Josten wrote:

> I usually redeclare variables if I want to build a final value
> in multiple steps, to make either calculation easier (reusing
> intermediate values multiple times in one expression), or just
> to decompose an otherwise very long calculation.

  I was pretty sure that was the reason :-) The thing is:  1/ you
name a temporary thing with the name of the final thing, and 2/
when one is looking back for the way a variable is computed,
he/she can be misled when finding the variable declaration, but
not noticing it is actually shadowed later on and is actually
only a temporary step.

  In the wrong case scenario, when I don't find a meaningful name
for the temporary variable, I simply call it [the-final-var]-tmp.

  But I guess this is becoming more a development best practice /
ideology thing, than an XProc topic...

> PS: what are the use cases for XSLT? ;-)

  Honestly, I am not quite sure but I suspect this is the same
reason.  Maybe also to ease generating code in some cases.  But
I didn't say I liked it more in XSLT :-)

  Regards,

-- 
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/

Received on Monday, 28 November 2011 10:54:11 UTC