天天看点

python元编程运用,使用Python与Ruby进行元编程

python元编程运用,使用Python与Ruby进行元编程

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:

Good metaprogramming. Ability to create classes, methods, functions, etc. at runtime. Preferably, minimal distinction between code and data, Lisp style.

Nice, clean, sane syntax and consistent, intuitive semantics. Basically a well thought-out, fun to use, modern language.

Multiple paradigms. No one paradigm is right for every project, or even every small subproblem within a project.

An interesting language that actually affects the way one thinks about programming.

Somewhat important:

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

Well-documented.

Not important:

Community size, library availability, etc. None of these are characteristics of the language itself, and all can change very quickly.

Job availability. I am not a full-time, professional programmer. I am a grad student and programming is tangentially relevant to my research.

Any features that are primarily designed with very large projects worked on by a million code monkeys in mind.

解决方案

There's not really a huge difference between python and ruby at least at an ideological level. For the most part, they're just different flavors of the same thing. Thus, I would recommend seeing which one matches your programming style more.