3 ms·
Prefixing with underscores to pretend that a variable is private still seems like the most pointless and ugly thing ever.
by jstx1 4y ago
Prefixing with underscores to pretend that a variable is private still seems like the most pointless and ugly thing ever.
- 8organicbits 4y ago> linters will flag protected member access Sometimes you've got internal code. Sometimes people use it. Communicating which code is internal helps people avoid depending on it. Allowing people to access internals allows them to decide if it's worth the risk, and sometimes it is worth the risk. Tooling support makes it easier to work with this model.
- atorodius 4y agoWhy is it pointless to communicate that a function shoulf not be called from the outside? Also, most autocomplete tools respect rhis and only show them when you start typing _. I think it’s actually great that in Python you can still call these functions in a pinch.
- wheelerof4te 4y agoWe mostly prefix function and method names, not variables. Prefixing module variables with an underscore is a bit strange.
- revskill 4y agoYou can use postfix if you want.
- Spivak 4y agoHow else do you communicate to a user of your code in a language with no access controls that there be dragons if you mess with an object’s internal data structures? Type hinting could do it today but you’d need a PEP to add it.