Functions and single responsibility
A function is a named operation that receives inputs and produces a result or effect. A focused function does one understandable job, such as validate_event or accept_ticket.
In the help desk case study, decomposition from Problem decomposition can become a small interface:
validate_event(event) -> validation result
accept_ticket(event) -> accepted ticket
The names expose the boundary between responsibilities. They do not yet decide whether the system uses a list, dictionary, or queue.
A clear function interface
Before writing a function, identify:
- Its purpose
- Its inputs and their expected form
- Its return value
- Its side effects
- Its behavior for invalid or boundary inputs
Small functions are easier to test, reuse, and replace. They are not valuable merely because they are short. Splitting one operation into many trivial functions can make a program harder to follow.
Single responsibility
The single-responsibility idea asks a function or module to have one coherent reason to change. A function that validates an event, stores a ticket, and assigns work has several reasons to change and is difficult to test safely.