[Tutor] Why is the name "self" optional instead of mandatory?

Francois Dion francois.dion at gmail.com
Thu Jan 21 08:16:07 EST 2016


On Thu, Jan 21, 2016 at 6:49 AM, Steven D'Aprano <steve at pearwood.info>
 wrote:

> On Wed, Jan 20, 2016 at 09:42:29PM -0600, boB Stepp wrote:
>
> > So I really only have one question:  Why not make Python's
> > *traditional* name, "self", mandatory?  Why give the programmer this
> > kind of choice?  [OK, that was two questions.]


[answers ommited]

All great answers. Ben mentioned the four space tab convention as a similar
thing:  Python has a ton of conventions but doesn't enforce them. That is
not the job of the interpreter, at least the Python one, since it has never
enforced any convention.

Yes, individual programmers can enforce these conventions in whichever way
they want. Some see this as a bad thing for coding standards, but that is
easily addressed by tools like pylint. In an enterprise setting, the
pipeline of going from writing code to deploying it will go through a few
phases, including checking for PEP8 compliance, Pylint compliance (the
rules the team cares about), code complexity etc. With pylint, if you try
it on your code with this instead of self, you'll get this in particular:
"Method should have "self" as first argument (no-self-argument)"

Francois


-- 
raspberry-python.blogspot.com - www.pyptug.org - www.3DFutureTech.info -
@f_dion


More information about the Tutor mailing list