4 ms·
Speaking of clobbering each other, min and max are names I had used for variables and functions all over the place. Suddenly they go and add global generic min/
by donatj 2y ago
Speaking of clobbering each other, min and max are names I had used for variables and functions all over the place. Suddenly they go and add global generic min/max functions and I'm shadowing like crazy.
I still don't understand why they aren't in a package, or better yet why they didn't just make math.Min and math.Max generic?
- shortrounddev2 2y agoC++ programmers have had this problem in win32 since C++14 when they added std::min and std::max, whereas MSVC has offered those as built in functions since the 1990s
- BearOso 2y agoThis has long been a problem with win32 and windows.h. Search for "NOMINMAX". They're preprocessor definitions, so you can't even shadow them.
- delta_p_delta_x 2y ago> min and max are names I had used for variables and functions all over the place Shadowing is better than the very questionable decisions made by whoever wrote Windows.h... #include <Windows.h> #define NOMINMAX // comment out to break #include <algorithm> auto main() -> int { return std::min(42, 1337); // may break }
- eska 2y agoThe windows headers are so convoluted and huge that I just copy the necessary declarations into my own mini header. It’s a bit annoying at first but saves a lot of headache later.
- mococa 2y agoThis one made me lose a few strands of hair years ago.
- BearOso 2y agoNOMINMAX is checked in windows.h to control whether it adds the macros. It needs to be defined before the inclusion.
- loup-vaillant 2y ago> or better yet why they didn't just make math.Min and math.Max generic? I don't know Go, but my first thought would go to lol no generics. Now that they do have generics I guess they could do it, but backwards compatibility may require them to use other names than `math.Min` and `math.Max`. (Note: Go did have some generic built-in constructs from the start, and could have included `min` and `max`, similar to how OCaml did it. At the same time, you don't want too many primitives in your language if you can help it.)