What Tom said plus:thanks guys.. question: what's the problem with public variables?
Publics are not a good option for modular applications. They make your code difficult to incorporate into a larger application.
You should NEVER use publics when trying to develop portable code that can be used in multiple applications, such as a Document System, Calendar System, etc.
Publics and Privates make code difficult to maintain because the programmer must have intimate knowledge of the entire application. It is very difficult to understand code in subroutines and functions that must access Public and Private variables because there is no pointer back to the origin of the variable. Locals and object-oriented code make it much easier to encapsulate code so that it becomes more portable.
I work a lot with code written by other programmers and nothing is more difficult to work with than code that uses Publics and Privates. Team programming is almost unmanageable, unless there are only a few.
Tom's comment about other threads stepping on Publics is not a really big issue for me because I found a solution to that problem many years ago. You can temporarily Privatize a Public variable when launching a new thread like below. I developed this technique when converting a large Clipper application that needed to run existing code in multiple windows.
Code: Select all
FUNCTION Main()
PUBLIC cCustomerName := 'Roger Donnay', cCustomerPhone := '208-999-9999'
oThread := Thread():new()
oThread:start({||EditCustomer()})
FUNCTION EditCustomer()
PRIVATE cCustomerName := cCustomerName
PRIVATE cPhoneNumber := cPhoneNumber
cCustomerName := 'Tom Liehr'
cPhoneNumber := '+011 64 888 8888'
RETURN nil