Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Syntax Error
Message
 
À
27/12/1999 17:51:39
Jimmy Ditta
Twin City Electronics
Monroe, Louisiane, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00308731
Message ID:
00309066
Vues:
30
>Hey Mike,
>
>I've seen you say not to use public variables on a couple of occasions. I'm just wondering why.


Jimmy,

I'm sure Mike would be glad to tell you this also.

PUBLIC is a word that should be banned from public use. There is only one reason to declare a variable public, that is that it must be referenced somewhere above the declaring routine.

No routine should ever deal with a variable it did not create. That's a pretty broad statement and it is possible to build systems that adhere to it, however, it is sometimes easier to allow some data to cross the boundaries of the routines. Using Private variables allows this to occur. Private vars are visible to the routine that creates them and all routines below that one in the calling stack. So a routine can create a variable that lower routines can see and manipulate (without resorting to public).

Using PUBLIC is similar to saying, "I want this variable to stomp all over everything and anything that has run or may run at anytime in the future. I want it to have no respect for encapsulation or the boundaries of the routine that is creating it. I want it to mess with any third party add ons I decide to use now or in the future. I much prefer my bugs to be impossible to track down so I will insure that this variable can smash any other code and that I will get the shear pleasure of reviewing every line of code in the system when anything doesn't work right."


Keep in mind that there is a big difference between global and public. A global variable is one that all routines can access while a public is a way to cause problems for yourself.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform