[Tutor] Re: Python vs. Ruby
Andrei
project5 at redrival.net
Thu Oct 30 18:35:18 EST 2003
Daniel Ehrenberg wrote on Thu, 30 Oct 2003 14:10:23 -0800 (PST):
> Alan Gauld wrote:
>> 2) I hate languages that insist on everything being
>> an object.
>> I've used OO long enough to know there are times
>> when it
>> ain't the best answer...
>
> When not? Isn't everything in Python an object, to
> some degree?
>From Dive into Python:
"Different programming languages define “object” in different ways. In
some, it means that all objects must have attributes and methods; in
others, it means that all objects are subclassable. In Python, the
definition is looser; some objects have neither attributes nor methods
(more on this later in this chapter), and not all objects are subclassable
(more on this in chapter 3). But everything is an object in the sense that
it can be assigned to a variable or passed as an argument to a function
(more in this in chapter 2)."
In Ruby, you can subclass everything, modify all classes, call methods on
everything.
Ruby Python
=====================================
2.times do for i in range(2):
puts "ok" print "ok"
end
- - - - - - - - - - - - - - - - - - -
ok ok
ok ok
=> 2
=====================================
5.0.+(3) 5.0 + 3
- - - - - - - - - - - - - - - - - - -
=> 8.0 8
"+" is a method of 5.0 and you can use it as such in Ruby. times() is a
method of 2. While writing 2.times() has a certain ring to it and I rather
like it, it's not something that makes a language superior or even better.
--
Yours,
Andrei
=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
ernq gur yvfg, fb gurer'f ab arrq gb PP.
More information about the Tutor
mailing list