# Command Query Separation Principle
Is an object oriented programming principle that states that every method should either query the current state, or alter it. Methods that do both should be avoided because they lead to Spaghetti Code. CQS also helps with documentation because the method signature communicates if the method alters the state.
It can be broken down into two separate parts:
- Commands are identified by method signature (they return void)
- Queries (methods that do not return void) are not allowed to call commands
The simple rules mean CQS could even be enforced by a compiler or analyzer.
CQS should not be confused with [[Command Query Responsibility Segregation]], which is a different principle.
## Sources
Martin Fowler. [Command Query Separation](https://www.martinfowler.com/bliki/CommandQuerySeparation.html).