Best Practices for Writing Compose Code
Article Summary
GJ Kooijmans from Just Eat Takeaway compares writing software to Bruce Springsteen's E Street Band. Both succeed by composing simple parts into harmonious wholes—but most developers struggle with the composition part.
This article breaks down function composition principles using JavaScript examples, drawing from Eric Elliott's book 'Composing Software.' Kooijmans argues that learning to compose code properly is the difference between maintainable software and projects held together with duct tape.
Key Takeaways
- Function composition passes each function's result as the next function's argument
- Separating concerns with pipe and trace utilities makes code more debuggable
- Single-responsibility functions reduce noise and improve code readability
- Currying creates function pipelines connecting outputs to inputs seamlessly
Mastering function composition makes your code structured, scalable, and understandable by breaking complex problems into simple, composable solutions.
About This Article
When developers work with composed functions, they can't see the intermediate values. This makes it hard to figure out where calculations break down in multi-step pipelines.
GJ Kooijmans built a trace utility function that logs values between composed functions. Developers can now inspect outputs at each step without breaking the composition chain.
Using pipe and trace utilities keeps code concise and easier to read. Other developers spend less mental effort understanding how the functions connect.