self.python vs Current.eiffel
Christian Tanzer
tanzer at swing.co.at
Tue Sep 26 12:26:05 EDT 2000
Egbert Bouwman <egbert at bork.demon.nl> wrote:
> In a python method the following instruction is allowed:
> self.x = self.x + a
> On page 187 of OOSC, Meyer seems to say that in Eiffel you cannot say:
> Current.x := Current.x + a
> He says: ...the occurrence of x on the left is not an expression
> (one cannot assign a value to an expression), so it would be
> meaningless to replace it by Current.x
I currently don't have a copy of Meyer's book at hand but I think the
quoted statement talks about the Eiffel rule that a function must not
have side effects. Therefore assignments to instance attributes are
not allowed in the function.
Eiffel has a strict distinction between `procedures' and `functions':
- procedures have side effects but cannot return a result
- functions return a result but must not have side effects.
> I am lost. What are the differences between python's self and x,
> and Eiffel's Current and x ?
Apart of the side effect issue, Eiffel's current is normally implicit
and rarely used. Python's self is explicit and must always be used.
You can assign to self (though that's probably not a good idea), but
not to current.
--
Christian Tanzer tanzer at swing.co.at
Glasauergasse 32 Tel: +43 1 876 62 36
A-1130 Vienna, Austria Fax: +43 1 877 66 92
More information about the Python-list
mailing list