High Maintenance:
Declare the globals to be used in each proc, using individual variables
Example: Two procs with several global variables
proc volume {} {
global height width depth area
set volume [expr $height * $width * $depth]
}
proc area {} {
global height width area
set area [expr $height * $width]
}
Advantage:
Disadvantage:
Use a state array to hold global variables
Example: Two procs with several global values
proc volume {} {
global values volume
set volume [expr $values(height) * $values(width) * $values(depth)]
if {[catch {testContainerSize $volume}] } {puts "Error: $errorInfo"}
}
proc area {} {
global values area
set area [expr $values(height) * $values(width)]
}
Advantage:
Disadvantage:
Lower Maintenance:
Create a list of variables to declare global.
Example: Two procs with several global values
proc area {} {
global globalList ; eval "global $globalList"
set area [expr $values(height) * $values(width)]
}
proc volume {} {
global globalList ; eval "global $globalList"
set volume [expr $values(height) * $values(width) * $values(depth)]
}
set globalList [list values area volume errorInfo errorCode]
Advantage:
Disadvantage:
Use a proc with uplevel to declare the globals
Example: Two procs with several global values
proc declareGlobals {list} {
global $list
uplevel "global [subst $$list]"
}
proc area {} {
declareGlobals globalList
set area [expr $values(height) * $values(width)]
}
set globalList [list values area volume errorInfo errorCode]
Advantage:
Disadvantage: