This is not bad code. It is "slightly inelegant" but more readable code (because it is a only return from a function). If would be "inelegant" when used in a if, say in: if (val==true). It starts to be bad when reaching levels of if (val==true) return true; else return false;
I think you don't understand what the problem with this code is. It isn't the comparison, rather its the fact that someone built an entire function around a builtin operator that uses said operator.
Its not about being build around an operator, that's no problem. Its about replacing the operator with function that uses the operator. And anyone that writes an interface like that is already writing bad code to begin with. If you're interface has something like "isTrue" you've got bad architecture, or you've gone OOP so far that it doesn't make sense anymore.
-2
u/F54280 Jun 23 '20 edited Jun 23 '20
This is not bad code. It is "slightly inelegant" but more readable code (because it is a only return from a function). If would be "inelegant" when used in a if, say in:
if (val==true). It starts to be bad when reaching levels ofif (val==true) return true; else return false;But a simple comparison with true? Absolutely not worth of a post here. Here are 663000 occurrences using a simple google search
Edit: lol @downvoters that have no idea what actual badcode looks like