
Ruby or Python? Well, it depends... - hanszeir
http://batsov.com/2011/05/03/ruby-or-python.html
======
lloeki
_"but python + any python IDE < Java + IntelliJ IDEA(Eclipse/NetBeans)"_ (and
I suppose s/python/ruby/g and s/Java/C#/g too)

I don't quite agree with this statement as I find python and ruby development
easy, perfectly usable and well performing in a generic code editor (vim,
emacs, textmate) whereas doing Java or C# almost mandates a full-blown
heavyweight IDE with smart code completion like IntelliSense to get anywhere
near the same efficiency. I've tried a few IDEs for python and ruby, and they
seemed almost more of a hindrance than a help, and definitely not a
significant improvement.

~~~
StavrosK
This has been my experience as well. IntelliSense, import resolution, auto
refactoring etc are all good, but I always find myself going back to vim
because I've finished editing by the time eclipse starts up...

------
lloeki
Python's REPL has autocompletion. It is just not enabled by default as it
lives in its own module and python prefers to start in an absolutely clean
state.

    
    
        >>> import readline
        >>> import rlcompleter
        >>> readline.parse_and_bind('tab: complete')
    

See this article for the details (and more, like history persistence and REPL
startup file): [http://valueerror.wordpress.com/2009/11/03/python-shell-
hist...](http://valueerror.wordpress.com/2009/11/03/python-shell-history-
autocompletion-and-rc-file/)

~~~
StavrosK
Who doesn't use ipython these days, though?

~~~
arctangent
I've read about it but never used it - I write all my code in TextMate,
Notepad++ or Nano, depending on where I am and what I'm doing.

Could you outline what you see are the main benefits of using an enhanced
interactive interface to Python such as IPython?

~~~
lloeki
It actually makes python a full-blown shell (which python REPL is not):

    
    
        $ ipython
        Leopard libedit detected.
        Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
        Type "copyright", "credits" or "license" for more information.
        
        IPython 0.10.1 -- An enhanced Interactive Python.
        ?         -> Introduction and overview of IPython's features.
        %quickref -> Quick reference.
        help      -> Python's own help system.
        object?   -> Details about 'object'. ?object also works, ?? prints more.
        
        In [1]: ls
        Applications/ Downloads/    Movies/       Public/       Workspace/
        Desktop/      Dropbox/      Music/        Sandbox/
        Documents/    Library/      Pictures/     Sites/
        
        In [2]: ls | grep App
        Applications/
        
        In [3]:

------
latch
Python and Lua were the first languages I used that had tuples as a
native/core/whatever type. Absolutely love them. Changes how you program sorta
thing. Mind blown that every language doesn't have them.

Despite this, I can't get into Python (having tried 3 or 4 times the last
couple years). The Ruby ecosystem is simply more polished...gem, rvm,
capistrano, rails, sinatra bundler, .... I really tried to fall in love with
Python/Django, and it just isn't as good as Rails by a wide margin.

When languages are as close as Ruby and Python (or C# and Java),
frameworks/ecosystem/community matters a ton more.

~~~
lloeki
I suppose some things fit in one mental's model more easily whereas others
don't, and there's no reason to contrive yourself in doing so, especially
given how close Python and Ruby are in the general landscape of all
programming languages.

For reference, each element of the Ruby ecosystem has a similar Python
counterpart.

\- gem -> easy_install or pip

\- rvm -> virtualenv

\- capistrano -> fabric

\- rails -> django

\- sinatra -> itty, bottle, web.py, or twisted http module

\- bundler -> setuptools (install_require directive)

also,

\- rake -> scons, paver

\- rspec -> unittest / unittest2 /nose

\- watchr -> autonose

\- rdoc markdown -> docstrings+restructured text

Of course they're not 1:1 mappings, but python itself is not a 1:1 mapping to
ruby, and any project is not a 1:1 mapping to any other project aiming to
solve the same task either.

Admittedly it seems that Rails pushed Ruby more towards web development
resulting in some more polish, whereas Python became more of a generalist, but
that's a slight advantage either way, and they are definitely not worlds
apart.

~~~
latch
As I said in another comment..my easy_install/pip experience wasn't polished,
but yes, that might just be me.

The rails -> django thing is where I'm not so humble. It didn't take me more
than 5 minutes of doing Windows Mobile (6) programming to know that it sucked.
Django doesn't suck (no way), but it isn't where Rails is. And I really think
that, if you're doing web dev, the web framework is as important as all the
other smaller pieces (package management, deployment, ...) put together.

~~~
jessedhillon
Some people like magic, and some people like underscores. That's why they make
chocolate _and_ vanilla ice cream flavors. I don't think the goal of the
Django team is to ever get to where Rails is, there are plenty of other
frameworks trying to do that.

------
bajsejohannes
> Ruby and Python do not have statements - only expressions.

Unfortunately this is not true for python. The reason his print-example
doesn't show the returned value is that there isn't one. In ruby, puts
actually returns Nil, and we can assign it:

    
    
         >> x=puts(0)
         0
          => nil
    

Whereas in Python, we get a syntax error

    
    
         >>> x=print(0)
           File "<stdin>", line 1
             x=print(0)
                   ^
         SyntaxError: invalid syntax

~~~
andrewcooke
that's fixed in python 3

[edit: sorry, yes, i agree the general problem remains.]

~~~
bajsejohannes
For the specific example of print, then yes. But in general it is not. Another
example is if-statements in python:

    
    
        >>> x=if True:
          File "<stdin>", line 1
            x=if True:
               ^
        SyntaxError: invalid syntax
    

whereas in Ruby:

    
    
         >> x=if true:
         ?>   5
         >> end
         => 5
    

Other Python statements from the top of my head: for, while, def, import.

My point is that there absolutely are statements that are not expressions in
Python. (You can easily tell by trying to assign the return value:
x=<statement>).

~~~
kbd
Heck, assignment itself is a statement. That's why you can't say while x=y:
... (and you'll notice the REPL gives no return value for an assignment).

This "Python has no statements" error was one of my biggest annoyances with
this article, as Python has a very strong statement vs expression dichotomy.

------
edanm
"If you’re looking for a flame post - this is not one of them. I love both
languages and I’ll simply compare some of their features and possible uses."

This was an interesting post, and I'm sure the op didn't mean any of it as a
"flame". Problem is, on a lot of the comparisons, the op just said "I won't
get into this, but I prefer Python" (or Ruby, depending on the feature). Those
kinds of statements don't really advance anyone's knowledge, but are sure to
get some people annoyed.

As someone who uses Python but hasn't learned Ruby, this article got me to the
same conclusion I alway get - while Ruby has a few very interesting
differences and clever tricks I'd love to learn, it's so similar to Python
that I'm better off learning a completely different language.

One thing I think is tiny, but incredibly helpful in Ruby, and I don't
understand why more languages don't have it - the ability to add "?" and "!"
to operators. That's an actually useful convention.

~~~
tesseract
> One thing I think is tiny, but incredibly helpful in Ruby, and I don't
> understand why more languages don't have it - the ability to add "?" and "!"
> to operators. That's an actually useful convention.

My primary languages are Ruby and C. After working in Ruby for a while and
then switching back to C I often find myself naming predicates with a trailing
_q. I don't have an equivalent for !, though.

~~~
edanm
In C/C++, I was usually in the habit of adding "Is" in front of predicates.
"something.IsDone()", "something.IsOver()", etc.

------
ctide
I thought it was a pretty good article until I got to:

"Since they are often used for the creation of webapps one should consider the
deployment issue. Most web hosting companies provide cheap Python hosting, but
very few companies provide Ruby hosting."

Which pretty much killed it. Doesn't Heroku alone pretty much blow this
statement away?

~~~
iamscanner
> Doesn't Heroku alone pretty much blow this statement away?

Not really - he said "very few", not "there aren't any". You can find
mod_python all over the place - where are your shared ruby hosting options?

~~~
ctide
I just mean that it implies that finding cheap hosting for a ruby webapp is
problematic. If the purpose of that statement is to say that more places will
support Python than Ruby, then it should probably be worded differently.

~~~
tesseract
Heroku may be a good value for what it is, but it's vastly more expensive than
a lot of entry-level shared hosting services - you know, the kind of place
that starts at $5 or $10 per month and runs cPanel or an equivalent. Lots of
those support Python these days; Ruby support still seems to be much rarer.

~~~
danenania
Heroku's free hosting is leaps and bounds beyond what a typical $5-$10 shared
host offers, and there's an easy upgrade path. Sure, you can come up with
specific usage levels where a shared host is cheaper on a bit-to-dollar basis,
but you're still not accounting for Heroku's main selling point: convenience
and saving developer time. This plus the fact that the vast majority of sites
on $5-$10 shared hosting would fit easily on Heroku's free plan means that
value-wise, Heroku faces much stiffer competition from Linode than any shared
provider.

I like and am comfortable with both Python and Ruby, and one of the biggest
reasons I choose Rails for projects nowadays is Heroku, and I'm not alone.
Given this, I really don't see how you could claim Python has any edge when it
comes to hosting. If you're concerned about what tons of shared hosting
providers have installed, why not just use php?

------
jessedhillon
> _Ruby’s REPL(irb) seems to me more advanced since it allows you to do TAB
> smart completion(amongst other things)._

You can easily have tab completion and a bunch of other good stuff (like
preserving history across sessions) with the Python REPL. You have to use the
PYTHONSTARTUP environment variable to indicate a script that is run when the
Python shell begins, and that script has to use adjust some rlcompleter and
readline setttings.

It's all right here: <http://docs.python.org/library/rlcompleter.html>

Incidentally, this is the first result on Google for "python tab completion"

