Ruby and Python, questions (not a flamewar!)

I've been using ruby for the past 6 months and I must say I am extremely
impressed. I find it a joy to write and I even find myself making
excuses to throw together simple scripts at work. I'm also teaching
myself rails and enjoying the experience as well.

At the same time, I'm looking at Python because I think it's also an
important language to know/understand today. However, the more I look at
Python the more I am convinced that ruby is just better. Syntax-wise,
language vision, design philosophy, I like them all from the ruby side
better.

So, I am kind of confused as to why Python is so mainstream and ruby
still seems so fringe. Apps like YouTube are written in Python and
powerful organizations like NASA, Google, etc. are using Python as well.
So basically, here are my questions:

1) I've read that Python is faster than ruby. How is this possible if
they're both interpreted languages written in C? Is it marginally or
substantially faster? Will this change with the release of YARV? Even if
ruby becomes faster with YARV, wouldn't this mean that the underlying
language, before producing the bytecode, is slower than Python?

2) Why are many mainstream organizations using Python rather than ruby?
Is it simply an age issue (Python has been around longer)? Is it a
performance issue? Is this changing currently?

3) Python seems to be quite prevalent within Linux distros as config
scripts...how did they gain this foothold? Why not ruby for standard
Linux config scripts?

Thanks so much for any answers you all have. I can only hope that ruby
will begin to rival Python in the "mainstream" (whatever this means).

···

--
Posted via http://www.ruby-forum.com/.

Drew Olson wrote:

1) I've read that Python is faster than ruby. How is this possible if
they're both interpreted languages written in C? Is it marginally or
substantially faster? Will this change with the release of YARV? Even if
ruby becomes faster with YARV, wouldn't this mean that the underlying
language, before producing the bytecode, is slower than Python?
  

I believe the Java Virtual Machine Ruby (JRuby) and the JVM Python (Jython) are competitive in performance. And I expect YARV to be competitive with any other language -- despite what some people say, there's nothing in the syntax or semantics of Ruby that forces a Ruby implementation to be *significantly* slower over all than other languages. It's purely a case of how clever you have to be when you implement the language run-times, compilers and interpreters.

2) Why are many mainstream organizations using Python rather than ruby?
Is it simply an age issue (Python has been around longer)? Is it a
performance issue? Is this changing currently?

3) Python seems to be quite prevalent within Linux distros as config
scripts...how did they gain this foothold? Why not ruby for standard
Linux config scripts?
  

1. Ruby started out a little later than Python, but the main reason Python is so much better known and more widely adopted is that Ruby was developed in Japan, and English-language documentation was pretty much unavailable until Ruby 1.6.

2. The question you *aren't* asking is "Why Python and not Perl?" And the answer is that Python is a lot easier to learn and use than Perl. :slight_smile:

Thanks so much for any answers you all have. I can only hope that ruby
will begin to rival Python in the "mainstream" (whatever this means).
  

I'm not sure this hope is by any stretch of the imagination shared by a large number of Rubyists. For one thing, it's unrealistic to expect major rewrites out of *any* current language -- Python, Perl, PHP, C++, Java, etc. are well-established, *living* languages with millions of lines of working and mostly maintainable code, IDEs, etc. What I hope and wish for as a Rubyist is simply that Ruby gets its proper share of *new* code, and I think that's happening. I'm not writing much new Perl these days, and I don't know any of the other mainstream general purpose languages well enough to do more than attempt to read the code.

···

--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blogspot.com/

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.

Drew Olson wrote:

So, I am kind of confused as to why Python is so mainstream and ruby
still seems so fringe. Apps like YouTube are written in Python and
powerful organizations like NASA, Google, etc. are using Python as well.

Python has a large library. Ruby's library is good and growing but it
simply doesn't compare to Python's at this point. At times I want to do
something in Ruby and I end up having to do it in Python simply because
the library pieces I'm looking for exist in Python and not in Ruby. So
I learned both.

1) I've read that Python is faster than ruby. How is this possible if

Python for the most part is faster. It's had more time to mature than
Ruby and the way the code is interpreted if I recall correctly is
different and Python currently has the edge there. Currently, Python
goes to bytecode and Ruby doesn't I believe. YARV should get Ruby on
par with Python or perhaps surpass it in speed - time will tell.

2) Why are many mainstream organizations using Python rather than ruby?
Is it simply an age issue (Python has been around longer)? Is it a
performance issue? Is this changing currently?

Python was better known in the mid to late 90's, especially in North
America.

3) Python seems to be quite prevalent within Linux distros as config
scripts...how did they gain this foothold? Why not ruby for standard
Linux config scripts?

Again, Python was here first, had good docs and a strong library. It
got a foothold first.

Had DHH written Rails for Python I think we'd see Python now the defacto
king of scripting languages. That didn't happen obviously. Rails is
Ruby's killer framework and I think has done more to promote Ruby than
any other thing.

Both Python and Ruby are great languages and both are going to keep
moving forward. The only one I see in troubled waters is Perl. I think
they've kinda hurt themselves by betting the farm so to speak on Perl 6
which has yet to materialize in a fully working form. Many people gave
up waiting and moved to Ruby or Python instead.

···

--
Posted via http://www.ruby-forum.com/\.

Drew Olson wrote:

I can only hope that ruby
will begin to rival Python in the "mainstream" (whatever this means).

I think the battleground is web apps. Right now you can leverage all
the RoR content that's directed at J2EE programmers, but you can't
hope to win a war of ideology yourself. The platform chosen seems to
determine what problems will be solved, from there you can Do The
Simplest Thing That Could Possibly Work, but it's not clear to me that
the choice of platform is anything more than an ideological struggle
where decisions are made, prior to the application of say Agile or
Design Heuristics, that determine all the problems in advance.

It would be nice if Do The Simplest Thing That Could Possibly Work, or
a normal conversation about what we can agree on, determined that Ruby
should be the language.

Maybe it would sound like: Look, Python has this weird indented
syntax and a bolted-on object model that creates an interest gap for
Java programmers. PHP is simply an unacceptable mess to Java
programmers. On the other hand there is definite interest in Ruby from
Java and dotNet programmers, due to 1) the base language Ruby actually
able to do something useful by itself, 2) RoR and 3) the basically
unacceptably complex and expensive definitions those popular compiled
languages with their do-nothing syntax have for The Web App.

-r

I'll address the one with which I have first-hand experience...

2) Why are many mainstream organizations using Python rather than ruby?
Is it simply an age issue (Python has been around longer)? Is it a
performance issue? Is this changing currently?

In some organizations, the answer is "inertia". It's more than just
age; it's the combination of age, existing expertise, installed base
of code, and concern about maintainability (however unfounded - I've
found that Python programmers have no problem reading, understanding,
and maintaining ruby code). But as more agile and startup companies
start using ruby, two things will happen: ruby talent becomes
easy/obvious to find, and some of those companies become "mainstream".
And then, who knows?

-Alex

···

On 1/18/07, Drew Olson <olsonas@gmail.com> wrote:

In my opinion, it's quite simple. Documentation.

With Python, the documentation is excellent, and it is very simple to
find docs for older versions of Python which you are likely using, as
projects stay on a given version for large amounts of time.

By constrast, the available Ruby documentation provided for free by
the project is pitiful. It is difficult to start without good docs,
when the alternatives have such excellent documentation.

I work on Ruby and Python projects, and I'm always wincing when I work
on Ruby after just working on Python. I do not like the Python
language as much, but the docs make my job easier than the digging and
digging that I need to do with Ruby.

Yes, that even includes buying the Pickaxe book, which should be an
optional step to using the language, btw, not a required one.

Love the language. It really needs a better library reference and
manual than what is currently available, and it needs to be available
for all previous versions of the language that someone might be using.

Sorry to rant, but it's a sore-point for me, because I do love the
language. Unfortunately I don't have copious free time to help fix the
problem. I can use the language or I can document it, but I can't do
both.

Mike

···

On 1/18/07, Drew Olson <olsonas@gmail.com> wrote:

So, I am kind of confused as to why Python is so mainstream and ruby
still seems so fringe. Apps like YouTube are written in Python and

--
Michael P. Soulier <msoulier@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It takes a
touch of genius - and a lot of courage to move in the opposite direction."
--Albert Einstein

1) I've read that Python is faster than ruby. How is this possible if
they're both interpreted languages written in C? Is it marginally or
substantially faster? Will this change with the release of YARV? Even if
ruby becomes faster with YARV, wouldn't this mean that the underlying
language, before producing the bytecode, is slower than Python?

Python isn't really an interpreted language in the sense that Ruby is.
Python scripts compile to Python bytecode, and it's the bytecode --
not the script itself -- which the interpreter runs. This is an
intermediate zone between a pure interpreted language like Ruby, and a
pure compiled language like C. The Python bytecode interpreter is
generally faster than regular scripting language interpreters, but
slower than C. However, it's not always very much slower. Lots of
low-level operations, like GUI stuff and I/O stuff, are handed off
directly to C code within the interpreter, and run pretty quickly
because of that. Long story short, Python's unusually fast for a
scripting language.

2) Why are many mainstream organizations using Python rather than ruby?
Is it simply an age issue (Python has been around longer)? Is it a
performance issue? Is this changing currently?

Ruby is of a comparable age, but it started in another country, a
distant country whose language is so different it cannot really be
translated literally, and Python's performance edge is signficant.

3) Python seems to be quite prevalent within Linux distros as config
scripts...how did they gain this foothold? Why not ruby for standard
Linux config scripts?

Same as number 2.

Basically, the advantage is the bytecode interpreter, and that Ruby
came from outside the West. Faster performance plus lower barriers to
adoption equals more users.

(Or at least, more users for now. Ruby books are outselling Python
books today, according to O'Reilly.)

···

--
Giles Bowkett
http://www.gilesgoatboy.org

http://gilesgoatboy.blogspot.com

Drew Olson wrote:

1) I've read that Python is faster than ruby. How is this possible if
they're both interpreted languages written in C? Is it marginally or
substantially faster? Will this change with the release of YARV? Even if
ruby becomes faster with YARV, wouldn't this mean that the underlying
language, before producing the bytecode, is slower than Python?

Ok, this is subjective, so take it with a grain of salt, but...
Yes. Standard C Python is (slightly) faster for mathematical
operations and the like (about 10-20%). It is a tad slower, imo, for
object inheritance (about 5-10%) and, albeit I have never quite
benchmarked, I would bet it is also slower for string operations (as
Python's strings are immutable, unlike Ruby's).
YARV, as it already appears in 1.9, will make Ruby roughly as fast as C
Python (some preliminary tests are still a tiny little bit faster in
Python, others are already faster in YARV). YARV does not look like it
will make Ruby faster than Python+Psyco, thou.
While the alioth shootout is often criticized for its unfairness (and
there is some truth to that, particularly with the python benchmarks
where I've often seen some questionable code) and their benchmarks lean
heavily on measuring just numerical performance, the overall results of
still show relatively correct trends in performance.
See:
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=iron&lang2=yarv
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=python&lang2=yarv
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=psyco&lang2=yarv

YARV, however, appears to me a slightly ahead of the game in terms of
making Ruby truly multi-threaded. The Python GIL (global lock) seems
like it is a big thorn into the design of the C Python interpreter.
Personally, I don't think performance is a strength of Python at all
anymore. In terms on scripting language performance, LuaJIT has left
YARV, CPython+Psyco, and Perl quite in the dust if you ask me (this is
not so surprising as Lua is a much simpler language, albeit somewhat
less friendly).
The reasons why C Python is faster than Ruby are probably deep embedded
in how their source code is coded, but, out of the top of my head:
- C Python relies mainly on reference counting for all its objects by
default, while Ruby uses a pretty inefficient garbage collector.
- C Python uses byte-code compilation, while Ruby (sans YARV) does not.
- C Python does have a couple of constructs that are efficiently
optimized by the interpreter (list comprehensions, for example). The
equivalent Ruby block code is usually not optimized at all.

2) Why are many mainstream organizations using Python rather than ruby?
Is it simply an age issue (Python has been around longer)? Is it a
performance issue? Is this changing currently?

Age, performance, origins of Ruby, and lack of knowledge about it till
about 3-4 years ago.
I'd say Ruby really became "mature" as a language with v1.8 (only about
4 years ago) and truly popular with Ruby on Rails (RoR), just two years
ago.

3) how did they gain this foothold? Why not ruby for standard
Linux config scripts?

Probably for the same reasons as 2).

Thanks so much for any answers you all have. I can only hope that ruby
will begin to rival Python in the "mainstream" (whatever this means).

Ruby is already quite mainstream, and in a domain that matters quite a
lot, which is the web. Thanks to RoR, most new websites now built are
likely to be built around Ruby than other technologies. Albeit python
did get (and probably still is) used in some places around the web, for
the most part python has struggled to achieve the massive user base on
the web that, say, Perl, PHP, Java or Ruby have obtained at some point
of their lives.
Ruby's popularity is still clearly on the upswing, unlike python which
seems more or less stuck, if you are to believe some of the statistics
published for 2006 (O'Reilley books, TIOBE index, etc).

Drew Olson wrote:

I've been using ruby for the past 6 months and I must say I am extremely
impressed. I find it a joy to write and I even find myself making
excuses to throw together simple scripts at work. I'm also teaching
myself rails and enjoying the experience as well.

At the same time, I'm looking at Python because I think it's also an
important language to know/understand today. However, the more I look at
Python the more I am convinced that ruby is just better. Syntax-wise,
language vision, design philosophy, I like them all from the ruby side
better.

So, I am kind of confused as to why Python is so mainstream and ruby
still seems so fringe. Apps like YouTube are written in Python and
powerful organizations like NASA, Google, etc. are using Python as well.
So basically, here are my questions:

Hi Drew,
Maybe your confusion on Python''s status is linked to your belief that
because Ruby is 'better' for you then it must be better than Python for
everyone?

- Paddy - A Pythonista who learned Python before Ruby, has seen no
compelling reason to switch, and would be more interested in getting
Python/Perl/Ruby/TCL/C#/Java to more seamlessly interoperate. Easy
access to modules written in any script, Yea!

Mark Haliday wrote:

Had DHH written Rails for Python I think we'd see Python now the defacto
king of scripting languages. That didn't happen obviously. Rails is
Ruby's killer framework and I think has done more to promote Ruby than
any other thing.

I don't share this opinion. I think Ruby (maybe more slowly) would of
continued to grow regardless of what happened with Rails. A few years
back (well before rails) I decided to add a more dynamic/scripting
language to my toolbox. I spent several months with Python and then
tried Ruby and never looked back. The same things that made DHH choose
Ruby would of kept grabbing the attention of other programmers even if
he hadn't noticed it.

···

--
Posted via http://www.ruby-forum.com/\.

Drew Olson wrote:

<snip>
Both Python and Ruby are great languages and both are going to keep
moving forward. The only one I see in troubled waters is Perl.

Completely agree

I think

they've kinda hurt themselves by betting the farm so to speak on Perl 6
which has yet to materialize in a fully working form.

Yes they obviously have, but did they have a choice? Just putting up at
level with Python (Ruby was probably not an issue at those days) was not
good enough.
But I guess something went wrong, maybe the critical mass was reached.
Larry always said Perl5 was his rewrite of Perl, Perl6 will be the
communities rewrite maybe they lack leadership, I dunno.

I think it is a most important lesson to learn. Ruby2 will still be Matz'
Ruby so there will be leadership.
The speed factor might be a problem for Ruby2 too, but again the delta is
much smaller than between Perl6/5.
So we will be fine I guess?

Cheers
Robert

Many people gave

···

On 1/18/07, Mark Haliday <markhaliday@yahoo.com> wrote:

up waiting and moved to Ruby or Python instead.

--
Posted via http://www.ruby-forum.com/\.

--
"The best way to predict the future is to invent it."
- Alan Kay

On Jan 19, 6:03 am, "Giles Bowkett" <gil...@gmail.com> wrote, in part:

Basically, the advantage is the bytecode interpreter, and that Ruby
came from outside the West. Faster performance plus lower barriers to
adoption equals more users.

(Or at least, more users for now. Ruby books are outselling Python
books today, according to O'Reilly.)

Citation needed :slight_smile:

The information I've seen on this suggested that Ruby book sales were
_growing_ at a faster rate than Python book sales. That's not at all
the same thing as saying that Ruby books are outselling Python books.

Of course, perhaps I haven't seen the most up-to-date information.

Gavin

gga wrote:

     In terms on scripting language performance, LuaJIT has left
YARV, CPython+Psyco, and Perl quite in the dust if you ask me (this is
not so surprising as Lua is a much simpler language, albeit somewhat
less friendly).

For more on LuaJIT, see the thread
"Intensive computing: Ruby? Ruby/C? Pure C++?" in this
newsgroup.

Giles Bowkett wrote:

> 2) Why are many mainstream organizations using Python rather than ruby?
> Is it simply an age issue (Python has been around longer)? Is it a
> performance issue? Is this changing currently?

Ruby is of a comparable age, but it started in another country, a
distant country whose language is so different it cannot really be
translated literally, and Python's performance edge is signficant.

Seems like the language barrier puts about a 5-10 year lag on it.
Probably Python doesn't have much to do with it.

The same country that produced the joyful version of chess shogi
http://trout.customer.netspace.net.au/index.html
produced the joyful version of scripting... that designed pokemon,
digimon, yugi-oh, manga, anime, toyotas, datsuns, mazdas, nissans,
etc etc has designed Ruby and exported it with the same 5-10 year time
lag as the rest of the designs. Could just be the language thing.

-r

Perl compiles to high-level bytecodes, for instance map or grep are opcodes. Are Python bytecodes similar? What about YARV?

-- fxn

···

On Jan 18, 2007, at 8:03 PM, Giles Bowkett wrote:

Python isn't really an interpreted language in the sense that Ruby is.
Python scripts compile to Python bytecode, and it's the bytecode --
not the script itself -- which the interpreter runs. This is an
intermediate zone between a pure interpreted language like Ruby, and a
pure compiled language like C. The Python bytecode interpreter is
generally faster than regular scripting language interpreters, but
slower than C. However, it's not always very much slower. Lots of
low-level operations, like GUI stuff and I/O stuff, are handed off
directly to C code within the interpreter, and run pretty quickly
because of that. Long story short, Python's unusually fast for a
scripting language.

Well, according to Tim O'Reilly, as late as last August Ruby was outselling Python:

No clue whether the trend continued.

Best,
James

···

On 2007-01-18 22:52:23 -0500, "Gavin Sinclair" <gsinclair@gmail.com> said:

On Jan 19, 6:03 am, "Giles Bowkett" <gil...@gmail.com> wrote, in part:

Basically, the advantage is the bytecode interpreter, and that Ruby
came from outside the West. Faster performance plus lower barriers to
adoption equals more users.

(Or at least, more users for now. Ruby books are outselling Python
books today, according to O'Reilly.)

Citation needed :slight_smile:

The information I've seen on this suggested that Ruby book sales were
_growing_ at a faster rate than Python book sales. That's not at all
the same thing as saying that Ruby books are outselling Python books.

Of course, perhaps I haven't seen the most up-to-date information.

Gavin

> (Or at least, more users for now. Ruby books are outselling Python
> books today, according to O'Reilly.)

Citation needed :slight_smile:

The information I've seen on this suggested that Ruby book sales were
_growing_ at a faster rate than Python book sales. That's not at all
the same thing as saying that Ruby books are outselling Python books.

Of course, perhaps I haven't seen the most up-to-date information.

···

--
Giles Bowkett
http://www.gilesgoatboy.org

http://gilesgoatboy.blogspot.com

Michael Greenly <mgreenly <at> gmail.com> writes:

I think Ruby (maybe more slowly) would of continued

As much as I don't like pointing out spelling mistakes, I can't help correcting
people about this particular one.

After it's happened, you use "Ruby *has* continued". To say it was a
possibility, you use "Ruby would *have* continued" - the same verb in both cases.

Just because it sounds a bit like "of" when you say it doesn't mean a thing.

Quoting r <johnsyntax@yahoo.com>:

Seems like the language barrier puts about a 5-10 year lag on it.

Historically, software has been a product of the Western cultures. The English
language has greatly influenced every programming language. Everything seems to
originate from the C programming language (Python, Ruby, etc.) and extend from
there. C and Unix are a western concepts.

I find Ruby fascinating simply because it was written by a non-western culture.
IMO, languages (natural languages not programming languages) influence the way
we think, form ideas and solve problems as human beings.

We can examine many programming languages designed by western software designers
and clearly see the western way of problem solving, but unfortunately, there are
not very many popular programming languages designed by other cultures. Ruby is
one example of this and is very refreshing.

I do not find Ruby to be inherently noble or the ultimate programming language,
it's only different. And IMO, different is good because it allows us to see and
frame issues from a different vantage point. In the end, we all benefit from
this.

> Python isn't really an interpreted language in the sense that Ruby is.
> Python scripts compile to Python bytecode, and it's the bytecode --
> not the script itself -- which the interpreter runs. This is an
> intermediate zone between a pure interpreted language like Ruby, and a
> pure compiled language like C. The Python bytecode interpreter is
> generally faster than regular scripting language interpreters, but
> slower than C. However, it's not always very much slower. Lots of
> low-level operations, like GUI stuff and I/O stuff, are handed off
> directly to C code within the interpreter, and run pretty quickly
> because of that. Long story short, Python's unusually fast for a
> scripting language.

Perl compiles to high-level bytecodes, for instance map or grep are
opcodes. Are Python bytecodes similar? What about YARV?

Honestly, I don't know, but Perl files are saved as Perl files. Python
files, the first time you run them, get compiled to .pyc files. Perl
files run through a Perl interpreter; Python files never actually run
at all. Only the .pyc files run.

(Perl and Python is kind of a Hatfields/McCoys situation, though, at
least it is on the Python lists I used to read.)

···

--
Giles Bowkett
http://www.gilesgoatboy.org

http://gilesgoatboy.blogspot.com