On 2014-09-08 21:12, Trevor Vaughan wrote:
I tend to avoid += since it's a "magic" edge case in variable scope.

If all of my code takes the strict view that variables are immutable, I
am much less likely to confuse anyone who reads my code later.


Just to be clear, the += does *not* mutate, it creates a new variable that shadows the original in an outer scope.

This does end up with stupid code like $l_var = $var + ['foo'], but that
can't be helped while preserving clarity.

Now, I would LOVE the ability to manipulate all variables within scope.
That would be very nice and then I would vote for keeping += around.

That would allow for things like:

if empty($foo) {
   $foo = 'bar'
}

Instead of:

if empty($foo) {
   $l_foo = 'bar'
}
else {
   $l_foo = $foo
}

Which is irritating.

Trevor


- henrik
--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
You received this message because you are subscribed to the Google Groups "Puppet 
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/ls60q9%24s0d%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to