It is good to have a function that is small, and pure and will perform only one thing and do it very well. Let’s look at the point that you should include while writing a function in any programming language.

Before starting, in simple words:

Extract till you drop

First rule of functions is that they are small

Extract the function as small as possible. It will help you write cleaner and error-free code with high testability.

They are smaller than that

You should always re-think the way to make them smaller than they are. If you can think of a smaller function then optimize it.

Lots of little well-named functions because they will save you and every one time.

Little good name functions are very clear and concise for another developer to understand. For example, A function with the name Array. sort() is a good name and we can understand it will sort array without any doubt. Though there might need a longer name in real-world programming we can always find a worthy name to explain its function simple way.

Most of us don’t have to worry about the efficiency of function calls.

Theoretically, yes too many functions will make a program slow. But, the answer of HOW MUCH?

Negligible.

Will it affect performance? Should I stop writing functions?

No Way. Never. For 99% of apps, this is just a few extra instructions and stack operations. It is insignificant when compared to the execution time for your whole program.

Making functions small save time.

It is easier to understand, debug and write a smaller function. So small functions always save time.

Functions do One Thing.

It is important, that function needs to do only one thing and do it very well. Attempting to do a lot of things inside a single function will make it impossible to test and understand.

They do it well and do it only.

We should always make sure they do it very well.

If you can extract one function from another, you should.

If the function can be extracted then you always extract it.

Classes hide in long functions.