Main goal today is to revisit what we've learned so far. We also want to put some of the different concepts together, by going back to already solved coding excercises, and refactoring the code so that it now contains methods.
Beginners often wonder why it is worth the trouble to create new methods. There are many reasons, but this example demonstrates a few of them:
- Creating a new method gives you an opportunity to give a name to a group of statements, which makes code easier to read and understand.
- Introducing new methods can make a program smaller by eliminating repetitive code. For example, to display nine consecutive new lines, you could invoke threeLine three times.
- A common problem solving technique is to break tasks down into sub-problems. Methods allow you to focus on each sub-problem in isolation, and then compose them into a complete solution.