Tinderbox v11 Icon

White space in code

Here the term 'white space' most generally applies to use of the space character.

Within action and export code operators

White space may not be used between the operator name and the parentheses used to hold input arguments:

collect(children,$Name) Good
collect(children, $Name) Good
collect (children,$Name) ERROR
^comment(data)^ Good
^comment (data()^ ERROR

No space allowed between the operator name and the parentheses, but spaces may be used between input arguments inside the parentheses. If the operator does not require trailing parenthreses, then normal general white space rules apply.

In action code operators using curly braces

A number of operators enclose code after the operator in curly braces, for instance the conditional 'if' test:

if(){...}else{...} 

Space before or in the parentheses is as in the section above. However, spacesafter the closing parentheses or before opening braces or after closing braces are allowed. Line breaks are also allowed in this position but by convention are generally only used inside the braces so that any code enclosed is placed on a discrete line, for clarity of human reading.

if() {...} else {...} 

is good as is

	if(){
	...
	}else{
	...
	} 

In queries (agents and conditional operators)

White space around comparison operators is allowed. All these work:

$Name == "test" 
$Name== "test" 
$Name=="test" 
$MyNumber > 4 & $Created==date("today") 
$MyNumber<=6 

Around assignment (=) or arithmetical operators

As with queries white space is ignored. All these work:

$Name="foo"; 
$Name = "foo"; 
$MyNumber = 2 * 6; 
$MyNumber=2*6; 

It also applies to the 'reset' usage to (re-)apply an attribute default value:

$MyString =; 
$MyString = ; 

The latter works but is less seen as it might imply a right side argument has mistakenly been omitted.

It is not necessary to use spaces paired before and after. These both work:

$Name ="foo"; 
$Name= "foo"; 

though generally balanced use of white space helps the human readers

Inside quoted literal strings

These are considered different strings as the white space has semantic purtpose:

"Hello world" 
"Helloworld" 

Be are that when concatenating (joining) strings, or setting attribute values, any trailing/leading space may be elided. If uncertain, test and this:

$Name = "Hello" + " world"; 

can always be re-written as:

$Name = "Hello" + " " + "world";