|
|
|
|
|
by kbp
2614 days ago
|
|
The important thing is restricting your public interface, hiding
implementation details, and thinking about how easy your code (and code that
uses it) will be to change later. It's not an OO vs anything thing. When you want a value from a module/object/function/whatever, whether or not
it's fetched from a location in memory is an implementation detail. Java and
co provide a short syntax for exposing that implementation detail. Python
doesn't: o.x does not necessarily mean accessing an x slot, and you aren't locking yourself into any implementation by exposing that interface as the way to get that value. It's more
complicated than Java or whatever, here, but it hides that complexity behind
a nice syntax that encourages you to do the right thing. Some languages provide short syntax for something you shouldn't do and
make you write things by hand that could be easily generated in the common
case. Reducing coupling is still a good idea. |
|
That is the important thing sometimes. At other times the important thing is to provide a flexible, fluent public interface that can be used in ways you didn't intend.
It really depends on what you're building and what properties of a codebase are most valuable to you. Encapsulation always comes at a cost. The current swing back towards strong typing and "bondage and discipline" languages tends to forget this in favour of it's benefits.