3 ms·
I don't see how this has any relation to API. The same argument could be true for any function — after all, your code would only benefit if you develop any clas
by golergka 12y ago
I don't see how this has any relation to API. The same argument could be true for any function — after all, your code would only benefit if you develop any class or function in your code base like an API endpoint.
And also, it is not the parameter type that is harmful here, but rather how the parameter is named and used. Let me just quote 2nd edition of Code Complete, which was written over 10 years ago: "give boolean variables names that imply true or false". Very simple, almost obvious piece of advice that summaries the problem on hand better than all this post.
- juliangregorian 12y ago"API" has a much broader meaning than the HTTP/REST/JSON variant that everyone is familiar with. Any class, 3rd-party lib, C header file, etc. that you include in your code can be considered to have an API - an application programming interface - as opposed to a application binary interface. I find it a great exercise when developing new code to first plan out the external API that other classes or programs will use to talk to it.
- golergka 12y agoThat's exactly what I meant. Ideally, I first write classes public interface (it's especially easy in C/C++, it's just an almost complete header file), then write some code that uses it to ensure that it is easy and intuitive to use, then unit tests, and only after that get to implementation. It's not always possible to follow this flow all the time (I work in the game industry and unit testing is seldom used, unfortunately), but I always find that I write better code when I follow it.