cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

Names Default to Here(1) as the default namespace

Several other programming languages default to the local namespace/environment rather than a global environment. JMP Experts say the NamesDefaultToHere(1) is the BKM whenever scripting as typically the local namespace is appropriate for new scripts to avoid clashing with other JMP scripts. It would be more convenient to define NamesDefaultToHere(0) when you want a script to be in the global namespace rather than defining every script with the "true" argument

3 Comments
Chris_Rodrigues
Level III

Having Global namespace as default is an extremely poor design decision, in my opinion, although I understand it may be necessary for backwards compatibility with JSL scripts written in earlier versions of JMP.

 

I think any new JSL coder learns about this the hard way when strange, difficult-to-debug things start happening because of variable name collisions with multiple scripts; in particular, with the detritus left behind by scripts that have been run earlier under the global namespace.  Since variables do not require declaration in JSL, and global namespace is the default, I believe it is absolutely crucial to initialize all variables to an empty state at the top of my script to be certain that unexpected values do not intrude into my script, causing confusion and mayhem.

 

Of course, it is also good practice to put Names Default To Here(1); at the top of every single JSL script ever written, everywhere, always, unless the script needs to use the global namespace for some strange reason.  Even in such a situation, I feel it would be better to set the default namespace to Local and refer to all Global variables as the global namespace explicitly using the ::global_name syntax.  Thus, if default global namespace is truly necessary for backwards compatibility, we should have the option for the script editor to always insert Names Default To Here(1); at the top of all new scripts, instead of requiring the coder to remember and type this out every time.

 

Even with these precautions, I still sometimes encounter edge cases where collisions occur.  For example, the Summation and Product functions include an implicit variable named by default.  That's fine when used inside of a script where I already set default local namespace.  But what about column formulas?  I don't normally think about column formulas as scripts, even though that's exactly what they are.  I edit them graphically using the GUI formula editor.  It had never crossed my mind.

 

Well, the first time I used a Summation in a column formula, I also happened to run a table script where I had forgotten to set local namespace, in which I used a For loop with the iterator as i.  This, unsurprisingly, led to confusion and mayhem.  The application became unresponsive, stuck in an infinite loop, and I had to kill the task.  Then I had to try it a few more times before I finally realized the terrible, obscure mistake I had made, fomented by the trap that had been set by the Summation's pernicious global iterator.  Long story short, now even in Column Formulas I double-click the script editor and insert the Names Default To Here(1);.  No script is safe without it.

 

Status changed to: Acknowledged

Hi @cnattrass, thank you for your suggestion! We have captured your request and will take it under consideration.

SamGardner
Staff
Status changed to: Investigating