Why Ruby over Python?

M

Michael Greenly

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

seems to many users, they are very similar in nature...

such as

1. non C or Java style syntax
2. focus on codes readability, not like Perl
3. ..

They are both excellent so you will not be unhappy with either.

The significant whitespace was really the decider for me personally.
 
J

James Britt

Michael said:
They are both excellent so you will not be unhappy with either.

There are differences in development philosophy among the two
communities, though. For example, both Python and Ruby allow running
code to alter existing classes, including core classes (though I do not
know if they are equivalent in options and effect).

The Python community is likely to look down on this, calling it "monkey
patching." In the Ruby community this is simply one of many techniques
for building applications and is pretty common.

Ultimately the language is yours to use as you please, but it helps to
have a community with a sense of design and development that matches
your own, one that will help you grow in the direction you prefer.
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.")



--
James Britt

"A language that doesn't affect the way you think about programming is
not worth knowing."
- A. Perlis
 
C

ceesaxp

Jeffrey said:
Perl makes it easy to write clear, readable code. Perl also makes it
easy to write incredibly dense, ugly code. Blaming the language for
crappy code is like blaming a bicycle for not having training wheels
welded to the frame.

Actually, one of the reasons why I am looking at Ruby is because it
ieasier on a Perl person like me, as opposed to Python. Plus it is so
much cleaner as an OOP language -- more like Objective C / SmallTalk,
rather than Java/C++.
 
R

richardun

I love Ruby because I can do this:

class Integer
def even?
( self % 2 ) == 0
end
end

puts 3.even?
puts 28.even?

-R
"Quis custodiet ipsos custodes?"
 
L

Logan Capaldo

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

Significant whitespace in ruby? Perhaps you mean "\n" as a statement
terminator? Are there any other examples?
 
B

Bill Kelly

From: "Logan Capaldo said:
Significant whitespace in ruby? Perhaps you mean "\n" as a statement
terminator? Are there any other examples?

# ruby -we "puts ('hi')"
-e:1: warning: (...) interpreted as grouped expression
hi


Regards,

Bill
 
E

Elliot Temple

I love Ruby because I can do this:

class Integer
def even?
( self % 2 ) == 0
end
end

puts 3.even?
puts 28.even?

I don't know if that's possible in Python, but apparently I can't
guess how to do it based on a little previous Python usage:

irb(main):037:0> quit
curi-g5:~ curi$ python
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1
3.methods
^
SyntaxError: invalid syntaxFile "<stdin>", line 1
3.x = 4
^
SyntaxError: invalid syntaxTraceback (most recent call last):
curi-g5:~ curi$ irb
irb(main):001:0>

I may have typed "quit" on purpose. *ducks*

-- Elliot Temple
http://www.curi.us/blog/
 
E

Elliot Temple

I don't know if that's possible in Python, but apparently I can't
guess how to do it based on a little previous Python usage:
<snip>

OK now I think you can't do it:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: can't set attributes of built-in/extension type 'list'


-- Elliot Temple
http://www.curi.us/blog/
 
R

Ron M

M. Edward (Ed) Borasky said:
I have found that switching languages rapidly, frequently, even in a
"staggered/parallel" manner is for the most part counter-productive.
...
Add multiple programming languages and you lose focus.

I find this not to be true when the languages each are used for the
special purpose they're best suited for. I've seen this to be true
for hardware design, where switching from C models to VHDL or Verilog
makes sense; and for web stuff where switching between (whatever)
and SQL is common; and for embedded DSP stuff where switching
between C and assembly is not uncommon.

I'd even go so far as saying that a mix of Ruby with C extensions is
better in all ways than Java or C# or C++ since in the former case you
can more often use the right-tool-for-the-job while in the latter case
you're using a crippled compromise language that sucks at OO and that
sucks at low-level stuff.

I think many of the more interesting ruby projects (
* _why's Hpricot;
* David Balmain's Ferret;
* Ara's NArray+mmap
) are proving this out, since they're excellent examples of
using Ruby where appropriate and using C where appropriate
and are producing results that go a long way to bringing the
best of both worlds to the user.



And this thought lets me drift back on-topic to the original
Python question -- I find Ruby's C interfaces (both RubyInline
and the traditional one) cleaner than that of most languages,
including Python back when I looked at it. And this cleanliness
is why I care very little about ruby performance concerns - it's
very easy to apply micro-optimizations this way if you need to.
I pity a
programmer who has to write a Ruby - FORTRAN bridge that is called by a
Java ERP application for an engineering firm located in Quebec. :)

Hmm.. I did Ada/Fortran and Fortran/Forth bridges as
one of my earlier programming jobs. Close enough?
 
M

Marcin Mielżyński

Logan said:
Significant whitespace in ruby? Perhaps you mean "\n" as a statement
terminator? Are there any other examples?


"" +"".to_s +""

which gives syntax error, not undefined +@ for String runtime error ;)

lopex
 
D

Daniel Martin

M. Edward (Ed) Borasky said:
Incidentally, where I disagree is that I think there are six families:

1. Macro assemblers
2. Algol
3. Lisp
4. APL
5. Forth
6. Smalltalk
I'm just curious; where does Haskell fit in this? I think in this
taxonomy it might fall under "lisp" because of the broad "functional"
language category, but I've found that doing serious stuff in Haskell
stretches my mind more than the bits of common lisp I've learned (but
that's probably because I have never gotten heavily into CL macros).

I remember several years ago someone responded to a slashdot interview
question with a list of about twelve language categories, with several
languages fitting into multiple categories; the idea was that a
well-rounded programmer would know at least one language from each
category. I'll see if I can find it.

As for the original subject of this thread, I just find ruby more fun
to program in. I definitely do not think that ruby code is more
obvious to the untrained eye than other languages - if that were the
only category, python would indeed win. However, the experience of
writing python feels like explaining things in detail to a somewhat
dim coworker. While there's something to be said for that approach, I
find that it often gets in the way of what I want to do - I want a
fast way to translate ideas into running code. Since there's not yet
a telepathic compiler, we're stuck with using some sort of language,
and I see no reason to use a language more cumbersome than necessary.
I suppose that the whitespace usage comes into play here, although I'm
definitely not opposed to using significant whitespace, having been
bitten a few times by ruby code that looked right indentation-wise but
left off the "end". I just wish python whitespace were optional the
way it is in Haskell.

That being said, the dynamic language I use the most is still perl. I
was never nearly as put off by all the bits of "snoopy swearing" as
some people seem to be - I suppose I learned perl at a time when my
mind was flexible enough that it just twisted certain structures into
a perl shape. Perl also has the advantage of being much faster for
most operations than ruby or python.

When I want to move text A in spot one over to text B in spot two, I
use perl. That's what it's for, and it does that job amazingly well.
(It's not all regexps either. The one-liner to convert fixed length
records into newline-delimited regexps is nice and tight.) It's
disturbing how many business problems boil down to moving text from A
to B.

When I wanted to document an algorithm for my father (who speaks none
of the same computer languages I do aside from C/C++, and has spent
his career largely in VB or at the VB/COM interface), I used python.
I was already doing extensive documentation, so at that point...

When I want to play with programming, I choose ruby. When I want to
experiment, and don't really know where I'm going to end up, or how
I'm going to want to do something, ruby is there and ready to be
twisted however I want. In short, when I want to have fun, I choose
ruby.

(those business analysts who are looking at this and thinking of right
now mandating python use for everything are well advised to go
(re-)read the book "Peopleware", and realize that developers having
"fun" has very serious economic advantages)
 
V

vasudevram

M. Edward (Ed) Borasky said:
Not so much flames as challenges ...
I have found that switching languages rapidly, frequently, even in a
"staggered/parallel" manner is for the most part counter-productive.
Programming in *any* language is an activity that requires a mix of
intense focus on the programming tasks *and* an intensely active
communication in a spoken human language with customers and colleagues.
Add multiple programming languages and you lose focus.

I might not have made my above point ("it is quite possible to ...")
clear. What I meant was, once you've learned those (more than one)
languages, to a reasonable degree of proficiency, then its quite
possible to work with more than one at the same time (strictly
speaking, in a staggered manner - I haven't yet seen anyone who can
write more than one program (whether in one language or two) literally
at the same time ... :) in a given project.

I've done that in real-life projects (and this is often a genuine need
in such projects); e.g. have programmed in Informix ESQL/C (which is
actually like two languages - C and SQL in one source file) (for
database apps), plain UNIX C (for system tools or one-off programs to
be used by me and developers), Java (for biz apps again, as well as
system utliities), standalone SQL scripts (run from an SQL client), and
UNIX shell scripts (for automating tasks and calls to other programs) -
all in a single large long-running corporate project.

The organization not having resources for hiring specialized developers
for each individual language can also be a reason for needing to have
people (rather, the same person) develop in more than one language on
one project.
Occasionally a project will need multiple languages. I've found those go
slower and are more difficult than projects where you can wallow in your
knowledge of a single language and a single application domain. I pity a
programmer who has to write a Ruby - FORTRAN bridge that is called by a
Java ERP application for an engineering firm located in Quebec. :)

Not so occasionally, IMO - at least in larger corporate projects - see
1st para above.
Yes, indeed, learning multiple languages does help you grow, provided
they aren't too similar. There's a note about that on someone's blog --
give me a day or so and I can track it down. But briefly, he claimed --
and I somewhat agree -- that there are two broad classes of language.

Why should learning languages that are somewhat similar but with some
differences, not help you grow? (challenge:) E.g, Case in point:
Python and Ruby.
There's the "Algol Family", into which class C/C++, Java, Python, Ruby,
Perl, etc. fall, and there's the "Lisp Family". If you're like most of
us, you spend most of your time in the Algol family. His point was that
you grow more if you learn a Lisp family language than if you learn
another Algol family language.

Incidentally, where I disagree is that I think there are six families:

1. Macro assemblers
2. Algol
3. Lisp
4. APL
5. Forth
6. Smalltalk

You forgot Prolog-style languages - which are different from Lisp. I'm
not a language lawyer or expert, but have checked both those out a bit,
and I do feel that the programming paradigm in Prolog is different from
Lisp. Can't speak from a theoretical standpoint (e.g. some Lispers may
say that Prolog is in the same family as Lisp), and if I remember, Paul
Graham's On Lisp or some other Lisp book has an implementation of
Prolog in Lisp - though that may not be against my point that Prolog is
a different family than Lisp).
Ruby, I'll give it a shot. And there are language-specific IDEs for
Ruby. But don't *real* programmers use Emacs?

<ducking>

I was quite skilled at vi before vim came out, and managed very well
with that, though I'm aware (now) that vim has lots more features, and
am slowly checking them out.

A couple of times I've heard people (newbies mostly) mutter "magic..."
to themselves, standing behind me and watching me type code .... ;-)
Nothing special about it - just years of typing .... I'm sure many
others are the same .......

Vasudev Ram
http://www.dancingbison.com
http://www.geocities.com/vasudevram
http://sourceforge.net/projects/xtopdf
 
J

Joel VanderWerf

Francis said:
I haven't met anyone working for a large or reasonably-large company
who is thinking of mandating anything but Java. Python is generally
considered highly suspect and Ruby isn't on the radar at all. Ajax is seen
by many as a dangerous and subversive practice that must not be allowed to
take root. If you have examples to the contrary, I'd be really
interested to
hear them.

Google? (Python and AJAX)
 
B

ben.armston

M. Edward (Ed) Borasky said:
And ... which would *you* give a lovely young lady -- a ruby or a
dangerous reptile?

:)

I have a friendly pet snake I'm often trying to give to lovely young
ladies. :)
 
J

Joe Van Dyk

Haskell is a strict, lazy functional language (and pretty close to the
state-of-the-art in computer languages, IMHO). As such it neatly fits the
Lisp category.

(those business analysts who are looking at this and thinking of right
I haven't met anyone working for a large or reasonably-large company
who is thinking of mandating anything but Java. Python is generally
considered highly suspect and Ruby isn't on the radar at all. Ajax is seen
by many as a dangerous and subversive practice that must not be allowed to
take root. If you have examples to the contrary, I'd be really interested to
hear them.

Boeing's recognized that Python has significant advantages over Java
for some things. The company certainly isn't mandating Java.

Joe
 
M

Marcelo

Oh, yes, I saw that page, but for what I saw, most of them are in early
development or dead. The only one apparently working is the Ruby/Gnome.

Am I wrong? Who is doing GUI development in Ruby and what are they
using? (please, Tk is awful both in Ruby and Python) I think that in
GUI development, Ruby is far behind Python, and that is something that
keeps me from stepping into Ruby.

Any help would be appreciated, and sorry for my English.

Marcelo
 
M

Marcelo

In Python you have to sub-class int:

class MyInteger(int):
def is_even(self):
return (self % 2) == 0

a = MyInteger(3)
a.is_even() -> False
a = MyInteger(4)
a.is_even() -> True

It's not the same as in Ruby, I can see that, but it is very posible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top