Avoid Spaghetti Code with Scope Minimization
Let’s see some recommendations on how to prevent the phenomenon of spaghetti code just by minimizing the visibility of variables.
Our aim will be reducing to the minimum possible the portion of code where our variables are visible over the source code, namely reducing the scope of variables.
Source: Avoid Spaghetti Code with Scope Minimization, an article by Massimo Nazaria.