Summary
In this chapter, we made good progress with learning about functions. Although functions have been lurking in our code since the first chapter, we finally got to study and understand them formally. We learned about the different parts of a function: the name, the parameters, and the return type. We have seen that what the function actually does goes inside the opening and closing curly brackets, and is called the function body.
We also saw that we can return from a function at any time by using the return
keyword, and that we can also use the return type in conjunction with the return
keyword to make data from the function available to the code that called the function in the first place.
We learned how we can use default and named arguments to provide different versions of the same function without writing multiple functions. This makes our code more succinct and manageable.
We also discovered that there is even more to functions than we covered in this chapter, but that it is best...