Don't use globals. If you have a problem with constants, I would use a singleton or a globals hash. Single globals become a serious problem.
------ We are the carpenters and bricklayers of the Information Age. Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement. Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified. | [reply] |
Globals aren't that bad. They are package scoped afterall, and very efficient too. If you use a convention, like consistently using uppercase for constants, you shouldn't have many problems. If you want to keep the constants private, you can use file scoped lexicals instead of globals and protect yourself even further.
A global hash isn't a terrible alternative, but the syntax is messy and you don't benefit from strict checking.
But a singleton? Ugh...
How about a tied scalar? (just kidding)
-sauoq
"My two cents aren't worth a dime.";
| [reply] |
I don't see a problem with using globals for constant values. They have the same scope as the subroutines created by the constant pragma.
| [reply] |