Imperative: You write explicit instructions for the machine: "do this, then do this, then check this condition, then loop". The control flow is up to you. Imperative code tells the computer exactly what to do, step by step. Set a counter to zero, loop over the orders, check each status, add to the total, return the result. You control the flow.
Most programming starts here, and it maps closely to how processors work. It is explicit and easy to step through in a debugger.
What should you keep in mind with Imperative?
The downside is that the intent can get lost in the bookkeeping. A ten-line loop that sums paid orders says less clearly what it does than $orders->where('paid', true)->sum('total'). Good code mixes both styles: declarative where the intent matters most, imperative where you need fine control over performance or a specific sequence of side effects, such as calling an external API in a set order.
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.