Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"If normal programming constructs did not allow the programmer to choose behavior based on input, then every program would have a fixed execution path, would have the same output every time. and metaprogramming itself would not be possible."

There is a difference between program control flow based on user input and generating program logic during the course of execution.

I posit that you may have metaprogramming in a progam that has the same output every time.

To me, metaprogramming is writing code which generates or modifies behavior, logic or program flow control. This may happen at compile or run time. Wether generating a closure and setting an attribute on a JS object or using "eval" to define the function, the effect is the same -- the object's implementation was not defined by the original source or environment.

For instance, this is metaprogramming:

def decorate(obj) obj.send :define_method, :yay, (Proc.new{ puts "woohoo!"}) end

a = File.open('tmp.txt','w')

decorated_a = decorate(a) a.yay

Here, there is no eval, but a's implementation changes at runtime. The same is trivially reproduced in JS.

edit: the difference between the original article and this is that the original article makes modifications directly to the original objects, and not to arbitrary objects, which i suppose is why you object to referring to this as meta-programming.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: