2 ms·
I'm not going to argue this is good, but it's fairly analogous: boolean isEven(int n) { boolean even = true; for (; n > 0; --n) even = !eve
by twic 4y ago
I'm not going to argue this is good, but it's fairly analogous:
boolean isEven(int n) {
boolean even = true;
for (; n > 0; --n) even = !even;
return even;
}
- chriswarbo 4y agoYour implementation has lost the encapsulation of mine, and broken the call-graph relationships. For example: - Updates and bug-fixes to the `isOdd` function will not be inherited by your `isEven` function. - If I set a breakpoint in this function, it won't get triggered when I call `isOdd`. - Your `isEven` function requires an implementation of `!` - etc.
- twic 4y ago> - Updates and bug-fixes to the `isOdd` function will not be inherited by your `isEven` function. > - If I set a breakpoint in this function, it won't get triggered when I call `isOdd`. boolean isOdd(int n) { return !isEven(n); } > - Your `isEven` function requires an implementation of `!` Yes, but this language has one, so that's fine.