Command-query Separation - Connection With Design By Contract

Connection With Design By Contract

Command-query separation is particularly well suited to a design by contract (DbC) methodology, in which the design of a program is expressed as assertions embedded in the source code, describing the state of the program at certain critical times. In DbC, assertions are considered design annotations – not program logic – and as such, their execution should not affect the program state. CQS is beneficial to DbC because any value-returning method (any query) can be called by any assertion without fear of modifying program state.

In theoretical terms, this establishes a measure of sanity, whereby one can reason about a program's state without simultaneously modifying that state. In practical terms, CQS allows all assertion checks to be bypassed in a working system to improve its performance without inadvertently modifying its behaviour. CQS may also prevent the occurrence of certain kinds of heisenbugs.

Read more about this topic:  Command-query Separation

Famous quotes containing the words connection with, connection, design and/or contract:

    “We should always remember that the work of art is invariably the creation of a new world, so that the first thing we should do is to study that new world as closely as possible, approaching it as something brand new, having no obvious connection with the worlds we already know. When this new world has been closely studied, then and only then let us examine its links with other worlds, other branches of knowledge.”
    —Vladimir Nabokov (1899–1977)

    “One must always maintain one’s connection to the past and yet ceaselessly pull away from it. To remain in touch with the past requires a love of memory. To remain in touch with the past requires a constant imaginative effort.”
    —Gaston Bachelard (1884–1962)

    “For I choose that my remembrances of him should be pleasing, affecting, religious. I will love him as a glorified friend, after the free way of friendship, and not pay him a stiff sign of respect, as men do to those whom they fear. A passage read from his discourses, a moving provocation to works like his, any act or meeting which tends to awaken a pure thought, a flow of love, an original design of virtue, I call a worthy, a true commemoration.”
    —Ralph Waldo Emerson (1803–1882)

    “The way in which men cling to old institutions after the life has departed out of them, and out of themselves, reminds me of those monkeys which cling by their tails—aye, whose tails contract about the limbs, even the dead limbs, of the forest, and they hang suspended beyond the hunter’s reach long after they are dead. It is of no use to argue with such men. They have not an apprehensive intellect, but merely, as it were a prehensile tail.”
    —Henry David Thoreau (1817–1862)