newbie: self.member syntax seems /really/ annoying

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Sep 13 18:21:36 CEST 2007


On Thu, 13 Sep 2007 16:16:03 +0200, Wildemar Wildenburger wrote:

> I see merit in using
> 
>    (_.foo + _.bar) * _.baz
> 
> instead of
> 
>    (s.foo + s.bar) * s.baz
> 
> because I'm trained to interpret the underscore as a synonym for one
> space. It's not particularly beautiful, but that is probably a matter of
> habituation. And that exact word is probably the reason why I'd still
> use self or s (explained by a comment, because I can get very dumb if I
> have to).
> 
> It's a matter of taste, so there is no point in bashing a valid
> suggestion.

It's not just a matter of taste.

Reading comprehensibility is an objective, measurable quantity, and I 
would bet that "(self.foo + self.bar) * self.baz" would be measurably 
more readable on average than either of your two alternatives _even for 
those people who claim to hate it_. 

But what do I care? If people are writing code that only they will see, 
they can use any conventions they feel like. It's no skin off my nose.

But if you're writing code that is going to be seen by others in the 
wider community, perhaps because it's open source, or because you're 
working in a team of coders, or even because you're posting snippets to 
comp.lang.python asking for assistance, then it is wise to write using 
conventions that others use. The harder you make it for people to read 
your code, the fewer people will be willing or able or bothered to read 
it.


-- 
Steven.



More information about the Python-list mailing list