Comparison
Command-query separationvsPrinciple of least astonishment
Command-query separation
you called something that looked like a getter and it wrote a row to the database.
A method should either change something or answer something, never both. When a query has a side effect, nobody can safely call it twice, log it, cache it or move it inside a conditional — all the things people do to a getter without thinking. The cost of ignoring it is a class of bug that only appears when someone removes a call they believed was a read.
Full entry →Principle of least astonishment
the method called save() also sent an email, and somebody found that out in production.
A component should behave the way most people reading its name would expect. Astonishment is a real cost, paid by every future reader who assumes the ordinary thing and is wrong. It is the strongest argument against a clever design that is defensible on paper: being right is not enough if every user of it has to be told, because you will not be there to tell them.
Full entry →