Guidelines for using subroutines

You can divide code blocks into structures called subroutines. With subroutines, you eliminate code duplication in scripts, and you can reuse snippets of code.

Keep subroutines simple and small

Try to keep your subroutines small. Small scripts are easier to maintain than large scripts, and this applies to subroutines too. Keep your subroutines as small and simple as you can.

Use subroutines to avoid code duplication

You should avoid duplicating code at all costs. Instead of duplicating code, change the code you want to duplicate into a subroutine for reuse.

Remove unused subroutines

Remove unused subroutines from the script, even if comments describe why those subroutines are unusable.

If you use subroutines only in specific scenarios, use conditional flows to handle them. For code debugging subroutines, use a test script.