Anyway, I was pleasantly surprised after I found this little method:
void process(SomeData first, SomeData second) {
if (first == null && second == null) {
doWhenBothNull();
} else if (first != null ^ second != null) {
doWhenOneNull();
} else {
doWhenBothNonNull();
}
}
Of course this code could have been rewritten without using xor and wouldn't loose in readability; of course, the whole algorithm could have been rewritten so that these checks wouldn't even take place.
This post isn't about maintainability or good practices. It is about the small things that make our work worthwile.
No comments:
Post a Comment