3 ms·
Variables should not be accessed directly outside of the object (encapsulation principle) and thus should all be private as a general rule. Then, you will pro
by mytailorisrich 4y ago
Variables should not be accessed directly outside of the object
(encapsulation principle) and thus should all be private as a general rule.
Then, you will probably divide up the code into a number of separate methods for better structured code. All the methods that are purely internal and not part of the public API should be private if only to enforce the public API, this is also the encapsulation principle.
- actusual 4y agoPython would like a word...
- jstx1 4y agoWhile 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.
- ajoseps 4y agoI think it's because of what underscoring does. It's the "fake" privacy in Python. Also autocompleters tend to ignore those functions
- swinglock 4y agoPerhaps you worked with Java/C++ programmers using Python.
- frenchy 4y agoProbably for the same reason that zero-based versioning (https://0ver.org/ https://0ver.org/) is so popular. People want to avoid commitment.
- mytailorisrich 4y agoThe 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.
- Saphyel 4y ago> 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 "_"
- mytailorisrich 4y agoYes but that point is irrelevant to the question...