![]() |
H.4 Streamlining Code with Local Routines |
SheerPower’s local routines are designed to make breaking up large routines into smaller pieces fast, safe, and clean. They reduce bugs and simplify development.
Local routines inherit the variable scope of their parent. You can use any variable from the parent routine directly, without passing it as a parameter. This reduces complexity and eliminates boilerplate.
Each local routine handles a focused task but stays tied to the main routine logically. This makes the code easier to understand, since unrelated tasks aren’t mixed together.
Local routines can only be invoked from inside their parent routine. This disallows accidental use elsewhere and avoids name conflicts in the global scope.
You can move sections of a large routine into local routines without needing to rewrite variables or handle lengthy parameter passing. It’s fast, clean, and safe.
Local routines must be defined after their parent calls them, but outside of the parent itself. This enforces a logical structure without being restrictive— for example, you can group all your local routines at the end of the file. If a local routine is ever called from outside its parent, SheerPower gives a compile-time error.
By isolating specific logic into local routines, you can more easily track down bugs. Smaller units are easier to test and diagnose than large blocks of code.
Splitting large routines into local routines is easy to do and creates a clean top-down view. The parent shows the overall logic, while the local routines handle the details.
Hide Description
|
|
Enter or modify the code below, and then click on RUN |
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |