views:

1824

answers:

7

What are the key differences between the "python way" and the "ruby way"

A: 

the obligatory answer: passing self all the time in python sucks...

...but I'm not really qualified to answer. I know very little Python. I love Ruby. I would guess that Python has more available in terms of libraries because it's been popular in the Western world for a longer time.

Lex
That's a pretty common complaint I've heard from people who prefer ruby over python. In Python everything should be explicitly defined. If you're not 100% familiar with python and editing some source, you don't have to guess "was it called `this`, or `self`, or whatever".
Gattster
+13  A: 

I've been closely working with both Ruby and Python for over a year now. In my (still non-expert) opinion, these two languages solve the same problem in wildly different ways. Except for some esoteric features of each language, there is nothing you can do in one that cannot be done in the other with some syntactic or conceptual changes, sometimes trivial, sometimes not.

I think the most salient difference between each language is that Python is extremely syntactically simple, and Pythonistas live in the "there is only one way to do it" camp, whereas Rubyists prefer their language's syntactic quirks, and believe that "there is more than one way to do it". Both languages have thriving communities with varying degrees of friendliness.

My suggestion is to get yourself vaguely familiar with both languages--just take a day or week for each of them--and then decide which one fits the cut of your jib more closely.

Max
good answer except for the use of the word 'quirks'.
banister
+1  A: 

Short answer: Neither. Choose the one that fits your development style better.

Here's why I like Python. I've been using Python casually for 6+ years. It is my go-to tool when I need to prototype an app quickly or script something that I do repeatedly. Python has a great community, both online and off (the c.l.python is pretty friendly, and PyCon is one of the best community conferences I've attended.) The libraries are, for the most part, very mature for just about every domain.

That said, I know very little about Ruby. I've had the last edition of the "pick-axe" Ruby book for some time now and have never gotten around to reading, mostly because Python already does what I need it to do.

technomalogical
+2  A: 

For the Python way, check out PEP-20

The Python way is 'this':

import this

The Zen of Python

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Corey Goldberg
+16  A: 

Well, if you really want to know, I'd consult a book called "On Lisp" by Paul Graham, which is available free as a PDF here. Basically, he explains the differences between Lisp and Fortran (the oldest two languages still in use today). I know this may sound irrelevant, but there is a good argument here.

Python

Python is modeled after the Fortran line; there is a clear distinction between expressions and statements, and between code and data. Sure, you can pass functions around like objects, but you can't go inside and change them. This makes it faster, and better suited to top-down programming. It is a lot easier to learn, and to understand when reading it. The philosophy of "there's only one way to do it" means there is no mystery; Ruby and Lisp are full of "tricks" which you can stumble upon by luck, and there is a lot of magic that Ruby employs; Python is explicit in everything. Passing self is no more irritating than having to wrap all of the attributes on your classes with an accessor function.

Whilst it might be faster initially, this does not mean that it is always faster. It's easier to write fast compilers for Python/Fortran/that-sort-of-thing, but you can write super-fast compilers for the Lispier languages too; it's just harder. Ruby have yet to perfect it; I think they're working on it though.

Ruby

Ruby is modeled after Lisp; there is no difference between expressions and statements, and code and data. The most striking commonality is how similar Ruby's blocks are to Lisp's closures. This makes it easier to do metaprogramming (i.e. creating new languages) to solve problems, and so it is more suited to bottom-up programming. At first, it can be slower to run (Ruby's performance right now is atrocious compared to Python), but the Ruby community are working on a virtual machine with some JIT compilation that should bring it up to speed with the other languages.

The thing that Ruby has lost, however, is Lisp's main "love it or hate it" feature: its syntax. Whilst some might argue that the excessive parentheses are annoying, they can be very powerful once you get used to them; Lisp's macros, for example, cannot easily be transferred to Ruby. In this way, Ruby takes some of the concepts of Lisp and applies them to a Fortran-like (well, Algol-like) syntax, and so it does lose some of the power of Lisp. It also makes it even more difficult to read than Python, because the Ruby people have their own little syntax annoyances.

Conclusion

To conclude, I think that Python and Lisp make a good combination (in fact, it's the combo I use). Ruby is just too much of a mixture of methodologies; it will advance at some point in the future, but until it does, it's not a good idea to start learning it; it will take you at least 1-2 years to become proficient, whereas Python will take you a few months only. Those who have a lot of experience with Ruby should stick with it; it's not a good idea to start throwing things out the window.

Anyways, all programming languages are equivalent, so it doesn't really matter. The more you learn, the better: it means you can talk about several approaches, weigh them up, and choose the best one for the job.

zvoase
I don't agree that there is a "there is only one way to do it"-philosophy in Python. There are a lot of tricks to stumble upon in Python as well. That said, a very good answer. +1
JesperE
There are a few ways of doing things, but it is said that there is only one *obvious* way to do it. Often this also means there is only one *conventional* way; but yes, there are several ways (though you should stick to one).
zvoase
There certainly is an "only one way to do it" philosophy in the core language, but there's also "practicality beats purity." The main point of TOOWTDI is not to feed language zealot wars, but to contrast with the philosophy of TMTOWTDI (i.e. Perl).
David Eyk
1-2 years to learn ruby? Are you teaching the prehistoric man coding?
Geo
I thought Python's philosophy was "There should be one-- and preferably only one --obvious way to do it." That's not the same as "there is only one way to do it" .
Gattster
+1  A: 

They're both really pretty interesting beasts that solve the same problems. Python feels a little more mature, and runs faster currently, but there is a lot of momentum in the Ruby community.

Ruby is very object oriented, and has lots of little tricks. It doesn't seem nearly as bad as Perl about having many ways to accomplish things, but does support the notion. There are features I miss from Ruby when writing Python.

Python is very simple, and powerful. It has a very large library to work with, and emphasizes the idea of only one way to accomplish something (making it easier to learn in many ways, and avoids Perl's problem of maintainability).

Personally I lean towards Python, but enjoy the things I've learned from Ruby as well. Either would be good to learn, and you should pobably pick the one that sounds like it suits your style better. If you liked Perl you'll love Ruby. If you liked C you'll love Python.

Enjoy

MattG