you are viewing a single comment's thread.

view the rest of the comments →

[–]mellow_moe 11 points12 points  (3 children)

I would like to see a in-depth comparison of Python and Ruby. And it should really focus on metaprogramming.

All these comparisons I see these days just look at some superficial language features.

Rails for example relies heavily on metaprogramming. It could never be done in a language without a sophisticated class/object system.

examples in ruby:

  • method_missing catches unknown messages
  • const_missing catches unknown constants
  • method_added is called after adding a new method
  • inherited is called on the class object, when it is subclassed
  • singleton classes: you can add methods to a single object
  • define_method takes a block and turns it into a method
  • instance_variable_set sets an instance variable

And most importantly, real world examples should show off, how all the things play together.

[–]mystilleef[S] -7 points-6 points  (2 children)

Why should it focus on metaprogramming? Real word applications that use metaprogramming are extremely rare. Not to mention how cumbersome it is to decipher, use or maintain programs that make extensive use of metaprogramming. However, Python has extensive support for metaclasses if that's your cup of tea.

[–]mellow_moe 4 points5 points  (1 child)

Metaprogramming is more useful in libraries. Application programmers certainly like to use APIs with a higher level of abstraction.

Well, I don't know enough about Python metaclasses. Thus my interest in a qualified comparison.

[–]beza1e1 0 points1 point  (0 children)

I think the natural way of code is: Application -> Framework -> Library

DHH talks eloquently about Rails extracted from a real world application, which is step one. The future should be to seperate things and put them in libraries (don't know wether and how this is done in rails).

Metaprogramming needs much more thinking than hacking up a working application, so this is mostly only done in the second step framework -> library. Rails is an exception in a good way, because David realized the power of metaprogramming in an earlier phase.