Hi developers!
Just want to share an old but always relevant best practice on namespaces changing @Dmitry Maslennikov shared with me (again).
Consider method:
classmethod DoSomethingInSYS() as %Status
{
set sc=$$$OK
set ns=$namespace
zn "%SYS"
// try-catch in case there will be an error
try {
// do something, e.g. config change
}
catch {}
zn ns ; returning back to the namespace we came in the routine
return sc
}
And with new $namespace the method could be rewritten as:
classmethod DoSomethingInSYS() as %Status
{
set sc=$$$OK
new $namespace
set $namespace="%SYS"
// do something
return sc
}
So! The difference is that we don't need to change the namespace manually as it will be back automatically once we return the method.
and we don't need try-catch (at least for this purpose) too.