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

JSL ignores white-spacing for names, most people don't take advantage of this!

Not an important question, but I've often wondered why.

 

At my company there are many casual scripters in JSL and a few heavy-weights.  I'm a voracious consumer of other peoples code (reading) and have read a great deal of code from more than 20 people here.  Also, I've seen many examples of code posted here in the community forums.

 

Almost universally I see that the code authors do not take advantage of JMP's strange decision to ignore white-spaces and case in names.  Below are some examples.

 

It seems that most people use built-in functions -- such as Insert Into() -- with white-spacing, but for user-defined names generally opt out of doing it.

My main question is why?  I find that code is much quicker to read when using white-spaces as one would in general writing.

 

I can understand when someone comes from a traditional programming language, but I've seen quite a few folks here at my job that are first-time scripters, and they will generally do the same (use spaces for built-in names, not use spacing for user-defined names).

 

Personally I've grown to greatly appreciate the flexibility that JSL affords names, but I'm curious as to what other folks here think.

 

Examples:

from @drewfoglia  in this post:

ErraticAttack_0-1705367082105.png

 

 

from @Phil_Brown  in this post:

ErraticAttack_1-1705367098015.png

 

 

The file libRecall_v2_0.jsl by @MikeD_Anderson 

 

And here is an excerpt from my code -- I use white-space in names extensively:

ErraticAttack_4-1705366535356.png

 

 

Jordan
1 ACCEPTED SOLUTION

Accepted Solutions

Re: JSL ignores white-spacing for names, most people don't take advantage of this!

Well - I can't speak for the others, but for my part, it's mostly habit. I was coding in Basic, VB, LaTeX, and Mathematica long before I started doing JSL.  All those languages have restrictions on the whitespace.  It never made sense for me to retool my skill set for one language when it would make it harder for me to step back into the others or step into new ones (like when I picked up Python over the lockdown). 

View solution in original post

9 REPLIES 9
jthi
Super User

Re: JSL ignores white-spacing for names, most people don't take advantage of this!

I think when I started writing JSL I immediately opted out of all the ways JMP lets you set the names and most likely it was because I didn't really trust it and it felt weird (I had some background from javascript and Python BUT I didn't have any proper programming style for any language back then).

 

Nowadays I do use code reformatting quite a lot when writing JSL and it will add whitespace to JMP names (because I have insert Spaces in operator names enabled). And in my names I don't use whitespace (I loosely follow some sort of Python Style Guide for JSL), this does (sometimes) help me separate my own names from JMP created names.

-Jarmo

Re: JSL ignores white-spacing for names, most people don't take advantage of this!

Well - I can't speak for the others, but for my part, it's mostly habit. I was coding in Basic, VB, LaTeX, and Mathematica long before I started doing JSL.  All those languages have restrictions on the whitespace.  It never made sense for me to retool my skill set for one language when it would make it harder for me to step back into the others or step into new ones (like when I picked up Python over the lockdown). 

ErraticAttack
Level VI

Re: JSL ignores white-spacing for names, most people don't take advantage of this!

I do definitely have a number of issues switching from JSL to Python / JavaScript!  If you're spending a lot of time switching between languages it does make sense to keep a uniform format as much as possible.

Jordan

Re: JSL ignores white-spacing for names, most people don't take advantage of this!

Another thought on this - since the built-in variables (formulas, etc) have syntactic highlighting built into the JSL editor, it's easy to tell that they're something special.  With the user defined stuff - it gets hard to tell what's one variable or two that might be missing a semicolon between them.  That would make debugging more difficult on longer scripts and applications.  

hogi
Level XI

Re: JSL ignores white-spacing for names, most people don't take advantage of this!

Hm, after investing 2 hours in debugging a script and then finding out that Concatenate, sometimes,  differentiates between upper and lower case, you will start to wonder why column "Age" can be different from column "age" and column "a g e":
(c) @jthi from data-table-message-column-exists-colname 

View more...
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt:age << set name("a g e");
dt:age[1] = 999;


Show(Column(dt, "age")); //Column(dt, "age") = Column("a g e");
Show(dt:age[1]); //dt:age[1] = 999;

dt << New Column("age", Numeric, Ordinal);
Show(Column Name(2) == Column Name(6)); // Column Name(2) == Column Name(6) = 1; // Columns don't need unique names?
Show(Column(dt, "age")); //Column(dt, "age") = Column("age");
dt:age[1] = 9999;
Show(dt:age[1]); //dt:age[1] = 9999;

wait(1);

dt << Delete Column("age");
Show(Column(dt, "age")); //Column(dt, "age") = Column("a g e");
Show(dt:age[1]); //dt:age[1] = 999;

This was the time when I decided to stick to one rule

Nevertheless, soon it will be a bit easier:
Via dt << Has Column() a user will have the possibility to check for a column - and choose if the match has to be exact or with some freedom:

 

hogi_0-1705874367096.png

 

ErraticAttack
Level VI

Re: JSL ignores white-spacing for names, most people don't take advantage of this!

You're right about column names -- they aren't strictly matched to the name structure of most JSL names.  That is great to hear of the new JMP18 feature -- I'll definitely use it a lot!

 

Another issue with JMP column names that would be amazing if it were to be fixed -- the fact that they take precedence over local / here names.  In the example script here I cannot use the Here name "device" because it has the same name as a column in the little table.

 

JSL should have a strict column reference mode that ONLY allows columns to be accessed (outside of column formulas) via explicit scoping.  That would be a nice thing...

 

Names Default to Here( 1 );
device = "ABC";

dt = New Table( "test",
	<<New Column( "DEVICE", "Character" ),
	<<New Column( "VALUE", "Numeric" )
);

device = "TOOL1";

dt:device = device;
Jordan
hogi
Level XI

Re: JSL ignores white-spacing for names, most people don't take advantage of this!

Maybe here the problem is that it's not possible to write a String to a column, but just to a cell:

Names Default to Here( 1 );

dt = New Table( "test",
	Add Rows( 1 ),
	New Column( "DEVICE", Character)
);

device = "TOOL1";

dt:device[1] = device; 
hogi
Level XI

Re: JSL ignores white-spacing for names, most people don't take advantage of this!

yes, if local names and columns have the same name, it's a lot of fun to use both in parallel:

 

Names Default to Here( 1 );

xxx = "device";

dt = New Table( "test", add rows(10), New Column( "DEVICE", set each value (random integer(20))),
New Column( "VALUE", set each value (1))
);

device = "value";

Print(device);

distribution of DEVICE = Distribution(	Continuous Distribution(	Column( device )	));
distribution Of VALUE = Distribution(	Continuous Distribution(	Column( Eval(device ))	));
another distribution of DEVICE = Distribution(	Continuous Distribution(	Column( "device" )	));

:value << set formula(device);

wait(3);

:value << set each value (device)

In total, there are 13 rules + some exceptions!
https://www.jmp.com/support/help/en/17.1/?os=win&source=application#page/jmp/rules-for-resolving-nam... 

 

ErraticAttack
Level VI

Re: JSL ignores white-spacing for names, most people don't take advantage of this!

There are a lot of rules, but it would be nice to have a flag in JSL to turn on a strict mode, such that unscoped names are FORCED to be local (as in, only check the local scope, not HERE, not GLOBAL, and certainly not any column-names), and anything not local is required to be explicitly scoped.  That would be nice.

Jordan