| ▲ | jchw 4 hours ago | |
I don't remember where it was originally written, but Qt used to have a fantastic Qt Quarterly about API design that included "The Boolean Parameter Trap", which advised several potential solutions to this very problem. Of course, it was somewhat specific to C++ in what it recommended, but I find that many insights in Qt's API design are more broadly applicable than they may first appear. In this case one insight that stuck with me: it's often better to use an enumeration of two values over a boolean. And while searching for a reference, I found the original Qt Quarterly, archived here: https://doc.qt.io/archives/qq/qq13-apis.html - I am sure some of it is just hopelessly outdated, but the general insights probably still hold up. There's a probably-more-modern successor here on their wiki: https://wiki.qt.io/API_Design_Principles | ||