Functions
In the program structure section in Lesson 1, we mentioned that functions are a key part of Swift's structure, and are units of code that can accept parameters and can return values. In this section, we'll dive into Swift functions, learning how to implement and call them in the course of a Swift application.
Before diving into Swift function syntax, we should summarize some key points about how functions are used in Swift, and in modern software development generally:
Functions are units of code that carry out some specific task.
In terms of lines of code, functions should be short. How many lines of code is a maximum for a function has been a topic of debate for decades. However, long functions often do not satisfy the specific task definition.
All things being equal, it's better to have a complex process broken into smaller functions, rather than combined into a large, complex function.
All things being equal, a function that references its parameters—but not global variables...