Use spaces for indentation, never use tabs. Editors should insert spaces when the tab key is pressed.
If a call (XML element) spans more than one line, then the end of the call should always line up under beginning of the call.
<do <thing/> />
<do> <thing/> </do>
Alignment of the beginning and end is very important -- even if the start of the call is indented.
<bar xxx=<thing x=10
y=100
/>
yyy=20
/>Here is an example of HTML
<TABLE> <TR> <TD> xxx yyy </TD> </TR> </TABLE>
The exception to the vertical alignment rule is when there multiple calls are started on the same line or closed on the same line. In this case, the first closing lines up vertically with the first call start.
<TABLE><TR><TD> xxx </TD></TR></TABLE>
The calls below start on different lines, but end all on the same line which is acceptable.
<TABLE> <TR> <TD> xxx </TD></TR></TABLE>
One option is to put unkeyed and/or required arguments on the first line, then put each keyed argument on separate lines.
<class foobar xxx="value" xxx="value" />
One space when indenting the content of a tag:
<stuff arg1="more stuff"> <more stuff/> "other_stuff" </stuff>
Simple nesting of expressions
<foo <bar xxx=10 yyy=20/> />
Deep expression nesting
<foo
<bar xxx=<thing x=10
y=100
/>
yyy=20
/>
/>Use two spaces to indent arguments from the start of the call. If the opening tag spans more than one line, indent the second and following lines.
<stuff arg1=null arg2=null arg3=null arg1=null arg2=null arg3=null />
Optionally, the arguments starting the second line can line up the start of the arguments on the first line.
<stuff arg1=null arg2=null arg3=null
argument4=null arg100=true
/>If tag with content has an opening tag spaning multiple lines, the closing angle is directly below the opening angle bracket. Although unconventional, this avoids the confusing attributes with elements.
<TABLE height=100 color="red" > stuff </TABLE>
Long paths can be continued on the next line and are indented exactly 3 characters:
customer_A.orders.123.<get_stuff x=10/>. line_items.3.<get_price/>
For paths containing calls spanning multiple lines, there are several options. The ending tag can align with the start of the path.
customer_A.orders.123.<get_price 1000 id=2333 />.<length/>
Alternatively, the closing tag can be aligned with the start of the tag.
customer_A.orders.123.<get_price 1000
id=2333
/>.<length/>The call within a path can start a new line and be indented by 3 characters. The closing tag is directly underneath the start of the tag.
customer_A.orders.123.
<get_price 1000
id=2333
/>.<length/>Use a closing tag unless the tag fits on one line.
<TR><TD>stuff</><TD>other</></>
Avoid using 3 or more concise closing tags in a row. A named closing tag should be used instead of seeing three unnamed closing tags.
<TR><TD>stuff</><TD><B>other</></></TR>
There should be an empty line before and after each method and class.
<class foo> <method bar> null </method> <method to_html> "stuff" </method> </class> <class yum> null </class>
If the attributes of a class or method don't fit on a single line, it is recommended to put each parameter on a separate line. Lines with attributes should be indented two spaces.
<class person last_name="Newell" age=26 />
The equal-sign can be aligned by spaces if desired.
<class person last_name="Newell" age =26 />
The field key can optionally be right-aligned so that the equal signs are vertically aligned.
<class person
last_name="Newell"
age=26
/>An exception to the 2-space indentation for attributes is when 'do' is used. When using 'do', a single space indentation is used.
<do <this/> <that/> />
For non-conditional, one-pass flows, use:
<do "..." />
<do <foo/> <bar/> ></do>
For conditional flows using repeat, while, until use:
<do> <while x.<less 10/> /> ... </do>
Do not put spaces around '=' in attributes, unless you are aligning multiple attributes. The exception is when using 'set'.
Use one space between attributes.
Use spaces around the equal sign for 'set'.
<set x = 10/>
When multiple fields are 'set', each pair of key and value should be on their own line.
<set x = 10
y = 20
/>To improve readability, the key can be indented so that the equal-signs are vertically aligned.
<set a_obj = 10
y = 20
/>The attributes can be indented two spaces and the first one can be put on the second line.
<set a_obj = 10 y = 20 />
When the value spans multiple lines, put the key on one line and the value on the next line.
<set new_posting_instance =
<post
where="here"
when="now"
/>
/>If only one short condition-action pair, can put on one line.
<if> condition1 action1
</if> Avoid using 'do' for a condition or action that is only one expression. The following is NOT recommended because it puts a single expression in a 'do' block, which tends to hurt code readability.
<if> condition1
<do
action1
/>
</if>If 'if' has one or two condition-action pairs that fit on a single line, put two spaces between the pair.
<if> condition1 action1 else action2 </if>
If there are more than 2 condition actions, always the condition and action on separate lines. Indent the action 2 spaces from the condition.
<if> condition1
action1
cond2
action2
else
<do
something1
something2
/>
</if>Alternatively, the first condition can be put on the second line:
<if>
condition1
action....
condition2
action2
condition3
action3
</if>If adding a blank line between the pairs improves readability, then add the extra space between every pair.
<if>
long_condition.....................
long_action....
cond2
action2
</if>Use all lowercase for classes and methods.
Static HTML symbols in uppercase. When formatted, tags are always printed in lower-case.
Attribute keys are lower-case.
System attribute keys start with a underscore.
For local variables: ones that hold instances, use "a_" concatenate with class name:
a_thing=<thing/>
<set AR = <get_accounts_receivables/>
GL = <get_general_ledger_transactions/>
/>Avoid using any abbreviation that is also an HTML tag name. For example, do not use these letters (uppercase or lowercase) for variable names: 'a', 'b', 'i', 'p', or 'q'.
Parameters that have names in common with a class, use: "a_" concatenate with a class name:
<uri a_uri="http://www.clearmethods.com"/>
For multi-word variable names, use underscores between words, not camel-casing. This avoids many case-sensitive errors. and works for foreign languages that do not have the concept of uppercase and lowercase letters. For multi-word names, camel-casing is often harder to read than camel-casing.
ThisIsCamelCasing andThisIsAlsoCamelCasing this_is_using_underscores_between_word_parts