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).

Drew O. 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.

  1. 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?

  2. 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§
http://borasky-research.blogspot.com/

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

Drew O. 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.

  1. 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.

  1. 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.

Drew O. 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…

On 1/18/07, Drew O. [email protected] wrote:

  1. 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

Mark H. 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.

Drew O. 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.
  1. 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.

  1. 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).

On 1/18/07, Drew O. [email protected] 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

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

  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.

  1. 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.

  1. 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.)

On 1/18/07, Mark H. [email protected] wrote:

Drew O. wrote:

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

Michael G. <mgreenly 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.

Giles B. wrote:

  1. 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

Quoting r [email protected]:

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.

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.)

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

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

– fxn

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.

Kind of a tangent but I find this pretty interesting too. It’s
probably the programming language which reads most like English and it
comes from a place where English is kind of weird compared to the
structure of the local language. It’s an interesting little paradox.

On Jan 19, 2007, at 9:01 PM, Giles B. wrote:

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.

Yeah I know, but I guess that’s orthogonal to having high-level
opcodes or not. Broadly speaking, it is a matter of generating an
intermediate file or not. In fact there’s a Perl bytecode generator
(B::Bytecode) and a source filter[*] that interprets it (ByteLoader),
though those are not normally used.

– fxn

[*] For those not into Perl, a source filter is a special module that
intercepts source code before it arrives to the parser, and it is
free to modify it at its will. Filters can be chained, and once they
are done the parser receives the result and the regular flow follows.

On Jan 19, 2007, at 11:21 AM, Brad T. wrote:

Quoting r [email protected]:
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.

C and Unix are not concepts, but artifacts. And, on the scale of
computer science “history” (funny to use that to describe something
that has arisen largely within the lifetime of many of the people
reading this list) they’re not extraordinarily old. Many languages
predated C (notably, Lisp and Fortran) and many of those old
languages are still influential today.

I find Ruby fascinating simply because it was written by a non-
western culture.
[…]
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.

Well, Ruby was written by a /person/, not a culture, and it’s largely
a tasteful amalgam of good ideas introduced in those old “Western”
languages. I’d be interested to hear what you (or anyone else)
thinks is distinctively non-Western about Ruby, as opposed to C or
Lisp or Smalltalk.

Tom

On 19.01.2007, at 18:21, Brad T. wrote:

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.

There’s the Whorf-Sapir Hypothesis that states that the language that
you speak influences the way you think. While linguists and cognitive
scientists believe that the hypothesis is flawed, most of them
believe there’s at least an ounce of truth in that statement. A
somewhat similar and more accepted theory is the one advanced by
George Lakoff, but centered on the concept of metaphor.

David West reasons that on a similar level programming languages
influence the way a programmer might write a specific piece of code.
And I’m pretty sure that’s an accurate statement.

Andrei

Drew O. 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.
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!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs