On Aug 24, 2010, at 10:31 AM, Glenn Little wrote:

Also, the "upcase" I was using was just a stand-in for more complex,
custom mutation.

Sure, but you understand that the variable is a reference, so you can just assign whatever you want to it within your block.

In the end, since this code is going to need to be maintained by more
than just me (including non-ruby-experts), I think I'll go with
"straigthforward" and avoid the case where you have to know reference
vs. value and so on and just build new hashes on the fly and append
them to a new list.  Seems mundane and not particularly elegant, but
at least it's straightforward and more universally maintainable.

PHP is the only language that has iterators that pass copies by default - but it does copies everywhere by default, so you are used to adding the & prefix for getting a reference (and when you do that with its foreach iterator then it does what you'd expect).

My point is that it's not just ruby experts who would expect this reference behavior of iterators. I'd be shocked if any (decent, ie. PHP doesn't count :) language iterated over an array making copies of each element. That'd be counter-intuitive for an iterator.

My thoughts have always been that language authors do this because the iterator syntax is really just a convenience for a C-style for loop, so the coder is always going to expect the element to be a reference, in the same way that foo_array[i] is a reference.

Just my 2ยข

--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to