On Sun, May 23, 2021 at 10:42 PM Marco Sulla <[email protected]> wrote: > > On Sun, 23 May 2021 at 14:35, Chris Angelico <[email protected]> wrote: > > > > On Sun, May 23, 2021 at 10:30 PM Marco Sulla > > <[email protected]> wrote: > > > > > > I think the only reason to introduce something like `private` is > > > refactoring. If you added a `_variable` and later you decided to > > > expose it, you have to change it to `variable`. This is something that > > > in languages like Java is not necessary, you have only to change the > > > variable from private to public. This sometimes bothered me in Python. > > > > Since you started with it private, you should be able to solve this > > with a simple search-and-replace within the class's own definition. > > Nothing outside the class should be affected. If it's that hard to > > replace "self._variable" with "self.variable" > > And, in non-trivial cases, it is :)
I'm curious as to what sort of non-trivial cases you have to deal with, where you have something harder than search-and-replace, yet you have to change your mind about whether something's private or public. Are your private members so poorly named that "._variable" comes up a lot? Do you yearn for actual refactoring tools - which do exist? > > then you can always > > create a property to make it available under both names. > > I use property a lot, but I noticed that the majority of programmers > do not use them. Also asyncio, written by Guido himself, uses normal > getters and setters. Maybe @property slows down the code? > Or maybe most Python programmers don't think in terms of private members, and it's easier to just make something public from the start. ChrisA _______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/OT54AL5JEPPOK3PK5WACHAMZ6KNFGRKO/ Code of Conduct: http://python.org/psf/codeofconduct/
