Hacker News new | ask | show | jobs
by vortico 2934 days ago
Most things here are reasonable, but I don't see a point about having only one struct. If your state is better organized in lots of hierarchical structs, within lists, within other structs, your data will be easier to move around, copy, and zero in smaller chunks, and you can write functions which processes isolated segments of data rather than a huge global state.
2 comments

This is very sound advice.

The interface of the library is intended to help the user of the library, not the developer of the library.

The simplest interface is the best for the user, who does not want to know anything about the implementation details.

In the ideal case, the developer and the api designer will be different persons who are not in good terms to each other. The more the developer hates the api designer, the better.

The point was about the user-facing side not the internal representation of state.
Even then, it seems weird to prefer a big flat state rather than a state made of heirarchical sub-structures and arrays.
As the user of the library I probably don't care about the hierarchies. If I want X the library can provide me a function to get X by looking up its internal substructures and arrays so that I don't have to.