Functions are among the most important concepts and constructs of any language, so let me give you a few reasons why we need them:
- They reduce code duplication in a program. By having a specific task taken care of by a nice block of packaged code that we can import and call whenever we want, we don't need to duplicate its implementation.
- They help in splitting a complex task or procedure into smaller blocks, each of which becomes a function.
- They hide the implementation details from their users.
- They improve traceability.
- They improve readability.
Let's look at a few examples to get a better understanding of each point.