Using Namespaces to Avoid Variable Collision and Allow for Cleaner Scripting
Aug 13, 2015 6:27 AM
Vince Faller, Meteorology Engineer, First Solar
Since the inclusion of namespaces in JMP, scripting has become much easier to do without the need to worry about creating unique instances of variables. This becomes especially viable in longer scripts where references to multiple objects need to be kept and recalled easily. It allows for the segmenting of code, when namespaces are combined with include(), into bite-sized chunks that can be more easily read by others. Garbage collection of entire chunks becomes much easier, using one variable instead of listing out all the specific variables to be cleared. The use of the Here namespace is especially useful in this regard. It allows libraries of user-defined functions to be made that won’t be accidentally cleared by a user. At the same time, this namespace will allow those variables to not be locked as well. This has the benefit of not crashing another user’s script if it uses the same variable name without the need of superfluous Try()s. I’ll walk through the many benefits of namespaces, discuss the current limitations of them, and talk about some methods for dealing with those limitations.