# 6.1. Why Higher Order Functions¶

Before we start working with functions as inputs to other functions, let us try to answer the question “Why?”

There is no problem that we need to solve using this trick. But, it can make our solutions easier to read and understand and allow us to reuse common algorithms instead of constantly reinventing the wheel.

Note

You do NOT need to build any of the scripts in this section. Just read on and watch the video to get the big picture idea of what our goals are.

This video introduces the idea:

### Key "Why" Ideas

To recap the video, our reasons for using this technique:

1. It is silly to repeat basic recipes like “Make an index counter, repeat (length of list) times, do something to current item, increment counter”. The only part that changes is the do something to current item part… one rule of good programming is if you have to say the same thing over and over, you are probably doing it wrong.

2. The code ends up much more readable. Which of these is easier to read and understand the intent of:

OR

3. Writing code in this fashion can help us write programs that can run in a parallel fashion (be split between multiple machines that cooperate to do a job… more on this later.

### Imperative vs Declarative

Reason #2 gets at the issue of programming style. Imperative programming is specifying exactly what to do. Declarative programming is describing the results you want to see.

Imperative add numbers in (list):
Set index to 1
Set total to 0
Repeat (length of list)
Change total by (item (index) of (list))
Change index by 1
Report total