4 ms·
class Foo: def __init__(self, a: int): self.a = a class Bar(Foo): def __init__(self, a: int): self.a = a The i
by agentultra 9y ago
class Foo:
def __init__(self, a: int):
self.a = a
class Bar(Foo):
def __init__(self, a: int):
self.a = a
The idea of "encapsulation," seems to be a synonym for information hiding, a principle touted by Betrand Meyer[0]. Except that languages which try to provide facilities for this principle have bolted it on in the wrong way and we as an industry have come to accept some other feature ("public/final/private" keyword languages) to mean we have, "encapsulation," in our language.
Information hiding is orthogonal to class member accessors and even object-oriented programming as we understand it today. In Haskell it's much easier to take advantage of information hiding without requiring such extra verbiage in our declarations.
This is just a long way to say that this isn't Python's fault. That Python doesn't have keywords or anything to control access to class members is a feature and not a flaw. I haven't read any introductory Python material that tries to misrepresent or hide this fact.
[0] https://sophia.javeriana.edu.co/~cbustaca/docencia/POO-2016-01/documentos/Object%20Oriented%20Software%20Construction-Meyer.pdf https://sophia.javeriana.edu.co/~cbustaca/docencia/POO-2016-...
update: That is, Python has ways to achieve the effect but it's not a part of the language grammar.
- Ace17 9y ago> Except that languages which try to provide facilities for this principle have bolted it on in the wrong way and we as an industry have come to accept some other feature ("public/final/private" keyword languages) to mean we have, "encapsulation," in our language. Actually, there's an interesting talk from Uncle Bob saying exactly that: https://www.youtube.com/watch?v=TMuno5RZNeE&t=2325 https://www.youtube.com/watch?v=TMuno5RZNeE&t=2325 The idea is that public/private/protected is an attempt to restore some of the "perfect" encapsulation we had with C; and that we lost this encapsulation with OO langages.