Thief. Writing code is for chumps, and the more code you right, the more of a chump you are.
Thief way is actually the best among all of these imo, in terms of readability and efficiency.
They’re setting a variable to a function. Just use the original function. All thief does is obfuscate for literally no gain except character count.
TDD
const max12 = (x, y) => { if (x === 1 && y === 2) { return 2; } else if (x === 7 && y === 4) { return 7; } else { return x; } };
Mathematician 2 kinda blew my mind, kinda obvious, just can't believe I was never taught or thought about it.
I've been staring at it for 10 minutes and I'm still not convinced it works.
#define max(x,y) ( { __auto_type __x = (x); __auto_type __y = (y); __x > __y ? __x : __y; })
GNU C. Also works with Clang. Avoids evaluating the arguments multiple times. The optimizer will convert the branch into a conditional move, if it doesn't I'd replace the ternary with the "bit hacker 2" version.
- Show
Otherwise, realistically, I’m prob the worst of all worlds … the procrastinator waiting/hoping to be the pair programmer that has hopefully remembered to just be the thief.
Why use
const max = (x, y) => x > y ? x : y
instead offunction max(x, y) { return x > y ? x : y }
?