Why does EK9 reject a method or function that has too many statements?

← Code Quality · Ref: Q1335

EK9 measures a raw SIZE metric - the number of statements in each function, method, operator and service operation - separately from cyclomatic complexity (E11010). Each variable declaration, assignment, control-flow entry, throw and call counts as one statement. When the count exceeds the threshold the compiler raises E11012. The thresholds are: operators 50, methods 100, functions 150, service operations 100.

A long function is doing too much, so the fix is to identify logical groups of statements and extract each into a well-named helper function with a single responsibility. The original function then becomes a short sequence of calls, and every unit drops well under the threshold.

Note E11012 is a pure size check: it fires even when each statement is trivial and the cyclomatic complexity is low. See Q696 for the complexity-limit catalogue. See Q1020 for refactoring techniques. See Q311 for quality checks.

Example

defines module qa.quality.statement.count

  defines function

    //FIX: each logical sub-task lives in its own small focused function,
    //so no single function approaches the 150-statement threshold.

    sumValues() as pure
      -> values as List of Integer
      <- rtn as Integer: 0
      for value in values
        rtn: rtn + value

    averageValue() as pure
      ->
        values as List of Integer
        total as Integer
      <- rtn as Integer: 0
      count <- length values
      if count > 0
        rtn: total / count

    formatReport() as pure
      ->
        total as Integer
        average as Integer
      <- rtn as String: `total=${total} average=${average}`

    //The orchestrating function is now a short sequence of calls,
    //well under the statement-count limit.
    buildReport() as pure
      -> values as List of Integer
      <- rtn as String?
      total <- sumValues(values)
      average <- averageValue(values, total)
      rtn: formatReport(total, average)

  defines program

    StatementCountDemo()
      stdout <- Stdout()
      values <- [10, 20, 30, 40]
      stdout.println(buildReport(values))

Common mistakes

E11012 — Putting 160+ statements directly in one function exceeds the function threshold of 150 (methods 100, operators 50, service operations 100), so the compiler raises E11012 - a size check distinct from cyclomatic complexity. Identify logical groups (sum, average, format) and extract each into its own named helper, then call them in sequence; every unit then falls under the threshold. See ek9 -h E11012 for details.

Incorrect:

    buildReport() as pure
      -> values as List of Integer
      <- rtn as String?
      stepTotal <- sumValues(values)
      step002 <- stepTotal + stepTotal
      step003 <- step002 + stepTotal
      step004 <- step003 + stepTotal
      step005 <- step004 + stepTotal
      step006 <- step005 + stepTotal
      step007 <- step006 + stepTotal
      step008 <- step007 + stepTotal
      step009 <- step008 + stepTotal
      step010 <- step009 + stepTotal
      step011 <- step010 + stepTotal
      step012 <- step011 + stepTotal
      step013 <- step012 + stepTotal
      step014 <- step013 + stepTotal
      step015 <- step014 + stepTotal
      step016 <- step015 + stepTotal
      step017 <- step016 + stepTotal
      step018 <- step017 + stepTotal
      step019 <- step018 + stepTotal
      step020 <- step019 + stepTotal
      step021 <- step020 + stepTotal
      step022 <- step021 + stepTotal
      step023 <- step022 + stepTotal
      step024 <- step023 + stepTotal
      step025 <- step024 + stepTotal
      step026 <- step025 + stepTotal
      step027 <- step026 + stepTotal
      step028 <- step027 + stepTotal
      step029 <- step028 + stepTotal
      step030 <- step029 + stepTotal
      step031 <- step030 + stepTotal
      step032 <- step031 + stepTotal
      step033 <- step032 + stepTotal
      step034 <- step033 + stepTotal
      step035 <- step034 + stepTotal
      step036 <- step035 + stepTotal
      step037 <- step036 + stepTotal
      step038 <- step037 + stepTotal
      step039 <- step038 + stepTotal
      step040 <- step039 + stepTotal
      step041 <- step040 + stepTotal
      step042 <- step041 + stepTotal
      step043 <- step042 + stepTotal
      step044 <- step043 + stepTotal
      step045 <- step044 + stepTotal
      step046 <- step045 + stepTotal
      step047 <- step046 + stepTotal
      step048 <- step047 + stepTotal
      step049 <- step048 + stepTotal
      step050 <- step049 + stepTotal
      step051 <- step050 + stepTotal
      step052 <- step051 + stepTotal
      step053 <- step052 + stepTotal
      step054 <- step053 + stepTotal
      step055 <- step054 + stepTotal
      step056 <- step055 + stepTotal
      step057 <- step056 + stepTotal
      step058 <- step057 + stepTotal
      step059 <- step058 + stepTotal
      step060 <- step059 + stepTotal
      step061 <- step060 + stepTotal
      step062 <- step061 + stepTotal
      step063 <- step062 + stepTotal
      step064 <- step063 + stepTotal
      step065 <- step064 + stepTotal
      step066 <- step065 + stepTotal
      step067 <- step066 + stepTotal
      step068 <- step067 + stepTotal
      step069 <- step068 + stepTotal
      step070 <- step069 + stepTotal
      step071 <- step070 + stepTotal
      step072 <- step071 + stepTotal
      step073 <- step072 + stepTotal
      step074 <- step073 + stepTotal
      step075 <- step074 + stepTotal
      step076 <- step075 + stepTotal
      step077 <- step076 + stepTotal
      step078 <- step077 + stepTotal
      step079 <- step078 + stepTotal
      step080 <- step079 + stepTotal
      step081 <- step080 + stepTotal
      step082 <- step081 + stepTotal
      step083 <- step082 + stepTotal
      step084 <- step083 + stepTotal
      step085 <- step084 + stepTotal
      step086 <- step085 + stepTotal
      step087 <- step086 + stepTotal
      step088 <- step087 + stepTotal
      step089 <- step088 + stepTotal
      step090 <- step089 + stepTotal
      step091 <- step090 + stepTotal
      step092 <- step091 + stepTotal
      step093 <- step092 + stepTotal
      step094 <- step093 + stepTotal
      step095 <- step094 + stepTotal
      step096 <- step095 + stepTotal
      step097 <- step096 + stepTotal
      step098 <- step097 + stepTotal
      step099 <- step098 + stepTotal
      step100 <- step099 + stepTotal
      step101 <- step100 + stepTotal
      step102 <- step101 + stepTotal
      step103 <- step102 + stepTotal
      step104 <- step103 + stepTotal
      step105 <- step104 + stepTotal
      step106 <- step105 + stepTotal
      step107 <- step106 + stepTotal
      step108 <- step107 + stepTotal
      step109 <- step108 + stepTotal
      step110 <- step109 + stepTotal
      step111 <- step110 + stepTotal
      step112 <- step111 + stepTotal
      step113 <- step112 + stepTotal
      step114 <- step113 + stepTotal
      step115 <- step114 + stepTotal
      step116 <- step115 + stepTotal
      step117 <- step116 + stepTotal
      step118 <- step117 + stepTotal
      step119 <- step118 + stepTotal
      step120 <- step119 + stepTotal
      step121 <- step120 + stepTotal
      step122 <- step121 + stepTotal
      step123 <- step122 + stepTotal
      step124 <- step123 + stepTotal
      step125 <- step124 + stepTotal
      step126 <- step125 + stepTotal
      step127 <- step126 + stepTotal
      step128 <- step127 + stepTotal
      step129 <- step128 + stepTotal
      step130 <- step129 + stepTotal
      step131 <- step130 + stepTotal
      step132 <- step131 + stepTotal
      step133 <- step132 + stepTotal
      step134 <- step133 + stepTotal
      step135 <- step134 + stepTotal
      step136 <- step135 + stepTotal
      step137 <- step136 + stepTotal
      step138 <- step137 + stepTotal
      step139 <- step138 + stepTotal
      step140 <- step139 + stepTotal
      step141 <- step140 + stepTotal
      step142 <- step141 + stepTotal
      step143 <- step142 + stepTotal
      step144 <- step143 + stepTotal
      step145 <- step144 + stepTotal
      step146 <- step145 + stepTotal
      step147 <- step146 + stepTotal
      step148 <- step147 + stepTotal
      step149 <- step148 + stepTotal
      step150 <- step149 + stepTotal
      step151 <- step150 + stepTotal
      rtn: formatReport(step151, averageValue(values, stepTotal))

Correct:

    buildReport() as pure
      -> values as List of Integer
      <- rtn as String?
      total <- sumValues(values)
      average <- averageValue(values, total)
      rtn: formatReport(total, average)
Other ways to ask this
  • What triggers E11012 EXCESSIVE_STATEMENT_COUNT in EK9?
  • How do I fix a function the compiler says has too many statements?
  • What is the statement-count limit for functions and methods in EK9?

Coming from another language?

Java: method length is unbounded; only optional tools (Checkstyle MethodLength, PMD ExcessiveMethodLength, SonarQube) flag long methods, and they emit warnings teams routinely suppress. Kotlin/Swift/Go: no built-in statement-count limit; detekt/SwiftLint can warn if configured. EK9: statement count is a hard compile error (E11012) per function/method/operator/service-operation, so an oversized unit simply does not compile.

Keywords: size, decompose, count, extract, function, statement, method, E11012, quality