Constant declaration

A constant is introduced with the const keyword.

A simple constant declaration looks like this:

const name string = "Bob"

Type inference is supported. If the constant’s type is not explicitly declared then the compiler infers it from the expression at the right of the = symbol. Hence the above instruction is equivalent to the following one:

const name = "Bob"

After a constant has been declared, no other object can be assigned to it (e.g. writing name = "Alice" after the above instruction is invalid).

However, in case of types with mutable attributes the object’s data can change (e.g. if a customer’s address attribute is variable, then the value of address can change after the customer object has been assigned to a constant).

The value assigned to the constant is defined by an expression of arbitrary complexity. Example:

const function_should_be_refactored = \
    function.lines >= 20 and \
    function.max_indent >= 5

The scope of a constant is limited to the block of instructions in which it is declared.

results matching ""

    No results matching ""