Whitespaces (spaces, tabs, and new line characters) are allowed anywhere in the code. Proper use of whitespace does make code a lot easier to read and more pleasing to the eye.
Spaces are mandatory at the following places:
Before an open parenthesis
At function calls
At if and while expressions
After a comma
At parameter lists in function calls
At list and map elements
Before and after a binary operator (= is a binary operator)
New lines are mandatory at the following places:
After every statement. As a rule of thumb, a semicolon must be followed by a newline.
Before and after every opening brace.
Before and after every closing brace.
After the initial variable declarations before the first statement.
To separate functional groups. A functional group is this sense is a set of variable declarations before a group of computational statements. Another example is grouping in preprocessing, computing, and postprocessing often used in larger modules.
Use whitespaces at other places you find appropriate to maintain readability.
Do
if (bool_flag) ... while (stay_in_loop) ... callFunction ( value1, value2 ); list a_list = [ 1, 2, 3, 4 ]; map a_map = $[ 1:`first, 2:`second ]; boolean test_flag = true; if (test_flag) { integer one = 1; boolean two_flag = false; callFunction (one, two_flag); }
Don't
if(bool_flag) ... while(stay_in_loop) ... callFunction(value1,value2); list a_list=[1,2,3,4]; map a_map=$[1:`first,2:`second]; boolean test_flag=true; if (test_flag){ integer one=1;boolean two_flag=false; callFunction(one,two_flag);}
Some explanation to the above "Don't" example:
There is no blank before the "(" in the if, while, and callFunction lines.
There is no new line to properly separate the group of variable declarations from the computational statements.
There are two variable declarations in the if () block. Without whitespace, this is not easily visible.