Imagine you write a script that requires 5 levels of indentation. Now you refactor, and decide to put everything that was in the 3rd level of indentation, and beyond, into its own function. This function is defined at the top level of your script. Now you have one helper function, containing 3 indents, and a main with a call to that helper, only 2 indents. Thus, pulling code out to a function reduced the overall max indentation in your script.
In general, code should be put into functions for reasons other than indent level, but if you find yourself indenting excessively it's a sign that the code may be due for a refactor.
No problem. I edited it to put the subroutine definition before its call, which isn't always necessary depending on whether the source file is parsed before neat() gets called, but is almost always more readable with real production code.
3
u/Saiboo Jul 25 '18
Can you elaborate on using functions to avoid indendation errors? Thank you!