
On 2021-05-23 at 16:30:35 +0200, Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
On Sun, 23 May 2021 at 14:50, Chris Angelico <rosuav@gmail.com> wrote:
On Sun, May 23, 2021 at 10:42 PM Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
On Sun, 23 May 2021 at 14:35, Chris Angelico <rosuav@gmail.com> wrote:
On Sun, May 23, 2021 at 10:30 PM Marco Sulla <Marco.Sulla.Python@gmail.com> 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
For example, having _variable in another class.
Then it isn't/wasn't private.
Do you yearn for actual refactoring tools - which do exist?
Renaming tools of IDE do not work in 100% of the cases. For example, if you have _variable in an eval string, it's not replaced.
Another reason not to use eval.
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.
Naaaa, I see private vars used a lot. It's @property that, it seems to me, is used sporadically.
I suspect that I am not "most Python programmers,", but I always think of state (aka members, variables, attributes) as private and internal. If I think I need to reach into an application level object for its state (to read it or to write it), or that I need a getter, let alone a setter, then I'm doing (or have done) somthing else wrong.