[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Best practices for Ruby Meta-programming

harshal

3/6/2008 4:11:00 AM

Dear all,

Ruby meta-programming is a real fun.
However no power comes without responsibility, so does the Ruby's meta-
programming.
Can anybody share the experiences with meta-programming (for example,
in writing DSLs.) so that if possible we can come up with best
practices?
It would be great if somebody is already aware of such best practices.

Thanks.

Warm regards,
Harshal
12 Answers

Bil Kleb

3/6/2008 1:38:00 PM

0

Hi,

harshal wrote:
>
> Can anybody share the experiences with meta-programming (for example,
> in writing DSLs.) so that if possible we can come up with best
> practices?

Martin Fowler is crafting a book along these lines:

http://martinfowler.c...

Regards,
--
Bil Kleb
http://twitter.co...

James Britt

3/6/2008 6:16:00 PM

0

harshal wrote:
> Dear all,
>
> Ruby meta-programming is a real fun.
> However no power comes without responsibility, so does the Ruby's meta-
> programming.
> Can anybody share the experiences with meta-programming (for example,
> in writing DSLs.) so that if possible we can come up with best
> practices?

Don't be evil.

Don't be stupid.


I think that about covers it.


--
James Britt

www.risingtidesoftware.com - Wicked Cool Coding
www.jamesbritt.com - Playing with Better Toys

Avdi Grimm

3/6/2008 7:20:00 PM

0

On Thu, Mar 6, 2008 at 1:15 PM, James Britt <james.britt@gmail.com> wrote:
> Don't be evil.
>
> Don't be stupid.

So THAT's what I've been doing wrong all this time. Wish someone had
clued me in sooner.

My concrete contribution to this discussion:

Modules are your friend. When tempted to dynamically extend a class
with new methods, consider adding them to a module instead
(potentially a dynamically created module using Module.new). Then use
#include or #extend to add the module to your target. This has a
number of benefits, including:

* Clients can clearly see which which methods come from your
extension vs. the methods that are part of the class itself, by using
Ruby's reflection.
* Clients can override dynamically created methods and still reuse
them with #super() - no need to resort to aliasing.
* A module can be re-used for either class-wide extension or
extending a single object.

--
Avdi

harshal

3/7/2008 3:41:00 AM

0

That's absolutely true.

It reminds me Einstein's quote "Make it simple, no simpler" (or
similar).

I think 'Module'-related suggestion is a good beginning.
Some of the best practices would still be valid from traditional OOAD.

However, the place where Ruby differentiates itself from traditional
programming languages is - Meta-programming.
So I am expecting few 'new patterns' just because of meta-programming.
I could not get any chance to look at the book 'Design patterns in
Ruby'.

Thanks.

Harshal

On Mar 7, 12:19 am, Avdi Grimm <a...@avdi.org> wrote:
> On Thu, Mar 6, 2008 at 1:15 PM, James Britt <james.br...@gmail.com> wrote:
> > Don't be evil.
>
> > Don't be stupid.
>
> So THAT's what I've been doing wrong all this time. Wish someone had
> clued me in sooner.
>
> My concrete contribution to this discussion:
>
> Modules are your friend. When tempted to dynamically extend a class
> with new methods, consider adding them to a module instead
> (potentially a dynamically created module using Module.new). Then use
> #include or #extend to add the module to your target. This has a
> number of benefits, including:
>
> * Clients can clearly see which which methods come from your
> extension vs. the methods that are part of the class itself, by using
> Ruby's reflection.
> * Clients can override dynamically created methods and still reuse
> them with #super() - no need to resort to aliasing.
> * A module can be re-used for either class-wide extension or
> extending a single object.
>
> --
> Avdi

Avdi Grimm

3/7/2008 3:55:00 AM

0

harshal wrote:
> However, the place where Ruby differentiates itself from traditional
> programming languages is - Meta-programming.

If Ruby differentiates itself it's in the form of a particularly
expressive syntax, or maybe in the way it brings an amalgam of different
language features together. Metaprogramming itself is nothing new.
Heck, I used to do metaprogramming in C++.

--
Avdi

M. Edward (Ed) Borasky

3/7/2008 4:05:00 AM

0

Avdi Grimm wrote:
> harshal wrote:
>> However, the place where Ruby differentiates itself from traditional
>> programming languages is - Meta-programming.
>
> If Ruby differentiates itself it's in the form of a particularly
> expressive syntax, or maybe in the way it brings an amalgam of different
> language features together. Metaprogramming itself is nothing new.
> Heck, I used to do metaprogramming in C++.
>
> --
> Avdi
>
>
Hell ... I've done metaprogramming in macro assembler and FORTRAN. ;)

Pedro Del Gallego

3/11/2008 5:11:00 PM

0

> programming (for example,
> in writing DSLs.) so that if possible we can come up with best
> practices?
> It would be great if somebody is already aware of such best practices.

Don't overuse method_missing, it can be conflictive with other
frameworks and dsl in your application.


--
-------------------------------------
Pedro Del Gallego

Email : pedro.delgallego@gmail.com

J.Pascal

5/26/2014 9:31:00 PM

0

On Monday, May 26, 2014 2:51:58 PM UTC-6, Dorothy J Heydt wrote:
> In article <0cf8d03c-7747-4754-b7b9-b5b3b6e1eb9f@googlegroups.com>,
>
> J.Pascal <julie@pascal.org> wrote:
>
> >
>
> >No one ever comes to Bubonicon. You all should come to Bubonicon in
>
> >Albuquerque.
>
>
>
> /e googles Albuquerque altitude
>
>
>
> 5,312 feet. Nope, sorry, I couldn't go there. I don't take high
>
> altitudes well, not since I spent the last day of a convention in
>
> Denver helping to disassemble the art show (the people supposed
>
> to be doing it had disappeared) and, essentially, collapsed. I
>
> didn't recover till our train got us out of the Rockies, over the
>
> Sierras, and down into the near-sea-level Central Valley. Sorry
>
> about that.


We actually live at about 7000 ft. which isn't too bad compared to some. I can tell when we hike to 8000. There seems to be something about 8000 feet because I've talked to other people who say they can tell when they're above or below it. Being above doesn't bother me, but I can tell. My sister started to get really sick and anxious when we took her to the peak (10-ish K) and my youngest is excused forever from going up there because she had a panic attack.

But yes. People don't think of it, but altitude makes a difference.

>
> By the way, why the name? Is plague epizootic there?

Yes. Also, our mascot is a rat.

:)

-Julie


J.Pascal

5/27/2014 4:55:00 PM

0

On Tuesday, May 27, 2014 8:25:07 AM UTC-6, William Vetter wrote:
> On Monday, May 26, 2014 3:10:59 PM UTC-4, J.Pascal wrote:
>
> >
>
> > > > And actually, I learned something really important from you, which was to not resist input on a critique, even though you were the published novelist and we were wanna-bes.
>
> >
>
> I think that I've been unpublished longer than you've been unpublished.
>
> So I can advise you not to regard yourself as "wannabe." I don't think that it's a mindset that will sustain you.

Well, that's true, I think.

This was 15 years ago, though, and at the time I don't think anyone in our crit group had been published at all. I know for certain that at least half of the group got at least short stories published since then. I moved and lost touch.

-Julie

Bill Swears

5/28/2014 4:24:00 PM

0

On 5/27/2014 3:30 AM, Jacey Bedford wrote:
> On 26/05/2014 03:40, J.Pascal wrote:
>> On Sunday, May 25, 2014 8:28:24 PM UTC-6, Dorothy J Heydt wrote:
>>> In article <b9929626-38eb-4dba-a0dd-bf66ad94c280@googlegroups.com>,
>>>
>>> J.Pascal <julie@pascal.org> wrote:
>>>
>>>> Hey! Jo Walton is going to be in my city in four weeks to do a signing.
>>>
>>>> Very cool!
>>>
>>> Indeed. What is your city?
>>
>> I'm in Albuquerque now.
>>
>>>> I'm gonna go meet someone from rasfc in person. I don't
>>>
>>>> know if I've ever actually done that before. Ever.
>>>
>>> Well ... you've met me.
>>
>>
>> ACK! Yes, yes I have! And I got you to sign the books I have, too.
>>
>> And actually, I learned something really important from you, which was
>> to not resist input on a critique, even though you were the published
>> novelist and we were wanna-bes.
>>
>> -Julie
>>
>
> Constructive critique is so important, whatever your level of experience.
> :-)
>
> Jacey
>
And Jo adds one more to Jacey's list of past RASFCerians attending
LonCon3. I've got to find my catvacuuming pin. I know it's around here
someplace....

Bill

--
Bill Swears
http://www.bills...
Zook Country - http://twilighttimesbooks.com/ZookCountr...
Also at Amazon, Barnes and Noble, and other fine ebook emporia.
Puppies - http://www.mtaonline.net...
Opinions - http://wswears.livejo...