Information générale
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
>I believe this is a bad practice, but this is my personal opinion. If a variable is PUBLIC, then the
>programmer must assume that this variable is available at all times. Otherwise it would not be
>public. If you declare the public variables at a point in time later than main.prg, you can fall into
>the trap to add later functionality or reuse code that makes use of those public variables, and
>call that code before the variables are declared. There is not a practical way to properly document
>this in the code and it can create program errors that are very difficult to trace.
Write a program that inserts a check at the location of every PUBLIC definition to see if it's already defined. You can then identify all cases just by running the program through its paces.
>>(2) To prevent the need for initializing variables within a oft / repeatedly called function
>Again here you can create objects that are instantiated at the beginning and when passed
>as parameters they will be available in the repeated function calls.
You're still creating and passing unnecessary things to the called functions. And you're still dealing with objects, which means looking elsewhere for accessor methods and other variables.
SometimesAlmost always simpler is far, far better for readability, understandability, and long-term maintenance. PUBLIC variables definitely have their place. Depends on many factors. Code should be clean and self-explanatory, not buried under layers of classes.
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement