I regularly run into a dilemma when writing API, whether to choose one that refl...
Dave Rahardja @drahardja@sfba.social
I regularly run into a dilemma when writing API, whether to choose one that reflects what a library *does* today, or one that reflects what I hope the library *should* be doing in the future. Do I use an enum instead of a Boolean even though there are only two states? Do I push an API down to a finer grained abstraction (even though does nothing today) because I *hope* that one day the finer grained abstraction will do some work? Do I create a configuration object even when it only has a couple of a parameters, or do I add named parameters to the initializer?
In most cases, I end up publishing the simpler API that *does something today*. Unless there is reason to believe that future functionality is going to be realized really soon (as in, I’m already working on it for a near-future release), it’s better to produce the *simplest* possible API as long as it doesn’t preclude future development.
Premature API optimization is still premature optimization.