One of my favorite things I've learned at Hack Reactor is the importance of breaking code into small units with clearly defined purposes, which can then interact with each other. This has several benefits.
- Easier to reason about your program. It's hard to wrap your mind around a function that does five different things. It's easier to track what's going on in your program when you can envision the flow from one small function to another. It's nice when you can evaluate one part of your program independently of the others.
- Code is more reusable. If you keep your functions small and with very clear, specific purposes, it's easy to reuse them elsewhere. A "getsAndFormatsAndSortsChatMessages" function is really specific to one task. A smaller function likes "sortsInputsReverseChronologically" can be used for many things.
- Easier debugging. You can quickly find out exactly which part of your program is throwing an error when each little part of the program is labelled with a descriptive function name like sortsMessages instead of being buried in a huge function like getsAndFormatsAndSortsChatMessages.
- Easier to split up work. It's better to assign each team member to work on a certain component than to have everyone simultaneously mucking around in one undivided chunk of code.