Coding Practice: What is the maximum number of lines of code for a function?
In general, a function should fit on your screen both length and width wise without requiring you to scroll, which is about 50 lines. A function is the right size if it only has a single responsibility, which tends to result in short functions.
“The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that. Functions should not be 100 lines long. Functions should hardly ever be 20 lines long.”
– Robert Martin
You can test a function for single responsibility in a function by making sure its name indicates exactly what the function does. If the name of the function is too long, then the function is probably doing too much. Go ahead and break the function into multiple functions each with their own area of responsibility.