From: dblack@... Date: 2006-09-29T20:33:39+09:00 Subject: Re: New magical version of Symbol.to_proc Hi -- On Fri, 29 Sep 2006, Dr Nic wrote: >> My problem with something like this: >> >> x.should.be.equal.to(y) >> >> It's very hard to know what "x.should.be" returns. I can figure it >> out, of course. But it has a tone of "don't worry about what's >> actually happening; just read the dot-connected words like a string", >> which makes me uncomfortable. > > This would be readable assuming that "should" on x meant something. If I > saw this I'd guess its like "assert". > > But, assuming that your list of words DID mean something, then it has to > be more readable to newcomers (and yourself in 12 mths time) than the > possible equivalent: The intent is very clear, I think. I just don't like the construct :-) > x.each {|an_x| assert_equal y, x} > > or to rephrase the example, perhaps: > > x.should {|an_x| an_x.be :equal, :to, y} I think my example, in (say) TestUnit, would be more like: assert_equal(y,x) But as I said, the magic dot example was made up, so I can't really push the point of what it would be equal to in other terms. > The magic dot gives you left-to-right readability, whereas the above > makes you figure out whats happening in the closure first, then go back > to the x.each part to see where an_x comes from. I can't really comment without hooking my eyes up to a machine and seeing where they go :-) But there's no necessity to backtrack once you've seen x.each {|an_x|, from the point of view of understanding the code. Mind you, the magic dot doesn't require backtracking either. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org