4 ms·
"WRT private class members, I can understand why this might be frustrating for library writers. But it's just so damned useful to be able to reach into a librar
by hangonhn 9y ago
"WRT private class members, I can understand why this might be frustrating for library writers. But it's just so damned useful to be able to reach into a library and get functionality the library's writer didn't think I'd need, that I'll personally never consider this to be bad."
I'll second that. I'll share my own experience to give some perspective. Older versions of the JDK had an LDAP library that for some reason I can't understand (actually pretty sure it was a mistake because it was changed in subsequent version) specified a File as the type instead of a Stream for its configuration file. There was no way for me to modify the configuration during run time without restarting the JVM. This wasn't acceptable to the software we were writing because it supported multi-tenancy.
What did I end up doing? I used introspection to grab the "private" configuration table (Vector or Hashmap?) and wroten an API around it to allow modification on the fly.
Lesson here is that "private" things aren't really so private and Python style discretionary "private" variables would have required a lot less work.
- sevensor 9y agoIs it possible that encapsulation just doesn't work, in general? It really boils down to a library author saying "trust me, this'll work great!" Sometimes it does, and sometimes it doesn't. In that light, Python's convention that a leading underscore means "probably better avoided" seems pretty reasonable. This is especially true for Python, where the type system gives you no guarantees about anything.