4 ms·
> #define min(x, y) ((x) < (y) ? (x) : (y)) cursed code. I checked and every single invocation is just `int`, so why do this? you can just write a function:
by 38 2y ago
> #define min(x, y) ((x) < (y) ? (x) : (y))
cursed code. I checked and every single invocation is just `int`, so why do this? you can just write a function:
func min(x, y int) int {
if x < y { return x }
return y
}
and keep type safety
- slashdave 2y agoHeck, you can also use the min instruction, which avoids a branch.
- 38 2y agono such thing as a min instruction
- oasisaimlessly 2y agoYou sure? https://www.felixcloutier.com/x86/minss https://www.felixcloutier.com/x86/minss
- 38 2y agohttps://wikipedia.org/wiki/Ward_Cunningham#%22Cunningham's_Law%22 https://wikipedia.org/wiki/Ward_Cunningham#%22Cunningham's_L...