Re: The need to put "self" in every method



Fernando M. <fernandomirandamuro@xxxxxxxxx> wrote:
>i was just wondering about the need to put "self" as the first
>parameter in every method a class has because, if it's always needed,
>why the obligation to write it? couldn't it be implicit?

Didn't this exact question get asked just a few days ago?

Anyway, the short answer is:

1) Yes, it's always needed.
2) It's part of the Python design philosophy that "explicit is better
than implicit".

Note that in languages like C++ where using "this->" is optional,
people invent their own conventions for keeping local and instance
variables distinct, like prepending m_ to member names (except that
different people do it different ways, so it's more confusing).

.



Relevant Pages

  • Re: The need to put "self" in every method
    ... parameter in every method a class has because, if it's always needed, why the obligation to write it? ... couldn't it be implicit? ... Or is it a special reason for this being this way? ... incompabible change affecting almost every script in existance. ...
    (comp.lang.python)
  • Re: feliz navidad...pc style?
    ... > Please accept with No Obligation, implied or implicit, my best wishes ... Regards ... at tpg dot com dot au ...
    (alt.usage.english)
  • The need to put "self" in every method
    ... why the obligation to write it? ... couldn't it be implicit? ... Or is it a special reason for this being this way? ... Prev by Date: ...
    (comp.lang.python)
  • Re: The need to put "self" in every method
    ... parameter in every method a class has because, if it's always needed, why the obligation to write it? ... couldn't it be implicit? ... Or is it a special reason for this being this way? ... The basis of optimism is sheer terror. ...
    (comp.lang.python)
  • Re: What it the type of the Class without modifier
    ... "with default access" is implicit after "member ... But default access applies to types in anonymous packages ... Prev by Date: ...
    (comp.lang.java.help)