CQRS is actually based on a simpler idea introduced long ago in the Eiffel programming language (the same one that introduced contracts). Command-query separation (CQS) is a principle that devises to separate API calls into, well, commands and queries – just like in CQRS, but regardless of the scale. It plays really well with objective programming and imperative programming in general.
If your function's name starts with a has, is, can, or a similar word, it should be just a query and not modify the underlying state or have any side effects. This brings two great benefits:
- Much easier reasoning about the code: It's clear that such functions are semantically just reads, never writes. This can make looking for a change of state much easier when debugging.
- Reduce heisenbugs: If you have ever had to debug an error that manifested in a release build, but not in the debug one (or the other way around), you have dealt with a heisenbug. It&apos...