Why Ruby over Python?

On Tuesday 11 July 2006 23:50, Mark V. wrote:

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

end

task :b => :a do
  ...
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.

You have to learn any syntax/API. Important is that it’s
easy to remember and that you don’t have to write unnecessary
code each time you define a task. In Python this would
probably be done like this:

def fun_a():
  ...

task("a", fun_a)

def fun_b():
  ...

task("b", "a", fun_b)

Having to define the separate functions fun_a and fun_b
is an unnecessary burden for the programmer. Having to
invent those function names gets tiresome. And I don’t
see how that would be any clearer than the Ruby version.

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.

Perhaps it wasn’t so a good idea to drop these examples
in without any explanation :frowning:

The parseInput function parses lines like this:

65572 /home/adept/photos/raw-to-burn/dir1

This example is from
http://haskell.org/haskellwiki/Hitchhikers_Guide_to_the_Haskell

The important point here is again that if you know basic
Haskell, Parsec provides an easy way to define parsers.
There is no bookkeeping for the Haskell compiler.
Parsec was used for Pugs, the first Perl 6 compiler. So
it seems to work for harder tasks too.

Of course, Lisp is the language for DSL construction.

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

Taken from “Practical Common Lisp”,
http://www.gigamonkeys.com/book/practical-building-a-unit-test-framework.html

Usage of a small unit test framework:

;; Define a test case for the "+" function
(deftest test-+ ()
  (check
    (= (+ 1 2) 3)
    (= (+ 1 2 3) 6)
    (= (+ -1 -3) -4)))

;; Another test case for "*"
(deftest test-* ()
  (check
    (= (* 2 2) 4)
    (= (* 3 5) 15)))

;; Test suite for arithmetic functions
(deftest test-arithmetic ()
  (combine-results
    (test-+)
    (test-*)))

;; run the test suite
(test-arithmetic)
pass ... (TEST-ARITHMETIC TEST-+): (= (+ 1 2) 3)
pass ... (TEST-ARITHMETIC TEST-+): (= (+ 1 2 3) 6)
pass ... (TEST-ARITHMETIC TEST-+): (= (+ -1 -3) -4)
pass ... (TEST-ARITHMETIC TEST-*): (= (* 2 2) 4)
pass ... (TEST-ARITHMETIC TEST-*): (= (* 3 5) 15)
T

That “T” in the last lines means that all tests have passsed.
“deftest”, “check” and “combine-results” are user defined macros.
The whole “framework” is defined in 26 lines of code.
For my needs, I would tweak it so that the test code is printed
only for tests that failed.

Currently I have to write a Java webapp at work. Writing Java and
loads of XML when you know Lisp and Ruby really hurts.
If Java would provide something like Lisp’s macros or some of
Ruby’s features (anonymous closures, defining own attr_* methods,
higher order functions, etc.), I’m sure we could reduce the code
size of the project to a quarter or less of the current size.
The same goes for the XML code. Those XML DSLs have a serious
problem. When a certain pattern occurs often in the project and
the framework hasn’t a builtin way to factor it out, you’re out
of luck. Type it out each time.

In an Rantfile/Rakefile I have the full power of Ruby at hand.
I simply Won’t Repeat Myself.

Stefan L. [email protected] writes:

I haven’t done much with Rake yet, but fortunately I knew that =>

see how that would be any clearer than the Ruby version.

I can think of a syntax that is far easier. :wink:

a:
stuff to do
for a

b: a
stuff to do
for b

Stefan L. wrote:

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.

Ultimate object orientation, continuations and blocks/closures - the
last is very very smalltalkish ;D

Smalltalk at: #a put: (Array new: 2)!
a at: 1 put: ‘some string’.
a at: 2 put: ‘some other string’.
a do: [:n| n printNl].

a=[]
a << ‘some string’
a << ‘some other string’
a.each{|n| n.display}

The similarity is obvious.

lopex

[email protected] wrote:

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

The Ruby community is better-looking.


James B.

“The use of anthropomorphic terminology when dealing with
computing systems is a symptom of professional immaturity.”

  • Edsger W. Dijkstra

James B. wrote:

[email protected] wrote:

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

The Ruby community is better-looking.

And more modest.

Hi –

On Sat, 8 Jul 2006, [email protected] wrote:

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

I can give you the answer in my case: love. I fell in love with the
Ruby language, and subsequently with the Ruby culture and community.
That gives you a much more lucid, rigorous account of my experience
than anything I can say about blocks, significant whitespace, or other
language features possibly could.

David

On Sat, 8 Jul 2006 [email protected] wrote:

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

RoR is irrelevant to it.

Ruby is love.
Python is bondage.

I choose love.

Kirk H.

vasudevram wrote:

Hi,

I’m sticking my neck out here a bit, since I’m relatively new to Ruby,
but gonna do it anyway … :0) [I do have a good amount of experience in other languages like Java, C, Python]. More knowledgeable Rubyists,
feel free to flame away at what I say below :slight_smile: I know I’ll learn
something from it anyway.

Not so much flames as challenges …

Reason 0: First of all, its not necessarily a matter of preferring Ruby
over Python. Its not an either-or situation at all - unless you want
to make it one. Its quite possible to learn and work with more than one
language at the same time, or at least in a staggered/parallel manner.
Many top developers are of the view that learning and using more than
one language is beneficial, helps you grow as a programmer.
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.

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. :slight_smile:

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.

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

One of the things that’s attractive to me about Ruby is that it contains
features from most of the six. I haven’t found much of APL or Forth, but
there are clearly influences from Algol, Lisp, Smalltalk and macro
assembler.

Reason 1: Ruby is more object-oriented than Python.

Well … Ruby objects were there from day one, and they resemble
“classical” object concepts like those in Smalltalk, C++ and Java, but I
don’t think today’s Python is “less object-oriented” than today’s
Ruby, nor do I think Ruby is “more object-oriented” than R, Lisp or
Scheme.

Reason 2: The Principle of Least Surprise. You can, to a good extent,
almost figure out how parts of the language / syntax work, after you’ve
learnt a bit of it. Read the Pickaxe and other Ruby books and the docs
to see more on what this means.
I’ve been writing some Ruby code and can attest to it.

I haven’t found Ruby code all that obvious to a newcomer. I’ve been
programming a long time, and I have a programming style that evolved
from macro assembler to FORTRAN to Perl to R, with influences from Lisp,
FORTH and Java.

Part of it is that I’m very much more familiar and comfortable with
functional programming than I am with object-oriented programming. In my
younger days, I was actually one of those people who went around on long
tirades declaiming that Functional Programming was the one true way. :slight_smile:
I thought pure functional languages had a lot going for them. I still
do.

I spent about three hours last night trying to understand Hal F.'s
well-crafted example of metaprogramming that reads CSV files. I know it
will make sense to me eventually, but it didn’t after three hours. I
know it’s “good code”, I know it’s “elegant code”, I know it’s an
example of the wonders of Ruby, and I know it works. But I still don’t
know why. :slight_smile:

was switching text editors (Metapad and GVim on windows) at times in a
coding session. This somehow led to the changing of some tabs to
spaces. Hard to detect visually in a Windows style editor like Metapad.
Using the “:se list” option in GVim can help, but it still takes time
to track down and change all those spaces back to tabs. One can argue
away that one should not change editors in the middle of a session,
etc., but the point is that this problem simply would not happen in
Ruby, even if you switch editors midway.

Well … there are language-specific IDEs for Python. If I were
planning/required to learn Python, I’d probably use Leo. I’ve got Leo
and if I can get it integrated with the languages I do use, Perl, R and
Ruby, I’ll give it a shot. And there are language-specific IDEs for
Ruby. But don’t real programmers use Emacs?

Actually, I’ve never bothered to learn Emacs. It had a (justified)
reputation as a memory hog, so I learned vi. I’m pretty sure GNU Emacs
is no longer a memory hog, but I’m so firmly down the “vim” path that
Emacs seems like a distraction.


M. Edward (Ed) Borasky

[email protected] wrote:

RoR is irrelevant to it.

Ruby is love.
Python is bondage.
Uh … love … bondage … uh … never mind


M. Edward (Ed) Borasky

M. Edward (Ed) Borasky wrote:

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.


M. Edward (Ed) Borasky

On 7/8/06, M. Edward (Ed) Borasky [email protected] wrote:

Not so much flames as challenges …
communication in a spoken human language with customers and colleagues.
give me a day or so and I can track it down. But briefly, he claimed –

  1. Macro assemblers

Reason 1: Ruby is more object-oriented than Python.
I’ve been writing some Ruby code and can attest to it.
I thought pure functional languages had a lot going for them. I still do.
a very good typist, Python’s syntax rules recently almost drove me mad,
to track down and change all those spaces back to tabs. One can argue

much shorter answers :wink:


Deux choses sont infinies : l’univers et la bêtise humaine ; en ce qui
concerne l’univers, je n’en ai pas acquis la certitude absolue.

  • Albert Einstein

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?”

On Jul 8, 2006, at 9:40 PM, [email protected] wrote:

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.

Integer
Traceback (most recent call last):
File “”, line 1, in ?
NameError: name ‘Integer’ is not defined
3
3
3.methods
File “”, line 1
3.methods
^
SyntaxError: invalid syntax
3.x = 4
File “”, line 1
3.x = 4
^
SyntaxError: invalid syntax
x = 3
x.x = 4
Traceback (most recent call last):
File “”, line 1, in ?
AttributeError: ‘int’ object has no attribute ‘x’
quit
‘Use Ctrl-D (i.e. EOF) to exit.’

curi-g5:~ curi$ irb
irb(main):001:0>

I may have typed “quit” on purpose. ducks

– Elliot T.

On Jul 8, 2006, at 9:49 PM, Elliot T. wrote:

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:

OK now I think you can’t do it:

list.x = 5
Traceback (most recent call last):
File “”, line 1, in ?
TypeError: can’t set attributes of built-in/extension type ‘list’

– Elliot T.

M. Edward (Ed) Borasky wrote:

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 B.'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. :slight_smile:

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

“M. Edward (Ed) Borasky” [email protected] writes:

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)

On 7/9/06, Daniel M. [email protected] wrote:

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

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

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)

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.

If you follow the framework debates in the Java world, they’ve been
talking
for months now about how heavyweight frameworks (which are still being
invented every other day, it seems) may be dying because of Ajax (read,
because of Rails). This obviously scares the hell out of people who have
invested heavily in Struts, Faces, and similar stuff.

[email protected] writes:

Ruby is love.
Python is bondage.

I choose love.

Vanilla!

SCNR.

Francis C. wrote:

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.
Well, I rather suspect .NET has reached the point that it’s
“mandatable”, like all other Microsoft products. On the other hand, the
whole point of Java is, or at least was, to be server and desktop
platform independent. Whether it’s worked out that way is a question I
can’t answer.
If you follow the framework debates in the Java world, they’ve been
talking
for months now about how heavyweight frameworks (which are still being
invented every other day, it seems) may be dying because of Ajax (read,
because of Rails). This obviously scares the hell out of people who have
invested heavily in Struts, Faces, and similar stuff.
Has anyone really determined once and for all whether the dinosaurs died
out because they were too large for their environment or because a huge
hunk of rock hit the Yucutan Peninsula? :slight_smile:


M. Edward (Ed) Borasky

M. Edward (Ed) Borasky wrote:

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 … :slight_smile: 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. :slight_smile:

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.

  1. Algol
  2. Lisp
  3. APL
  4. Forth
  5. 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?

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 … :wink:
Nothing special about it - just years of typing … I’m sure many
others are the same …

Vasudev Ram