I’ve read that good programming practice claims that one should use a function if a block is to be used repeatedly in a program. But what if you have a procedure with clear conceptual boundaries, but it is only called once. Should you immediately write it in the main code or should you put it into a function and invoke it in the main code?
I’ve read that good programming practice claims that one should use a function if
Share
Write-once is one reason to use functions. However, any block of code with clear conceptual boundaries is a great candidate for a function.
The resulting logic flow of your script will be more straightforward and easier to read/debug.
For example, consider you have a database script that runs some basic audits before continuing with the main work. This happens once in the script, but the resulting logic flow would be:
Nice and clean, easy for others to read and maintain.