Statements

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

If statement

  • Avoid enclosing the condition with parentheses.

    Do's

    Copy
    if valid {
        ...
    } else if active {
        ...
    }

    Don'ts

    Copy
    if (valid) {
        ...
    } else if (active) {
        ...
    }
  • Keep the else and else if keywords in the same line with the matching if or else if block's closing brace separated only by a single space.

Empty block

  • Do not have any empty if, else if, or else blocks.

  • If empty, add an empty line between the opening and closing braces.

    Example,

    Copy
    if inProperSallaryRange {
        
    } else if inSallaryRange {
        
    } else {
        
    }

Match statement

The best practices related to the match statement are as follows.

Match patterns clause

  • Block indent each pattern clause in its own line.

  • Keep a single space before and after the => sign.

    Example,

    Copy
    function foo(string|int|boolean a) returns string {
        match a {
            12 => {
                return "Value is '12'";
            }
        }
    
        return "Value is 'Default'";
    }
  • If a pattern clause has more than one statement, block indent each statement in its own line.

    Example,

    Copy
    match x {
        var [s, i] if s is string => {
            io:println("string");
        }
        var [s, i] if s is int => {
            io:println("int");
        }
    }
  • If the pattern body is empty, then keep it as an empty block.

    Example,

    Copy
    match x {
        var [s, i] if s is string => {}
        var [s, i] if s is int => {}
    }
Previous