Briefle
LearnGlossaryPricing

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.

Study A · the weaker one
Study B · the stronger one

Why: B splits the job into 'getUnreadCount()' (query) and 'markAllSeen()' (command); A's 'getUnreadCount()' does both.

Related words

  • Single responsibility principle
  • Flag argument
  • Side effect
  • Parameter object
  • Long parameter list
  • Named arguments
  • Options object
  • Utils file

Room 3 · Functions & structure

Learn “Command-query separation” in a five-minute lesson

Start free
AI can build almost anything. The bottleneck is saying what you want.
WordsPricingTermsPrivacyRefundsContact
© 2026 Briefle