4 ms·
Yeah I know how to implement FizzBuzz since it's such a meme, but I've basically never used the mod operator in real code. Maybe it comes up in more math-y code
by sensanaty 2y ago
Yeah I know how to implement FizzBuzz since it's such a meme, but I've basically never used the mod operator in real code. Maybe it comes up in more math-y code I suppose, but for most backend/frontend/SQL code I've never reached for it.
- stefan_ 2y agoMore mathy code like checking if a number is even or splitting a total number of seconds into minutes and seconds?
- vundercind 2y agoI’ve used it for coloring alternating lines differently in UI code, and as a lazy way to log only every so many times some loop runs. I only know it well because it was covered near the beginning of one of the first programming books I picked up (on Perl 5) and it stuck with me because it seemed wild to me that they had an operator for that.
- wruza 2y agofor (…) { heavy_op(); if (i % 100 == 0) { printf("not dead"); } Classic
- kmoser 2y agoDepends on the application. I've written accounting software that makes use of it, along with heavy use of floor() and ceil(), including in SQL.