Does Python really follow its philosophy of "Readability counts"?
pavlovevidence at gmail.com
Mon Jan 12 00:32:52 CET 2009
On Jan 11, 5:02 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Carl Banks <pavlovevide... at gmail.com> writes:
> > and where it was manipulated for that matter.
> > This criticism is completely unfair. Instance variables have to be
> > manipulated somewhere, and unless your object is immutable, that is
> > going to happen outside of __init__. That's true in Java, C++, and
> > pretty much any other language.
> The criticism is very valid. Some languages do support immutable
> variables (e.g. "final" declarations in Java, "const" in C++, or
> universal immutability in pure functional languages) and they do so
> precisely for the purpose of taming the chaos of uncontrolled
> mutation. It would be great if Python also supported immutability.
I don't think what you said (which is fine) makes his criticism valid,
unless you also suggest that all objects should be immutable.
If any objects are mutable, you have to be prepared for objects to
mutated outside the initializer.
I guess it could be a valid criticism of Django's progamming style
("They mutate stuff haphazardly everywhere!!~") but that's not the
Python langauge's problem.
> > 4. It allows a simplification of the object system. Right now, all
> > attribute access is handled identically: at any point in time any
> > attribute may be set. If you wanted to limit attribute creation to
> > __init__, then it would mean objects have to have two phases (one,
> > during __init__, where you can create attributes; the other, where you
> > can only modify them). This would add significant complexity, and
> > "Simple is better than complex.
> On the other hand, correct is better than buggy.
What bugginess do you speak of? Adding a variable outside __init__ is
questionable style, not a bug. I don't think it's a significant
source of bugs, either. And I definitely don't think the language
should add a layer of complexity (and I think you're underestimating
the complexity of making the whole object system two-phase) just to
prevent a minor style issue.
pychecker is the appropriate tool to diagnose this issue.
More information about the Python-list