D
dblack
Hi --
I'm not getting the "naturally" part
I mean, of course it's all
non-natural in a sense, but I just can't seem to get my brain to
perceive 3.times as returning something that responds to map this way.
Maybe part of the problem is that it suggests an equivalence between:
[0,1,2].map {}
and
3.times.map {}
which makes it seem like 3.times is return an array. Or something. I
don't even know exactly; it just reads very badly to me.
I think that if something has to be around for a while to be
comprehensible, it loses the "intuitive" badge
I'm sure that
eventually the process of mentally translating it will get faster....
I guess I'm just used to Ruby semantics not having big gaps, and for
me, there's a big gap between "3.times.map" and mapping across 0,1,2.
(I'm not sure about your .collect point; to me that suffers from
exactly the same problem.)
I'm also still troubled by the rather wide net cast by magic
enumerators. I don't think anyone came up with an answer to my
earlier question: When would you ever need this:
some_enumerable.map.other_method
? If the answer is "never", then I don't think map should return an
enumerator.
David
--
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
http://www.manning.com/black => RUBY FOR RAILS (reviewed on
Slashdot, 7/12/2006!)
http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log
(e-mail address removed) => me
irb(main):001:0> RUBY_VERSION
=> "1.9.0"
irb(main):002:0> a, b, c = 3.times.map { Object.new }
=> [#<Object:0x2382c8>, #<Object:0x2381d8>, #<Object:0x238070>]
Interesting.... That reveals that one of the problems with this magic
enumerator thing is that the method names weren't necessarily chosen
with this in mind, and don't work very well. 3.times.map very
strongly does *not* communicate a 0...3 mapping to me. My first
If you think about it, though, the underlying problem is that 3.times
passes a parameter into the block, which is what makes 3.times.map
{|i| } nonintuitive. The plain 3.times.map {} doesn't suggest a 0...3
mapping, but rather an enumerator consisting of three "passes" which
map naturally turns into a 3-object array.
I'm not getting the "naturally" part
non-natural in a sense, but I just can't seem to get my brain to
perceive 3.times as returning something that responds to map this way.
Maybe part of the problem is that it suggests an equivalence between:
[0,1,2].map {}
and
3.times.map {}
which makes it seem like 3.times is return an array. Or something. I
don't even know exactly; it just reads very badly to me.
I predict that this *will* seem intuitive once magic enumerators
have been around a while - note that it already reads perfectly as
3.times.collect
I think that if something has to be around for a while to be
comprehensible, it loses the "intuitive" badge
eventually the process of mentally translating it will get faster....
I guess I'm just used to Ruby semantics not having big gaps, and for
me, there's a big gap between "3.times.map" and mapping across 0,1,2.
(I'm not sure about your .collect point; to me that suffers from
exactly the same problem.)
I'm also still troubled by the rather wide net cast by magic
enumerators. I don't think anyone came up with an answer to my
earlier question: When would you ever need this:
some_enumerable.map.other_method
? If the answer is "never", then I don't think map should return an
enumerator.
David
--
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
http://www.manning.com/black => RUBY FOR RAILS (reviewed on
Slashdot, 7/12/2006!)
http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log
(e-mail address removed) => me