5 ms·
The code in the example has poor encapsulation, but I do not think it's the "JSON" style that causes that. Much OOP code includes a hodgepodge of exposed inter
by grandalf 10y ago
The code in the example has poor encapsulation, but I do not think it's the "JSON" style that causes that.
Much OOP code includes a hodgepodge of exposed internal state and methods that offer a combination of derived state and behavior to mutate that state.
Often, using data literals (like JSON) can make code clearer by making it explicit what is going on with state (when/if it is being mutated), and making the system easier to snapshot, test, etc.
While much code that uses JSON-like constructs is overly verbose and error prone, adding a bit of structural typing (with Flow) or creating schemas to ensure system invariants (jsonschema) can lead to a system that is easy to reason about and maintain.