tags:

views:

1682

answers:

11

Hi,

I am a C++ developer, slowly getting into web development. I like LISP a lot but don't like AllegroCL and web-frameworks available for LISP. Which one is closer to LISP: Python or Ruby? I am looking for more freedom and ability to do cool hacks on language level. I don't consider tabs as a crime against nature.

I can't seem to be able to choose from Python and Ruby: they seem very similar but apparently Ruby is more functional and object-oriented (which are good things) while Python is more like Perl: a simple scripting language. Do I have the right impression?

Thanks,

Olek

PS. This might seem like a flamebait but it's not really, I'm just trying not to go crazy from OCD about switching from RoR to Python/Django and back.

+12  A: 

I'd go with Ruby. It's got all kinds of metaprogramming and duck punching hacks that make it really easy to extend. Features like blocks may not seem like much at first, but they make for some really clean syntax if you use them right. Open classes can be debugging hell if you screw them up, but if you're a responsible programmer, you can do things like 2.days.from_now (example from Rails) really easily (Python can do this too, I think, but with a bit more pain)

PS: Check out "Why Ruby is an acceptable LISP".

zenazn
Actually, blocks in Ruby are magic if you are used to functional programming.
ewalshe
I've added article's title.
J.F. Sebastian
+20  A: 

Peter Norvig, a famous and great lisper, converted to Python. He wrote the article Python for Lisp Programmers, which you might find interesting with its detailed comparison of features.

Python looks like executable pseudo-code. It's easy to pick up, and often using your intuition will just work. Python allows you to easily put your ideas into code.

Now, for web development, Python might seem like a more scattered option than Ruby, with the plethora of Python web frameworks available. Still, in general, Python is a very nice and useful language to know. As Ruby and Python's niches overlap, I agree with Kiv that it is partly a matter of personal taste which one you pick.

namin
I was in the midst of posting this link when you put it up :)
Kiv
Ruby has all the advantages that Norvig attributes to Python.
ewalshe
+2  A: 

I also recommend the article by Peter Norvig that namin posted. If you want to look at functional programming in Python check out the functools module in the standard library.

There is also a lot of room to hack around in Python; private variables are by convention and not enforced, so you can poke around in the internal state of objects if you feel like it. Usually this is not necessary, though.

Both Ruby and Python are very object-oriented and support functional programming; I wouldn't say either one is clearly superior for your project; it's partly a matter of personal taste.

Kiv
+11  A: 

Speaking as a "Rubyist", I'd agree with Kiv. The two languages both grant a nice amount of leeway when it comes to programming paradigms, but are also have benefits/shortcomings. I think that the compromises you make either way are a lot about your own programming style and taste.

Personally, I think Ruby can read more like pseudo-code than Python. First, Python has active whitespace, which while elegant in the eyes of many, doesn't tend to enter the equation when writing pseudo-code. Also, Ruby's syntax is quite flexible. That flexibility causes a lot of quirks that can confuse, but also allows code that's quite expressive and pretty to look at.

Finally, I'd really say that Ruby feels more Perl-ish to me. That's partly because I'm far more comfortable with it, so I can hack out scripts rather quickly. A lot of Ruby's syntax was borrowed from Perl though, and I haven't seen much Python code that feels similar (though again, I have little experience with Python).

Depending on the approach to web programming you'd like to take, I think that the types of web frameworks available in each language could perhaps be a factor in deciding as well. I'd say try them both. You can get a working knowledge of each of them in an afternoon, and while you won't be writing awesome Ruby or Python, you can probably establish a feel for each, and decide which you like more.

Update: I think your question should actually be two separate discussions: one with Ruby, one with Python. The comparisons are less important because you start debating the merits of the differences, as opposed to which language will work better for you. If you have questions about Ruby, I'd be more than happy to answer as best I can.

nakajima
You must have written some other kind of pseudocode than the one I've seen so far, if significant whitespace and pseudocode are not related.
ΤΖΩΤΖΙΟΥ
+5  A: 

Both Ruby and Python are fairly distant from the Lisp traditions of immutable data, programs as data, and macros. But Ruby is very nearly a clone of Smalltalk (and I hope will grow more like Smalltalk as the Perlish cruft is deprecated), and Smalltalk, like Lisp, is a language that takes one idea to extremes. Based on your desire to do cool hacks on the language level I'd go with Ruby, as it inherits a lot of the metaprogramming mindset from Smalltalk, and that mindset is connected to the Lisp tradition.

Norman Ramsey
+5  A: 

Alex Martelli gives a good analysis of the subject. It's a bit dated now, but I agree with the basic gist of it: Python and Ruby are two different ways of implementing the same thing. Sure there are some things you can do in Ruby that you can't do in Python. And sure Python's syntax is (arguably) better than Ruby's. But when you get down to it, there's not a whole lot of objective, scientific reason to prefer one over the other.

A common thing that you will hear is this: the platform is more important than the language and Python has a better platform than Ruby (this argument works both ways so don't vote me down, all you rubyists). And there is some truth to it. Unfortunately, it's not very relevant though. If you dislike the platform for either languages, there are implementations of both in Java and .Net, so you can use those if you have concerns about the platform.

Jason Baker
A: 

If you need Unicode support, remember to check how well supported it is. AFAIK, Python's support for Unicode is better than Ruby's, especially since Python 3.0. On the other hand, Python 3 is still missing some popular packages and 3rd party libraries, so that might play against.

Adriano Varoli Piazza
+7  A: 

Devils Advocate: Who Cares?

They are both good systems and have an ecosystem of good web frameworks and active developer communities. I'm guessing that you're framing your decision based on the wrong criteria. The question sounds like you're fretting about whether you will hit implementation problems or other difficulties by choosing one over the other. Don't.

This is similar to Java/.Net decisions. There may be compelling reasons in a specific instance, but soft factors like the architect's familiarity with the platform are a much stronger predictor of project success.

I will admit that I've used Python much more than Ruby, but I wouldn't say that I have any great preference between the two apart from familiarity. I've used Python off and on since about 1998 and I like the Smalltalkish-ness of Ruby as I used Smalltalk briefly about 15 years ago. They both do similar things slightly differently.

I would like certain features from Ruby (or Smalltalk for that matter) but Python doesn't work that way. Instead, it has other features and language idioms are slightly different from Ruby or Smalltalk. Several of the other posters have linked out to articles that compare the two.

If you're worrying about Rails vs. Django, that suggests you're looking for a platform for web applications. Both languages have good tool support and an active developer community. Django seems to be the winner of the Python web framework melee and Rails seems to be in the process of 'crossing the chasm' and bringing Ruby along with it. Both are reasonably mature systems and have been demonstrated to work well for respectable traffic volumes.

ProTip: The presence of religious wars is a good indicator that neither side has a compelling arguement.

So, I'm going to play devil's advocate and say that worrying about the choice is pointless. The languages have advantages and disadvantages with respect to each other but nothing that could be viewed as compelling in the general case. Fretting about the detailed merits of one platform or the other is framing the decision wrongly.

Pick one and use it. You will be able to build systems effectively with either.

ConcernedOfTunbridgeWells
+1 for the insightful ProTip.
Andrzej Doyle
+2  A: 

I am a Pythonista; however, based on your requirements, especially the "cool hacks on the language level", I would suggest you work on Ruby. Ruby is more flexible in the Perl way and you can do a lot of hacks; Python is targeted towards readability, which is a very good thing, and generally language hacks are a little frowned upon. Ruby's basic types can be modified in a hackish way that typically prototype languages allow, while Python's basic types are more suited for subclassing.

By the way, I would add a minor correction: both Ruby and Python are very, very object-oriented, and neither is intended to be used for quick-and-dirty scripts the Perl way. Among the two, Ruby is syntactically more similar to Perl than Python.

ΤΖΩΤΖΙΟΥ
A: 

I'm a Rubyist who chose the language based on very similar criteria. Python is a good language and I enjoy working with it too, but I think Ruby is somewhat more Lispy in the degree of freedom it gives to the programmer. Python seems to impose its opinions a little bit more (which can be a good thing, but isn't according to our criteria here).

Python certainly isn't more Perlish— Ruby is essentially a Smalltalk/Perl mashup (some of its less-used features are pulled directly from Perl), whereas Python is only distantly related to either.

Chuck
A: 

pick the most popular one for your domain so your work gets the most visibility. some might say ruby/rails for web, python for everything else. picking a language just because its like lisp is really not appropriate for a professional.

Dustin Getz