Why Ruby over Python?

On 7/10/06, Tim P. [email protected] wrote:

[snip]

What I do like about Python is how the documentation is built right
into the language. That is the biggest feature I wish Ruby had. That
and Python’s speed – long live YARV.

Well, we’ve got rdoc. What specific python doc feature do you miss?
Maybe being able to type “help( some_obj.some_method )” at the
interactive prompt?

Personally, I didn’t like the Python way of putting doc strings
below the thing they were documenting… always seemed upside-down.

Hi John,

On 7/10/06, John G. [email protected] wrote:

Well, we’ve got rdoc. What specific python doc feature do you miss?
Maybe being able to type “help( some_obj.some_method )” at the
interactive prompt?

Personally, I didn’t like the Python way of putting doc strings
below the thing they were documenting… always seemed upside-down.

Coming to Ruby from Python, that was the first thing I said to myself:
“I wish documentation were ‘built in’ like Python”. Rdoc is great,
and I use it everywhere now, so my documentation desire is met. But I
had to say that I missed something from Python :wink: No other Python
specific features come to mind that I miss.

I’m blessed right now to be coding Ruby full time for my job. We’re
writing tools to test the avionics for the Kepler Space telescope –
this involves generating 110 mega-pixel test images, running them
through the avionics, and then verifying that none of the pixels got
lost or mangled.

The flexibility of Ruby has allowed me to

  1. write C code for the parts that need to be fast
  2. write Ruby code for the parts that the users want to change all the
    time
  3. use meta-programming to write some DSL syntax so the test engineers
    can write their own image generation and validation scripts
  4. rake to deploy everything – I’m amazed no one has mentioned rake yet
  5. gems to distribute everything – another one I’m amazed no one has
    mentioned

Oh, and the Ruby community is just awesome … thanks to

Matz - for writing this thing
Guy Decoux - for the mmap library
Jim W. - for rake and gems
Ara Howard - for all the awesome answers about threads and numeric
coputing with Ruby
Mauricio - rcov makes our Software Quality Engineers happy
howachen - for this fun thread :slight_smile:

Blessings,
Tim P.

PS We should have an official “Thank Matz” day. Send him money, or
an Apple iCard, or write a Ruby program that is a haiku and actually
parses and runs – hmmm … Ruby Haiku day for Matz

On Jul 10, 2006, at 3:45 PM, Tim P. wrote:

PS We should have an official “Thank Matz” day. Send him money, or
an Apple iCard, or write a Ruby program that is a haiku and actually
parses and runs – hmmm … Ruby Haiku day for Matz

You really caught me with that Ruby Haiku concept. I started working
on it, but the last line is really tricky to get up to five syllables
and still be meaningful. It’s an odd downside to ruby’s terse syntax.

Maybe I’ll put a page for ruby Haiku on http://wiki.rubygarden.org/
Ruby/page/show/RubyFun once I come up with something :slight_smile:
-Mat

On Tue, 11 Jul 2006, Mat S. wrote:

Ruby/page/show/RubyFun once I come up with something :slight_smile:
harp:~ > cat a.rb

 raise :the, :red_flag unless :weak

throw :fear while :people and not :truth

 :dove and :hawk while :death

harp:~ > ruby a.rb
(infinite loop on last line)

-a

Okay, that made me smile :slight_smile:

On 7/10/06, [email protected] [email protected] wrote:

 raise :the, :red_flag unless :weak

throw :fear while :people and not :truth

 :dove and :hawk while :death

harp:~ > ruby a.rb
(infinite loop on last line)

if :love == :pain
then raise ArgumentError
else print ‘happy’ end

And you have to read == and “equals” for the haiku to work

TwP

On Jul 10, 2006, at 4:25 PM, [email protected] wrote:

meaningful. It’s an odd downside to ruby’s terse syntax.

:dove and :hawk while :death

harp:~ > ruby a.rb
(infinite loop on last line)

That ‘while’ was the inspiration I needed. I was also trying to play
on the “Thank Matz day” idea and do something a little useful.

for i in “Matz” do
print “Thank you #{i}, ruby rocks.”
end while :happiness

-Mat

Marcelo wrote:

I would LOVE wxRuby when it is done.

This is the last state, from SourceForge:

Development Status: 4 - Beta
wxRuby 0.6.0 November 21, 2004

Not as near as wxPython 2.6.3.

It’s a shame.

The last message at wxruby site is from June 12, 2006 and says that
wxruby2 is close to release quality. So grab the sources and compile it!
;D

lopex

James B. wrote:

The significant whitespace was really the decider for me personally.

Ruby has significant white space, too. But no significant indentation
(or, as I tend to think of it, “static indentation.”)

Next you’re going to correct me for calling plum… purple?

Fine, significant indention, if that make you feel better.

Doug H wrote:

Go ask this same question over on comp.lang.python and you’ll see why
you might prefer ruby.

Funny you ask:
http://groups.google.ca/group/comp.lang.python/tree/browse_frm/thread/40d8d11e12cb00ba/12306d4d9b0ce50c?rnum=11&q=ruby+or+python&_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2F40d8d11e12cb00ba%2F7256adbbc7f79afe%3Fq%3Druby+or+python%26rnum%3D1%26#doc_74bfb0743eff1367

Jean-Marc

On Tuesday 11 July 2006 17:00, [email protected] wrote:

  1. focus on codes readability, not like Perl
    eff1367
    Interesting. Someone there said that Python is more like Java
    and Ruby is more like Smalltalk. I’ve never written any
    Smalltalk, but I know some Lisp. IMO, Ruby and Python are both
    somewhere between Lisp and Java, Python closer to Java, Ruby
    closer to Lisp.

I have learned many programming languages in the last two years
and the ones I like most are Ruby, Lisp and Haskell. There is one
thing these three languages have in common: It’s easy and natural
to construct domain specific languages in them, allowing you
to write code that expresses more directly the problem at hand.

Consider Rake/Rant syntax:

task :a do
  ...
end

task :b => :a do
  ...
end

Or a well known (in the Haskell community) DSL in Haskell
is Parsec; an example from the Haskell wiki:

parseInput = do
    dirs <- many dirAndSize
    eof
    return dirs

data Dir = Dir {dir_size::Integer, dir_name::String} deriving Show

dirAndSize = do
    size <- many1 digit
    spaces
    dir_name <- anyChar `manyTill` newline
    return (Dir (read size) dir_name)

Of course, Lisp is the language for DSL construction.

Python, and more so Java do not allow you to construct a DSL.
Thus in Python and Java, on the syntax level you are always
limited to the few constructs the language provides: Defining
classes and methods, constructing objects, calling methods,
arithmetic expressions, branches via if/else, switch/case.
This gets more limiting the bigger a project grows. Java people
compensate this via huge frameworks that interpret XML files.

Ruby’s design is also more coherent than Python’s. One example
where Python really f****d up are properties. Python’s properties
are an ugly mess, just IMO.

If you already know Java/C#/C++, you’ll gain much more in
learning Ruby than Python.

On 7/11/06, Stefan L. [email protected] wrote:

  1. non C or Java style syntax
    %2F7256adbbc7f79afe%3Fq%3Druby+or+python%26rnum%3D1%26#doc_74bfb0743
    thing these three languages have in common: It’s easy and natural

    end

I haven’t done much with Rake yet, but fortunately I knew that => is
used to indicate that one task depends on another. I wonder how many
people who didn’t know Rake would guess that.

dirAndSize = do
    size <- many1 digit
    spaces
    dir_name <- anyChar `manyTill` newline
    return (Dir (read size) dir_name)

And this? I don’t know Haskell, but I thought if it’s a good language
for creating DSLs then I’d at least have a good guess at what the code
does. Unfortunately I don’t have a guess here. I think that’s a bad
sign. Call me stupid if you’d like.

Of course, Lisp is the language for DSL construction.

I’d like to see a DSL example in LISP.

Mat S. wrote:

On Jul 10, 2006, at 4:25 PM, [email protected] wrote:

meaningful. It’s an odd downside to ruby’s terse syntax.

:dove and :hawk while :death

harp:~ > ruby a.rb
(infinite loop on last line)

That ‘while’ was the inspiration I needed. I was also trying to play
on the “Thank Matz day” idea and do something a little useful.

for i in “Matz” do
print “Thank you #{i}, ruby rocks.”
end while :happiness

-Mat

I had to add my own, > cat haiku.rb:

since = “Ruby is king”
puts “Perl and Python way down”
raise “Matz up” if ‘agreed’

Yea, it throws a runtime error, but I liked the poetry.

On Jul 12, 2006, at 5:23 AM, Steve M. wrote:

I had to add my own, > cat haiku.rb:

since = “Ruby is king”
puts “Perl and Python way down”
raise “Matz up” if ‘agreed’

Yea, it throws a runtime error, but I liked the poetry.

Looks like 6 syllables in the last line to me. You forgot to throw
it through Test::Unit::Haiku :slight_smile:

Feel free to put it on: http://wiki.rubygarden.org/Ruby/page/show/
RubyHaiku
once you get that last line tweaked.

-Mat

unknown wrote:

Besides ROR, can you give me a reason why perfer ruby instead of
python?

This may be a trivial reason to most people, but it makes a huge
difference to me. I find it much easier to turn .rb scripts into
standalone .exe executbales on Windows. I’ve used Python’s py2exe and it
works OK, but Ruby’s rubyscript2exe is far better and far easier to use.

I wish Ruby had more Win32 native libraries (like Python), but I can use
win32API and win32ole for most purposes. And, Ruby is catching up with
better library support.

Also, I’ve written a lot of py code and ruby code, and I can say that I
like them both, but in general ruby is more flexible and thus more
enjoyable for me personally.

Admin -

having trouble unsubscribing from this list,
where/how do I send unsubscribe message?

Thanks

On 7/12/06, j c theriot [email protected] wrote:

Admin -

having trouble unsubscribing from this list,
where/how do I send unsubscribe message?

Thanks

If you have a question, send e-mail with the body
“help” (without quotes) to the address [email protected];
help=mailto:[email protected]?body=help

brad tilley wrote:

This may be a trivial reason to most people, but it makes a huge
difference to me. I find it much easier to turn .rb scripts into
standalone .exe executbales on Windows. I’ve used Python’s py2exe and it
works OK, but Ruby’s rubyscript2exe is far better and far easier to use.

I absolutely agree! Erik V.'s done a fantastic job developing,
maintaining, documenting, and supporting Tar2Rubyscript and
Rubyscript2Exe, and that’s a major reason why I am developing more apps
in Ruby than in Python (with which I have more experience).

Mully

newbie asks: is it true that python does NOT support containers simply
like ruby does?
ie.
a=[]<< an array container
a<<[0,1,2]
a<<{“me”=>“i think”,“you”=>“you think”}
and then use .each iterater to process this container…

Python indeed doesn’t have an #each method to iterate over a container
class and pass the elements into a block as is the case with Ruby. I
think this is because Ruby borrowed from Smalltalk with the do, block,
each, etc. aspects of the language. And Python did not.

There is a next( ) method in Python that will advance to the next
element of a container class. Here’s a reference →
http://docs.python.org/lib/typeiter.html. From there you could sort
of
create your own block using Python lambdas to mimic things to a
point…

I don’t know what you mean “simply”. Here goes the code:

a = []
a += [1, 2, 3]

if you would append the list instead of three numbers,

it would be a.append([1, 2, 3])

a.append({“me”: “i think”, “you”: “you think”})

for i in a:
print i

That’s all.

Marcelo