[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Best practices for Ruby Meta-programming

John Carter

3/11/2008 4:31:00 AM

On Mon, 10 Mar 2008, Robert Dober wrote:

> attr_reader e.g. is nothing less than MP.

I'd still be happier if I could flick a switch and see the
intermediate vanilla code that was generated.

> FWIAC metaprogramming is here to do things at runtime and nothing else
> in the world can replace it.

I suspect we've overloaded the term "meta-programming".

There are "programs that write programs".

There is a common subset of that ... "programs that instantiate
generic template code by substituting template variables with concrete
text."

If by meta-programming you mean one of the meanings above this line,
seeing a concrete vanilla ruby intermediate representation is
invaluable.

----------------------------------------------------------------------

If by meta-programming you mean one of the following, creating
concrete intermediate representations is harder..., but certainly not
impossible.

There are "programs that query & display the current run time state of
the program". (Profiling, debugging, coverage, memory profiling & leak
detection, object creation hotspot detection...)

There are _very_ hairy programs "that query the current run time state
of the program and modify the code 'on-the-fly' accordingly."

> You know sometimes it is just the right tool to use, *sometimes*.

Their are times and places where on-the-fly self-modifying code is
appropriate.

They are clearly marked on the map as "Here be Dragons".

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand


1 Answer

Robert Dober

3/11/2008 11:01:00 AM

0

On Tue, Mar 11, 2008 at 5:31 AM, John Carter <john.carter@tait.co.nz> wrote:
You are certainly right that MP is overused here, I have read slightly
different definitions of which I like best:
"Programming for the Programmer.

def attr_reader *atts
atts.each do |att|
define_method att do instance_variable_get "@#{att}" end
end
end

is definitely for the programmer, it also should rather run at runtime
than at compile time.

Robert


--
http://ruby-smalltalk.blo...

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein