Breaking Out Functions
The teachers at Hack Reactor tell us that functions should usually be longer than five lines. Each function should do a minimum of work. This makes it a lot easier to think about how the program as a whole works. It's easier to understand a process where an input goes through a series of steps, getting modified at each one, than to picture a process where an input goes into one big, gnarly machine.
Today's toy problem was to make filler text generator, to make Lorem Ipsum type text. We were given an empty function named generateFillerText that took as its argument the number of words that the returned text was to consist of.
First I thought of it as one big function that would take in the number of words, do a bunch of work, then return the appropriate text. As I discovered complications, though, the function got long, and it became apparent that there were a few different jobs it was doing. So, first, I split out a word generator function. That was an improvement, but then I realized that building sentences was a different task than building a collection of sentences. So I split out the sentence building function.
Then, I was able to wrap my mind around the problem better.











