New magical version of Symbol.to_proc

Dr Nic wrote:

You're quoting techniques need some practise! I don't think I said that
:slight_smile:

My ability to spell needs some practise.

"Your" instead of "You're"... doh!

···

--
Posted via http://www.ruby-forum.com/\.

Robert Dober wrote:
[ Missing ] : Trans <...> wrote

--

>> Posted via http://www.ruby-forum.com/\.
>>
>> I'll have a look at T's link but it is a truely interesting discussion.

You're quoting techniques need some practise! I don't think I said that
:slight_smile:

Indeed, indeed, I deleted the "Trans wrote", I am very bad at that, sorry
for the confusion

It is for the first time that I hear that very honorable members of the
> community dislike this feature.
> For me it was the most intreaging of Ruby at all (at the beginning)
> I recall my old Python code
>
> something.get_other().do_stuff().transform()
>
> Terrible, it is only now that I realize that the concept of writing code
> like this might be flawed, there are OTOH strong indications that it is
> not
> so flawed too. E.g. lots of programing conventions asking for methods to
> return objects.
> Now, to complicate things even more, very often that object is "self",
> personally I find the idea to return other objects, especially proxy
> objects
> to self, very intriguing, the idea came to me when I looked at the BDD
> video cast.

In Smalltalk all methods return self unless they return something else,
thus inferring that something.get_other().do_stuff().transform() (using
Smalltalk syntax :slight_smile: is common.

In JQuery - the javascript library - everything is centered around a
"jquery" object which holds 1+ dom objects in it. All methods on the
jQuery object should return that same set of objects (via the jQuery
object container) so that you can chain method calls.

The idea of returning a proxy object (in the Magic Dot example of
.map.lengths) was very nifty. It works the normal way AND works in the
magical way.

Thx :wink: credits go to BDD of course

The more and more examples I see and concoct myself like this the more I

am happy to give up the core assumptions of "object oriented
programming" etc, and adopt "happy syntax programming". Syntax that
reads nicely and makes sense as to what it will do and what it will
return.

You are heading for the future, I'll try to keep up with your ideas.

Now if I could just get the code I originally wrote to work on

ActiveRecord associations I'd be such a happy camper. I'm in love with
that syntax.

Nic

--
Posted via http://www.ruby-forum.com/\.

Robert

···

On 9/29/06, Dr Nic <drnicwilliams@gmail.com> wrote:

> On 9/29/06, Dr Nic <drnicwilliams@gmail.com> wrote:

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

Hi --

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
:slight_smile:

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 :slight_smile: 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

···

On Fri, 29 Sep 2006, Dr Nic wrote:

--
                   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] Ruby for Rails | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

David wrote

I don't think anyone objects to method-chaining in every case. My
dislike is for method chaining that, to my eye and brain, is just a
way of composing a longer method name (or something that could be done
by passing in arguments representing conditions) with dots.

Your.mileage.may.vary :slight_smile:

I.see.your.point.emphasis_start.now.emphasis_end
Now that would be abuse of course, mixing content and presentation.

David I am sincerely sorry that my posts -always a bit odd, always a bit
funny [ in both senses of the word ] - have given you the impression that I
wanted you to explain something.

I am, and all other regular readers are, well aware that your Ruby level is
way above mine and even I understand the magic dot notation :slight_smile:

As a matter of fact I took your concerns, and Tom's [ I'll come back to that
later ] very seriously and did not understand them in the first place.

You made a very good point in your last mail, but again I had the feeling
that I had inadevertly insulted you, it was *not* my intent.

So we have the tool, and as always there is danger with power, Tom's link to
the Object Adapter Pattern fits very well and when getting into that
paradigm one might as well adapt more towards method chaining than before,
even with some small magic.

Tom's attitude "I do not like that", "other people like that", "hmmm why do
they like it?",
"hmm maybe because they see it differently, let us do some research", "see
that is interesting" is truely admirable and very productive.
I try to mimmick that attitude for sure :slight_smile:

OTOH one has to look out for code that is not too clear, we are starting a
very philiosophic thread here, sorry folks, I thaught BDDs paradigm change
was too radical too, but I think that is because I am very conservative (c.f.
my POV towards ducktyping).

Those of us who want always to understand - count me in for 100% - might
sometimes fall into the trap of not allowing certain abstractions to take
place because, we cannot - even the smartest - immediately understand them.
It is a truely difficult process to decide if a new paradigm is worth
exploring and I am more than glad to have nice, competent people here
talking about their paradigms and ideas.

Nuff said for today.

Cheers
Robert

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] Ruby for Rails | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

Hi --

···

On Fri, 29 Sep 2006, Robert Dober wrote:

David wrote

I don't think anyone objects to method-chaining in every case. My
dislike is for method chaining that, to my eye and brain, is just a
way of composing a longer method name (or something that could be done
by passing in arguments representing conditions) with dots.

Your.mileage.may.vary :slight_smile:

I.see.your.point.emphasis_start.now.emphasis_end
Now that would be abuse of course, mixing content and presentation.

David I am sincerely sorry that my posts -always a bit odd, always a bit
funny [ in both senses of the word ] - have given you the impression that I
wanted you to explain something.

I am, and all other regular readers are, well aware that your Ruby level is
way above mine and even I understand the magic dot notation :slight_smile:

As a matter of fact I took your concerns, and Tom's [ I'll come back to that
later ] very seriously and did not understand them in the first place.

You made a very good point in your last mail, but again I had the feeling
that I had inadevertly insulted you, it was *not* my intent.

No, I didn't get that impression in the slightest. I'm just doing my
usually thing of burrowing down into Ruby stuff and seeing what's
there -- nothing personal riding on it.

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] Ruby for Rails | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

[David] wrote:

No, I didn't get that impression in the slightest. I'm just doing my
usually thing of burrowing down into Ruby stuff and seeing what's
there -- nothing personal riding on it.

Ruby is great for burrowing. Java is bad. I remember burrowing in Java
and you always end up at something "final"; something you'd LIKE to
override or extend but you're not allowed for reasons unknown.

Now we are officially OT. :slight_smile:

Nic

···

--
Posted via http://www.ruby-forum.com/\.