[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

pre/post ideas

Charles Comstock

11/28/2003 7:26:00 PM

Hi,

I wonder if it would be possible if we could define a syntax for multiple
targets on a wrapping method.
class A
def meth1
puts "do stuff1"
end

def meth2
puts "do stuff2"
end

def:pre meth1,meth2
log(args)
end
end

Hmm after writing the example it seems like the

def:pre
def:post

style would show the symantics of this idea through the syntax much nicer
then meth1,meth2 :pre or meth1:pre,meth2:pre.

Of course that last syntax exposes interesting concepts about parallel
method assignment to the same block. I suppose at the moment that is taken
care of with alias, but if you have special syntax on def forms then
alias can't apply to all methods anymore.

In addition it would probably lots of things, but it just seems that
You could potentially be adding the same pre, post, or wrap method
to most of the classes methods and some method to chain the definition
would be nice.

Clearly it would have potential issues with method arity and such,
But it seemed an intriguing concept.

As a related note, what would happen if you unbound a pre,post,wrap method.
Or the method they hook onto. It seems some clarification on differences
between methods/procs will be in order because these AOP methods aren't
really either. Are they first class objects as well? Are they full blown
methods? Can you explicitly name a hook and hook it?

I also was thinking that whichever syntax is worked out for this, assuming
some : syntax exists for extensions to def it would also be nice to be able
to overload this, allowing some interesting potential for programmer defined
syntactic forms.

Just some thoughts I had on these ideas that have been bouncing around in my
head.

Charles Comstock

> -----Original Message-----
> From: Yukihiro Matsumoto [mailto:matz@ruby-lang.org]
> Sent: Thursday, November 27, 2003 10:42 PM
> To: ruby-talk ML
> Subject: Re: pre/post question/idea
>
> Hi,
>
> I prefer :pre, :post.
>
> In message "Re: pre/post question/idea"
> on 03/11/28, "David A. Black" <dblack@wobblini.net> writes:
>
> |> Nothing against this idea, just noting how my brain reads Ruby code
> right
> |> now. The x:*** syntax screams special case to me, and this doesn't.
> |
> |My concern is that, as people get used to doing this, x:*** will cease
> |to be a special case, but will still look like one :-)
>
> That's the point. Hooking method is a part of metaprogramming, which
> should be handled with care, even in the future. x:*** are a good
> signs for it.
>
> matz.



2 Answers

matz

11/29/2003 3:12:00 PM

0

Hi,

In message "pre/post ideas"
on 03/11/29, "Charles Comstock" <cc1@cec.wustl.edu> writes:

|I wonder if it would be possible if we could define a syntax for multiple
|targets on a wrapping method.

It would be (and is) covered by AspectR.

|As a related note, what would happen if you unbound a pre,post,wrap method.
|Or the method they hook onto. It seems some clarification on differences
|between methods/procs will be in order because these AOP methods aren't
|really either. Are they first class objects as well? Are they full blown
|methods? Can you explicitly name a hook and hook it?

Auxiliary methods are _not_ first class objects, but they are (along
with primary method) attributes of a methods object.

|I also was thinking that whichever syntax is worked out for this, assuming
|some : syntax exists for extensions to def it would also be nice to be able
|to overload this, allowing some interesting potential for programmer defined
|syntactic forms.

I don't know. Flexibility is not always a good thing. It often leas
language designers into temptation.

matz.


Tim Hunter

11/29/2003 3:24:00 PM

0

On Sun, 30 Nov 2003 00:11:59 +0900, Yukihiro Matsumoto wrote:


> I don't know. Flexibility is not always a good thing. It often leas
> language designers into temptation.
>
> matz.

LOL! Is somebody writing down all these delightful "Matz-isms?" I think
they'd make great subtitles for the next book about Ruby!