3 ms·
There should rather not be magic stat'ing and loading of random files in a library function that pretends to be stateless. If it needs to load state from a fil
by mike_hock 4y ago
There should rather not be magic stat'ing and loading of random files in a library function that pretends to be stateless.
If it needs to load state from a file to do its thing, it should be split into initialization, the actual operation(s), and cleanup. (You know, like creating, using, and destroying an object, but this is C so this will be explicit calls.)
- Denvercoder9 4y agoI wouldn't consider the configuration file that says what the local timezone is a "random file" in the context of a function whose sole purpose it is to convert a timestamp to the local timezone. In fact, loading the file makes the function stateless; because if it didn't, it'd have to cache the timezone somewhere, which can get out of sync with the actual configuration.
- mike_hock 4y agoYes, caching would be even worse with no control over the cache's lifetime. You load the file into memory when I tell you to, you stringify timestamps when I tell you to, using the memory pointer I give you, and you release the memory when I tell you to. That's what a sane API looks like.