6 ms·
APIs you provide to consumers should aim to make their badly written code just work. That's what Linus said.
by 1gor 7y ago
APIs you provide to consumers should aim to make their badly written code just work. That's what Linus said.
- blazespin 7y agoYeah. So many api writers aim to force clients do all the heavy lifting. The whole point of a good api is that it reduces heavy lifting. Anyone can write pass through apis that don’t do anything.
- dpark 7y ago> The whole point of a good api is that it reduces heavy lifting. Isn’t that the opposite of what Torvalds is saying? He seems to be arguing for simplicity. APIs that do a bunch of magic for you are the opposite of simple and tend to be mountains of subtle bugs and unexpected behavior.
- jasonjayr 7y agoI think that lies in the art of developing the API in the first place. It should give you enough primitives that it gets the job done balancing the responsibilities it advertises with the cognitive load on the developer to use it correctly.
- Const-me 7y ago> APIs that do a bunch of magic for you are the opposite of simple You're mixing simplicity of API with simplicity of implementation. More often than not, you can only have one but not both. Modern Linux or Windows do huge amount of magic when you call kernel API like open (POSIX) / CreateFile (Windows), yet the API is simple and easy. You can expose all implementation details, your code will be simple, but hard to build upon. Speaking about data storage, once upon a time I programmed Nintendo consoles, their file system API probably was very simple for Nintendo to implement, but using it wasn't fun: SDK documentation specified delays, specified how to deal with corrupt flash memory, etc. You can do the other way, you'll have to do lot of work handling all the edge cases, your code will be very complex, but this way you might make a system that's actually useful. About data storage, SQL servers have tons of internal complexity, even sqlight does, but API, the SQL, is high level and easy to use even by non-programmers.
- dooglius 7y agoDisagree in this case, it's about exposing a simple abstraction, which may mean a simple implementation, or may mean a complex one, depending on the impedance mismatch with what's going on under the hood.