cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
hogi
Level XII

JSL: if - else -> find the commas?

Hi,

 

I often face the problem that a code doesn't work because 1 out of 10 semicolons is a comma or one comma which belongs to the if block is actually missing.

Is there an easy trick to make the blocks in an if-else clause more visible?

 

1 ACCEPTED SOLUTION

Accepted Solutions
hogi
Level XII

Re: JSL: if - else -> find the commas?

Hm, I just thought: 

If there is this wonderful GraphBuilder in Jmp which helps you to generate every kind of graph within 5 seconds,

it should also be possible to analyze complicated If & Match structures in < 5 seconds to find any error in the structure.

 

Automatic indentation via "reformat script" is great - it shows the complete hierarchy of the code structure - at a single glance.

But that's also the disadvantage: The complete hierarchy

 

This is why a human eye needs some time to analyze the information - and even needs some support from the brain to do so.
There are ways to encode information in a format where the "eye" needs less support from the brain - as one can learn from  @XanGregg :
Plenary: All Graphs Are Wrong, but Some Are Useful - Xan Gregg 

 

Thinking along this line ...

A Click on a bracket to highlight the If statement is very useful

- but it would be great if the shading of the included text was not uniform (like in the picture on the left) - but in a meaningful way (like in the picture on the right).

Jmp has all the information that is needed (it uses it to adjust the indentation) - why not use it for the shading?

 

It's clear that there is NO additional information in the picture on the right which cannot be deduced from the indentation on the left.

And the indentation can even show more: the complete hierarchy of the complex code structure at a single glance. Yes.

But the right image looks quite convinding, right?

edit: link to the wish

 

 

hogi_3-1669376512364.png             hogi_4-1669376548370.png

View solution in original post

17 REPLIES 17
txnelson
Super User

Re: JSL: if - else -> find the commas?

Right click on the JSL window, and select "Reformat Script".

That will align the blocks at standard indentations.

You can also click on any function or matrix boundary bracket {} [] and it will select the matching bracket 

Jim
Ressel
Level VI

Re: JSL: if - else -> find the commas?

I liked what this man had to say here.

 JMP doesn’t care about this formatting but you will quickly get into a mess if you don’t have the discipline to write the code in a way that reflects the hierarchy of display boxes.

This statement doesn't exclusively apply to display boxes, but JSL in general. I am still learning myself, but it is a good investment of time to visually structure code into logical parts, even if it sometimes turns into a forensic exercise (which, coincindentally, is where most learning tends to happen).

hogi
Level XII

Re: JSL: if - else -> find the commas?

Hm, I just thought: 

If there is this wonderful GraphBuilder in Jmp which helps you to generate every kind of graph within 5 seconds,

it should also be possible to analyze complicated If & Match structures in < 5 seconds to find any error in the structure.

 

Automatic indentation via "reformat script" is great - it shows the complete hierarchy of the code structure - at a single glance.

But that's also the disadvantage: The complete hierarchy

 

This is why a human eye needs some time to analyze the information - and even needs some support from the brain to do so.
There are ways to encode information in a format where the "eye" needs less support from the brain - as one can learn from  @XanGregg :
Plenary: All Graphs Are Wrong, but Some Are Useful - Xan Gregg 

 

Thinking along this line ...

A Click on a bracket to highlight the If statement is very useful

- but it would be great if the shading of the included text was not uniform (like in the picture on the left) - but in a meaningful way (like in the picture on the right).

Jmp has all the information that is needed (it uses it to adjust the indentation) - why not use it for the shading?

 

It's clear that there is NO additional information in the picture on the right which cannot be deduced from the indentation on the left.

And the indentation can even show more: the complete hierarchy of the complex code structure at a single glance. Yes.

But the right image looks quite convinding, right?

edit: link to the wish

 

 

hogi_3-1669376512364.png             hogi_4-1669376548370.png

txnelson
Super User

Re: JSL: if - else -> find the commas?

I like your thinking on this, and other thoughts you are having on improvements to JMP and JSL.....I suggest you add these to the JMP Wish List,.  That will get your input to the individuals who can actually make the changes.

Jim
hogi
Level XII

Re: JSL: if - else -> find the commas?

thank you for your support

here is the wish:
optimized syntax highlighting in JSL editor 

 

pauldeen
Level VI

Re: JSL: if - else -> find the commas?

JMP should hire you into a product quality role! Love it!

ErraticAttack
Level VI

Re: JSL: if - else -> find the commas?

My solution to this is to put important commas at the level of the enclosing fence.  Here is an example -- notice that the commas separating the IF blocks are at the level of the IF statement, and the same for TRY

 

Names Default to Here( 1 );
dt = Current Data Table();

Try(
	If( Contains( dt << Get Column Names, As Name( "height" ) ),
		mean = Col Mean( dt:height );
		max = Col Max( dt:height );
		min = Col Min( dt:height );
		std dev = Col Std Dev( dt:height );
		Write( "\!NSome stats on :HEIGHT:",
			"\!NMin: ", min,
			"\!NMax: ", max,
			"\!NMean: ", mean,
			"\!NStd Dev: ", std dev
		)
	,
		Contains( dt << Get Column Names, As Name( "weight" ) ),
		mean = Col Mean( dt:weight );
		max = Col Max( dt:weight );
		min = Col Min( dt:weight );
		std dev = Col Std Dev( dt:weight );
		Write( "\!NSome stats on :WEIGHT:",
			"\!NMin: ", min,
			"\!NMax: ", max,
			"\!NMean: ", mean,
			"\!NStd Dev: ", std dev
		)
	,
		Contains( dt << Get Column Names, As Name( "age" ) ),
		mean = Col Mean( dt:age );
		max = Col Max( dt:age );
		min = Col Min( dt:age );
		std dev = Col Std Dev( dt:age );
		Write( "\!NSome stats on :AGE:",
			"\!NMin: ", min,
			"\!NMax: ", max,
			"\!NMean: ", mean,
			"\!NStd Dev: ", std dev
		)
	,
		Print( "Cannot find columns 'height', 'weight', or 'age'" )
	)
,
	Print( "mistakes were made" )
)
Jordan
jthi
Super User

Re: JSL: if - else -> find the commas?

I use a bit similar style as @ErraticAttack but I separate conditions to same line as , and might even comment else and catch if the blocks are long

Names Default To Here(1);
dt = Current Data Table();

Try(
	If(Is Empty(dt),
		print("no table found");
	, N Rows(dt) == 0,
		print("table has no data");
	, N Rows(dt) <= 10,
		print("not enough data");
	, // else
		print("ok")
	);		
, // catch
	show(exception_msg);
);

I try to avoid using jsl re-formatting after my scripts gets long /complicated enough as I usually have to clean-up after using it. Even if reformat was as flexible as I would need it to be, I think I wouldn't bother configuring it properly...

-Jarmo
hogi
Level XII

Re: JSL: if - else -> find the commas?


@jthi wrote:

configuring [re-formatting] properly...


is there a way to configure re-formatting?