Why does EK9 require a dedicated constants file once a module has many constants?
← Code Quality · Ref: Q1341
EK9 raises E11067 when a multi-file module has 10 or more constants spread across 2 or more files. This volume of constants across multiple files signals that the module's vocabulary has grown large enough to deserve a single dedicated constants file.
WHY CONSOLIDATION MATTERS
A large, scattered constant vocabulary is a maintenance burden: no developer can see the full set of fixed values without opening multiple files, duplicates and near-duplicates hide easily, and the intent of 'this is where constants live' is lost.
THE FIX
Create one dedicated constants file for the module and move every 'defines constant' block into it. Group related constants together with doc comments. If the count is very high, ask whether the module is doing too much.
This example shows the consolidated end-state: all 12 module constants live in a single file, organised by concern, so the multi-file/high-volume condition never arises.
See Q863 for the related 3+ file consolidation check (E11066). See Q695 for named constants. See Q311 for quality checks.
Example
defines module qa.quality.constants.volume defines constant <?- Retry and timeout configuration. Used by network and service components. -?> MAX_RETRIES <- 3 RETRY_DELAY_MS <- 500 CONNECTION_TIMEOUT_MS <- 5000 READ_TIMEOUT_MS <- 8000 <?- Endpoint configuration. Centralised so a host change touches one place only. -?> BASE_URL <- "https://api.example.com" HEALTH_PATH <- "/health" METRICS_PATH <- "/metrics" <?- Reporting and formatting constants. Used by the output and report functions. -?> SEPARATOR_LINE <- "----------------------------------------" INDENT_SPACES <- " " PAGE_SIZE <- 50 MAX_PAGES <- 20 REPORT_TITLE <- "Service Status Report" defines function <?- Build a single report line using the shared formatting constants. -?> formatReportLine() as pure -> content as String <- rtn as String: INDENT_SPACES + content <?- Compute how many items a full report could contain using the consolidated paging constants. -?> maxReportItems() as pure <- rtn as Integer: PAGE_SIZE * MAX_PAGES defines program ConstantsVolumeDemo() stdout <- Stdout() stdout.println(SEPARATOR_LINE) stdout.println(formatReportLine(REPORT_TITLE)) stdout.println(SEPARATOR_LINE) stdout.println(formatReportLine(`Base URL: ${BASE_URL}${HEALTH_PATH}`)) stdout.println(formatReportLine(`Max retries: ${MAX_RETRIES}`)) stdout.println(formatReportLine(`Connect timeout: ${CONNECTION_TIMEOUT_MS}ms`)) stdout.println(formatReportLine(`Read timeout: ${READ_TIMEOUT_MS}ms`)) stdout.println(formatReportLine(`Metrics at: ${METRICS_PATH}`)) stdout.println(formatReportLine(`Retry delay: ${RETRY_DELAY_MS}ms`)) stdout.println(formatReportLine(`Max report items: ${maxReportItems()}`)) stdout.println(SEPARATOR_LINE)
Other ways to ask this
- What triggers E11067 in EK9?
- Why must 10+ module constants live in a single file?
- How do I consolidate a large constant vocabulary spread across files?
Coming from another language?
Java/Kotlin/Go: there is no compiler enforcement of how constants are organised across files; teams rely on convention (a Constants class, a constants.py, a const block) and on reviewers spotting sprawl. EK9 enforces it at compile time: once a module crosses 2+ files AND 10+ constants, E11067 fails the build until the constants are consolidated into one dedicated file.
Keywords: consolidate, E11067, quality, module, scattered, volume, file, constant, organization, vocabulary