E1853: function is above the preferred size

View source

A function has more than 50 code lines, which is the preferred size of a function.

A function has more than 50 code lines, which is the preferred size of a function. Strict mode (--strict, ADR-0041) counts the code lines of each function, from its verb line to its closing brace. Blank lines, # comments and """ documentation blocks do not count. Strict mode reports the first limit a function crosses: E1853 above 50, E1854 from 60 and E1855 above 80. Without --strict the size of a function is not checked. The message names the function and the count, as in function `long` has 51 code lines; preferred limit is 50.

Example

The comment # catalog: repeat N stands for N copies of the lines up to # catalog: end, with {n} replaced by the copy's number. The example is 49 bindings value_01 to value_49, so that long has 51 code lines.

actus
verb long() {
# catalog: repeat 49
    erg value_{n}: Int = 0;
# catalog: end
}

verb main() {
}

Fix

Split the function into functions that each do one thing, and call them in order.

When a long function is one operation that splitting would only scatter, such as a state machine or a register setup sequence, mark it with meta limitless("verb") (ADR-0048). The exception is then visible in the source and in review.

actus
"""First part of the split function: it declares placeholder bindings and has no other effect."""
verb first_half() {
# catalog: repeat 25
    erg value_{n}: Int = 0;
# catalog: end
}

"""Second part of the split function: it declares more placeholder bindings and has no other effect."""
verb second_half() {
# catalog: repeat 24
    erg other_{n}: Int = 0;
# catalog: end
}

"""Entry point of the example; it does nothing and returns no value."""
verb main() {
    first_half();
    second_half();
}

Run actus explain E1853 in your terminal to read this entry offline. Browse Strict & toolchain or all error codes.