Thursday, August 26, 2010

Ruby vs Python

Alex Martelli, the guy who spearheaded the Python Cookbook has a nice essay on Python vs Ruby.



It hits on a lot of the things I’ve noticed between the the two languages.  They’re very similar, far more similar than you’d think at first glance; both allow a great degree of metaprogramming (though admittedly, Ruby’s is far more prevalent and pervasive) , both allow people to put things into production with pretty straightforward syntax, and both kick the crap out of Perl.



The biggest differences that Martelli highlights are things I’ve noticed, too - there are little syntax nits, but the big issues are the level of metaprogramming allowed, and iterators/codeblocks vs iterators/generators (and I’d throw decorators in there, too).  Ruby allows you to open anything up, and while that can be nice in some scenarios, it could be a nightmare in large scale projects.  Python still lets you clobber builtins, but you can’t, for instance, open up the Python 3 str class and edit it, outside of subclassing.



It’s far more common in Ruby to crack open a class and do stuff with it; Rails is fundamentally built on that.  Python lets you do that, but I just don’t run into it as much in actual code.  There’s some, but it’s closer to the straight-forward C-style stuff.  Perhaps it’s the projects and code I’ve encountered, I dunno.  But, for contrast, Pylons and Django are far more comfortable with requiring the programmer to use them as libraries, rather than the DSL-ness of Rails.



Ultimately, between the two it’s really a matter of taste.  Yes, that applies to all programming languages, but Python and Ruby are close enough to each other that it’s more down to taste than one of those compared to say, Java or C.



All that said, I’ll continue to use and learn what I can about both.    Sometimes, an idea can be more easily expressed in different syntax, and that’s ok.


No comments:

Post a Comment