What's better about Ruby than Python?

Heiko Wundram heikowu at ceosg.de
Tue Aug 19 07:39:02 CEST 2003


On Mon, 2003-08-18 at 19:40, John Roth wrote:
> This is why Ruby's solution is superior: "self" is a reserved word,
> and so is the special character shortcut. There is no question as
> to what is meant. It eliminates essentially futile arguements in the
> same way that Python's indentation eliminates arguements about
> the proper placement of braces.

I think you're not getting the main point in a difference between Ruby
and Python here, and why it makes (IMHO) no sense to have a default self
in a function:

class X:
	def test(*args):
		print args

X.test()	# 1
x = X()
x.test()	# 2
X.test(x)	# 3

Run this, and for the first call you will get an empty tuple, while for
the second call, you will get a tuple with the first parameter set to a
class instance of X, and for the third call the same as for the second
call. Remember about method binding (method/function difference), and
the like.

I want to have class-functions which can be callable either as a
function of the class (doing something on input-data), or work directly
on the instance they are associated with. If you have a predeclared
self, only calls 2 and 3 would work, if the self parameter is just
another parameter for the function, I can miraculously call the function
just like it is (see call 1).

I find it reasonable enough to have a feature like this to not complain
about having to specify self as the first parameter, always.

Heiko.






More information about the Python-list mailing list