This can be accomplished more simply and reliably by marking modulus as const. The compiler currently has to reason about the whole compilation unit to determine that modulus is not modified, which works. However, if future code modifies modulus (either on purpose or accidentally) or something changes that prevents the compiler from performing global reasoning, the optimization will be lost. By marking the actual int…
> It's really easy to forget to const something, which forces the compiler to do global reasoning or to generate worse code. Global mutable state is pure evil. Don’t write globals. It shouldn’t be easy to forget const on a global because a mutable global should produce immediate revulsion and nausea. (I don’t really consider a const global to be “a global”. So ordinarily I’d just say globals are evil don’t write glob…
Nobody is being fooled about global state when you have a singleton database connection, event bus router, or network stack. I don't think your program is better when you pass in i/o functionality to every single class context in the constructor.
Similarly a mega-class that encapsulates everything your program does is also a code smell. There's no point to a private variable when everything can access it.