News for hackers. Stuff that matters.
Re:Ask HN: Why do you make class members private? by actusual on Monday July 25, 2022 @02:07PM (#32228482)
Python would like a word...
Re:Ask HN: Why do you make class members private? by jstx1 on Monday July 25, 2022 @02:14PM (#32228572)
While we're on Python and private methods - what's with everyone just _underscoring every method and variable by default? Does anyone teach people to do this or have I just ran into a few people with this habit by chance?

I know what _underscoring does in Python and what PEP8 recommends but doing it all the time for everything is so ugly and unnecessary.

Re:Ask HN: Why do you make class members private? by ajoseps on Monday July 25, 2022 @02:22PM (#32228692)
I think it's because of what underscoring does. It's the "fake" privacy in Python. Also autocompleters tend to ignore those functions
Re:Ask HN: Why do you make class members private? by frenchy on Monday July 25, 2022 @02:34PM (#32228882)
Probably for the same reason that zero-based versioning (https://0ver.org/) is so popular. People want to avoid commitment.
Re:Ask HN: Why do you make class members private? by swinglock on Monday July 25, 2022 @02:31PM (#32228826)
Perhaps you worked with Java/C++ programmers using Python.
Re:Ask HN: Why do you make class members private? by mytailorisrich on Monday July 25, 2022 @02:33PM (#32228866)
The language is not relevant to the question.

Making variables and methods private means making them inaccessible outside the class and I gave the typical reasons/best practices for that.

Re:Ask HN: Why do you make class members private? by Saphyel on Monday July 25, 2022 @03:35PM (#32229804)
> Making variables and methods private means making them inaccessible outside the class and I gave the typical reasons/best practices for that.

The point they are making is in python there's no private method, everything is public. There's only a convention of "avoid using anything starting with "_"

Re:Ask HN: Why do you make class members private? by mytailorisrich on Tuesday July 26, 2022 @12:04AM (#32234119)
Yes but that point is irrelevant to the question...