Python vs. Ruby for metaprogramming

dsimcha picture dsimcha · Sep 28, 2008 · Viewed 34k times · Source

I'm currently primarily a D programmer and am looking to add another language to my toolbox, preferably one that supports the metaprogramming hacks that just can't be done in a statically compiled language like D.

I've read up on Lisp a little and I would love to find a language that allows some of the cool stuff that Lisp does, but without the strange syntax, etc. of Lisp. I don't want to start a language flame war, and I'm sure both Ruby and Python have their tradeoffs, so I'll list what's important to me personally. Please tell me whether Ruby, Python, or some other language would be best for me.

Important:

  1. Good metaprogramming. Ability to create classes, methods, functions, etc. at runtime. Preferably, minimal distinction between code and data, Lisp style.
  2. Nice, clean, sane syntax and consistent, intuitive semantics. Basically a well thought-out, fun to use, modern language.
  3. Multiple paradigms. No one paradigm is right for every project, or even every small subproblem within a project.
  4. An interesting language that actually affects the way one thinks about programming.

Somewhat important:

  1. Performance. It would be nice if performance was decent, but when performance is a real priority, I'll use D instead.
  2. Well-documented.

Not important:

  1. Community size, library availability, etc. None of these are characteristics of the language itself, and all can change very quickly.
  2. Job availability. I am not a full-time, professional programmer. I am a grad student and programming is tangentially relevant to my research.
  3. Any features that are primarily designed with very large projects worked on by a million code monkeys in mind.

Answer

S.Lott picture S.Lott · Sep 28, 2008

I've read up on Lisp a little and I would love to find a language that allows some of the cool stuff that Lisp does, but without the strange syntax, etc. of Lisp.

Wouldn't we all.

minimal distinction between code and data, Lisp style

Sadly, the minimal distinction between code and data and "strange" syntax are consequences of each other.

If you want easy-to-read syntax, you have Python. However, the code is not represented in any of the commonly-used built-in data structures. It fails—as most languages do—in item #1 of your 'important' list. That makes it difficult to provide useful help.

You can't have it all. Remember, you aren't the first to have this thought. If something like your ideal language existed, we'd all be using it. Since the real world falls short of your ideals, you'll have to re-prioritize your wish list. The "important" section has to be rearranged to identify what's really important to you.