Hacker News new | past | comments | ask | show | jobs | submit login

Calling the examples just "fist-class functions" is being reductionist. The examples programmatically change the structure of the code. That fits the definition from Wikipedia:

Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data ...




It's not manipulating the program as data. It is simply the program itself. If the program runs with its output being another program which runs, then that is a form of metaprogramming. In this case, the program is simply running. A collection of functions which accept arguments and return values directly is not what most people would consider metaprogramming. It's just a program.

JavaScript is entirely capable of doing metaprogramming, but in the article posted here, it does not.


It's adding structure (methods to classes) at runtime which normally would require writing source code. That is treating the program as data; it manipulates the object system as any other kind of data.

You seem confident that your definition of metaprogramming is the accepted definition, but I don't see evidence of that.


"It's adding structure (methods to classes) at runtime which normally would require writing source code."

-- the linked blog post doesn't do this, though it is possible.


Then what is this?

  sword_symbol = "*********"
 
  drew.metaclass.send(:define_method, 'swing') do |sound_effect|
    puts "#{name}: #{sword_symbol} #{sound_effect}"
  end
 
  drew.swing 'slash!!'
I understand that to add the swing method without writing the source code to do it. This use is trivial, but it's easy for me to extrapolate to how one could make the newly created method depend on runtime information.


Ruby, not javascript.




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

Search: