What is the module coupling limit in EK9?

← Code Quality · Ref: Q766

EK9 limits the number of external modules a single module can depend on. When a module references more than 10 external modules, E11016 triggers.

WHAT IT MEASURES

Module coupling counts the distinct external module namespaces referenced via 'references' declarations. This is different from type-level coupling (Ce) — it measures architectural-level dependencies.

THRESHOLD

- Maximum: 10 external module references per module

WHY LIMIT MODULE COUPLING

- High module coupling creates brittle architectures
- Changes in one module ripple through many dependents
- Makes the module hard to understand in isolation
- Indicates the module is doing too many things

HOW TO REDUCE MODULE COUPLING

1. Split the module into focused sub-modules
2. Create a facade module that re-exports needed types
3. Use dependency injection to decouple
4. Apply the Interface Segregation Principle

THIS EXAMPLE

The module below demonstrates a self-contained module without external references. In a real project, you would add 'references' to declare dependencies on other modules.

See Q310 for code quality overview. See Q314 for cohesion and coupling details. See Q762 for type-level coupling.

Example

defines module qa.codequality.modulecoupling

  defines function

    <?-
      Helper function demonstrating self-contained module design.
      In practice, high module coupling comes from too many 'references'
      declarations pointing to external modules.
    -?>
    calculateTotal()
      -> numbers as List of Integer
      <- total as Integer: 0
      for num in numbers
        total += num

  defines program

    ModuleCouplingDemo()
      stdout <- Stdout()
      numbers <- [10, 20, 30, 40, 50]
      stdout.println(`Total: ${calculateTotal(numbers)}`)

Common mistakes

E50001 — The function calcTotal is not defined in this module. The correct name is calculateTotal. See ek9 -h E50001 for details.

Incorrect:

      stdout.println(`Total: ${calcTotal(numbers)}`)

Correct:

      stdout.println(`Total: ${calculateTotal(numbers)}`)
Other ways to ask this
  • What triggers E11016 excessive module coupling?
  • How many external modules can I reference?
  • What is the module-level coupling threshold?
  • Why does EK9 limit cross-module dependencies?

Coming from another language?

Java: Maven/Gradle track module dependencies but don't enforce count limits. C#: NuGet package count is unchecked. Python: import count is unchecked. Go: module dependency count is unchecked. Rust: crate dependency count is unchecked. EK9: > 10 external module references is a compiler error.

Keywords: architecture, references, external, E11016, module, threshold, quality, coupling, dependency