The simplest form of a function is one that takes no arguments as input. Suppose that you wanted to put your name and contact information in the upper left corner of the canvas for every program that you write in Processing. We can create an abstraction of this algorithm by writing a function called signature() that performs the algorithm when we call it (the draw() and setup() functions are special in Processing and they do not need to be called). Here’s what that definition would look like:
Let’s break down what’s happening here. The first line uses the keyword def to define a function called signature(). A pair of parentheses must follow the name of a function in a function definition, then a colon. This entire line is called the function header. Notice how the rest of the lines after the function header are indented. In Chapter 1, we called this a block; when it’s part of a function, we also refer to such a block as the function body. Just like in our pseudocode, we group statements in blocks by indenting them. All of the Python code in a function body is in the same block, so it has to be indented. What’s more, we indent by the same amount or Python will complain, thinking that some lines are not part of your function even when you want them to be.
Consider the following examples where the indentation is incorrect: