Expressions

The sections below include the coding conventions with respect to expressions.

Function invocation

  • Do not keep spaces between the function name and opening parentheses (.

  • If it is not possible to keep the function invocation in a single line due to it exceeding the maximum line length, split it into a new line based on the best practices given in Line breaks.

Example,

Record literal

  • If empty, keep it as an empty block.

Example,

  • In a record literal, arrange the fields in a single line. Then, add a space after the comma and leave no spaces between the braces and fields.

Example,

  • Do not keep any spaces between the key and the colon. Also, keep only one space between the colon and the value.

Example,

  • You can define the fields in new lines. If you do so, make sure each field is in a separate line and is block-indented.

Do's

Don'ts

Map literal

  • For map literals, follow the same formatting guidelines as Record literals.

Example,

Tuple

  • Always, place a tuple in a single line.

Example,

  • If a tuple exceeds the maximum line length limit, move the whole tuple to a new line and indent with four spaces from the starting position of the statement or definition.

Example,

Array literal

  • Place simple arrays in a single line.
  • Do not keep any spaces between the opening bracket, value, and the closing bracket.

Example,

  • If an array cannot be placed on a single line due to it exceeding the maximum line length, split each value in the array to its own block-indented line.

Example,

Type casting

  • Do not keep spaces between the type and the angle brackets (i.e., <string>).
  • Do not keep spaces between the closing angle bracket and value reference, which will be casted.

Example,

  • Avoid line breaks in type casting.

Do's

Don'ts

Table literal

  • Follow the formatting guidelines of Record literals when formatting a table block.

Example,

"Star"

"Watch"