11.1 Introduction

11.1.1 Terminology

The notion of function is quite fashionable, but conveys different meanings. Two distinct uses:

  • Mathematical notion of a “function”: Provide a mapping between sets of elements.

  • A “functional” explanation explains a natural phenomenon (e.g., why did many creatures evolve to have two eyes?) in terms of its goals or purpose.

In programming, functions also provide mappings, but are better thought of as tools for solving tasks. Programming functions requires identifying tasks that will be encountered and thus need to be solved repeatedly (by ourselves or others).

11.1.2 The function of functions

Functions enable abstraction:

  • Expressing a process solely in terms of its goals and results (i.e., a mapping between inputs and outputs).

  • Functions can be used as “black boxes”: We do not need to understand the mechanism (i.e., the process or computations taking place inside a function) in order to use a function.

From a system design perspective, functions enable hierachical and modular designs:

  • Functions can call other functions, etc.

  • We can edit and replace functions without changing the rest of the system.