I have a disagreement with one of my colleagues on whether or not functions should have inverse functions available.
I would like to know when/if inverse functions should be used.
For example, say we have a function isTrue(boolean condition){return condition == true;}
then what I would do is also include a isFalse(boolean condition){return !isTrue()';}
function, given that I know that !isTrue()
is used in the code-base.
I argue that this makes the code more readable and less error-prone as you may forget to add the "!" (which has happened to me on occasion).
He argues that the function is superfluous as !isTrue(condition);
is functionally equivalent to isFalse(condition)
and therefore isFalse()
should not be included in the API of the class.
Clearly he is right about them being functionally equivalent but I disagree that this means you should not include the isFalse()
method.
I believe that I have read somewhere that my version decreases cognitive load but I can no longer find the source. Either way, my take is that "This condition is false" is easier to understand than "This condition is the inverse of true".
If you know of any sources on either my take or his and you can share them that would be appreciated.
ValueConverter
.isTrue
andisFalse
could be really named in your code (probably because of the wrong assumption it does not matter). Sorry, but you should really try to give a few more realistic example, this is too contrived.