4 ms·
I disagree with criticism's of Python's lack of encapsulation. I prefer the "responsible adults" method of dealing with things that should be private. Prefixi
by Sohcahtoa82 9y ago
I disagree with criticism's of Python's lack of encapsulation. I prefer the "responsible adults" method of dealing with things that should be private. Prefixing with an underscore to tell users "Don't mess with this", and prefixing with double-underscores to tell users "DO NOT mess with this!" is a perfect compromise.
If someone hands you a gun and tells you "Don't shoot yourself in the foot", and you proceed to aim down and pull the trigger, it is not the fault of the person that handed you the gun that you shot yourself in the foot.
Lack of encapsulation is a feature. It allows greater flexibility. But flexibility requires responsibility.
I've never understood the desire for multi-line lambdas. At that point, what makes a lambda different from a function? Just seems like a $1,000 term for a $5 concept.
And decorators are wonderful things. The ability to alter functions in a single line is beautiful.
TypeErrors as described by the author are just sloppy programming. If a function is expecting a string, why are you passing it something that's not a string?
- kiriakasis 9y agoI saw the examples differently; first the author notes that it is easy to mask a private attribute and that docs would not help, I believe this was its main point. secondly and less importantly he notes that (with some weird naming practice though) _Foo__bar might again look like something you could define. here i'm stretching my python knowledge so i could be wrong (for example i don't know if hinheritance affects the extended name...) Anyhow i think the first one was the main point: "accidental and hard to debug modification of private field"