Briefle words · Code & architecture
Command-query separation
Also called CQS
A rule that a function should either answer a question (query) or change something (command), never both.
Say it to an AI
TypeScript Inbox class for a chat app. Follow command-query separation: getUnreadCount() is a side-effect-free query counting messages newer than lastSeenAt, and a separate markAllSeen() command updates lastSeenAt, called only when the user opens the channel.
How an expert would brief the stronger version of “Unread badge”.
See it
Try it as a puzzle →A team chat web app shows how many new messages arrived since you last opened a channel.
Why: B splits the job into 'getUnreadCount()' (query) and 'markAllSeen()' (command); A's 'getUnreadCount()' does both.
Related words
Room 3 · Functions & structure
Learn “Command-query separation” in a five-minute lesson