Why use functions?


There are two main reasons to use functions.

One of the is code reuse. Instead of copy-paste-ing snippets of code that does the same in multiple areas in the application, we can create a function with a single copy of the code and call it from multiple location.

Having functions can also make the code easier to understand, easier to test and to maintain.

The functions are supposed to be relatively short, each function dealing with one issue, with one concern. They should have well defined input and output and without causing side-effects.

There are no clear rules, but the suggestion is that function be somewhere between 4-30 lines of code.