|
|
|
|
|
by jeremyjh
3779 days ago
|
|
>Code that takes a full structure when it only needs to operate on a part of the structure is badly designed. No, it is not; this is done all the time with methods and it improves encapsulation - you may not want your clients to be able to decompose your data structures. Do you really mark every member of your data structures as pub?? Sorry but this is a poor ad-hoc defense of an actual annoyance in the borrow-checker. |
|
I think this was a sensible statement, especially in context; I strongly agree that "this is behind a lot of long-term maintenance messes". And lost performance.
For encapsulation in Rust, traits are used to abstract and separate concerns, but they don't force you to bundle your data into large structures.
And encapsulation isn't an end in itself. Privacy has its uses (maintaining invariants, minimizing the exposed surface area of a library, etc.) but I find often in OO codebases that encapsulation creates its own problems. There is no substitute for careful data-oriented design; no amount of `private` will prevent your teammates from working around or ripping apart your carefully shrink-wrapped objects.
There is certainly some awkwardness in the borrow checker, but also great value.