Ruby or Python? Well, it depends...
batsov.com
batsov.com
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.
>>> 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...Could you outline what you see are the main benefits of using an enhanced interactive interface to Python such as IPython?
$ 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]:Its advantage over the stock Python repl is that it has better code completion, colours, pretty printing, nice history, built-in profiling and many other niceties I enjoy.
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.
This is exactly why I use Python over Ruby: scipy, numpy, matplotlib, etc.
The right language + ecosystem will obviously be very domain dependent.
I can tell you my last expedition in Python land was bad. I ran into two problems: upgrading the version of Python that came on my Air and installing MongoEngine. For MongoEngine I used the instructions on their website "easy_install -U mongoengine". And after a bit of googling (I say a bit because a lot of people were having the same problem I was) I ended up installing PIP (via easy_install no less!) and then got into pathing problems.
Having to use one package manager to install a better package manager isn't polish. Again, I can agree that this might all just be familiarity and comfort (or lack of in this case).
I'm not so open to Django vs Rails though. I don't need to do a lot of struts to see how horrible it is (compared to anything). I don't need to do a lot of Django to see that it's behind Rails as a productive web frameworks. I'm not completely closed to the possibility that i'm just an idiot, but at this point it would likely take working with a guru for a couple weeks to change my mind.
Btw, I went with MongoKit after running into some index troubles using MongoEngine, worked like a charm.
Hint: pip -E yourenvdir install yourpackage
That will create a virtualenv and install the package there. You can just delete the env when you're done. You really shouldn't install things system-wide, generally...
- stock python 2.6.1 and /Library/Python/2.6/site-packages
- brew install python (which brings in python 2.7)
- brew install python3
... and a bunch of virtualenvs
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.
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.
Some people love Python and can't see what all the fuss is about with Ruby, others do the opposite. They're both excellent languages but you'll almost always find yourself leaning toward one over the other. This isn't because one's better, but just that it works closer to the way you think
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[edit: sorry, yes, i agree the general problem remains.]
>>> 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>).
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.
>>> def a():
... pass
...
>>> a() is None
True
>>> a()
>>>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.
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.
(I have been using Ruby (in a FOSS/academic setting) for a couple of years now (and I know Python too, though still prefer Ruby over it))
More here: http://coding.derkeiler.com/Archive/Python/comp.lang.python/...
"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?
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?
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?
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"