Menu

Modules

A module is just an .aus file that you want to use from another .aus file. Pull one in with the include keyword.

Including a module

include sys;
include math;

Include the module name, not the filename. The runtime adds the .aus extension itself. Include statements normally go at the top of the file, before any class definition.

For a module name with a dot in it, the dot represents a directory separator:

include playwright.playwright;   // playwright/playwright.aus
include lib.helpers.formatters;  // lib/helpers/formatters.aus

Where Aussom looks for modules

When you write include myModule;, the runtime searches in this order:

  1. Standard library packaged inside the Aussom JAR. This is where sys, math, lang, reflect, aunit, and the rest of the built-in modules come from.
  2. The directory of the script you ran. If your main script is apps/myapp.aus, then apps/ is searched.
  3. Subdirectories under that script directory. A dotted name like lib.formatters resolves to lib/formatters.aus relative to the running script.

In a server or CLI setup, the host application sometimes adds extra search paths. Aussom Server, for example, makes the app's directory available so each app's helper modules are reachable.

Delayed include

Includes do not have to be at the top of the file. You can also write an include statement inside a function, in which case the module is parsed and made available at the moment the function runs.

include sys;

class App {
    public main(args) {
        c.log("starting up...");
        this.runJob();
    }

    public runJob() {
        // pulled in only when runJob() is called
        include myJobModule;
        // ...
    }
}

This is useful when:

  • The module is heavy and you only sometimes need it.
  • The module's existence depends on configuration loaded at startup.
  • You want startup time as low as possible.

For everyday code, prefer top-of-file includes. They make dependencies obvious to a reader.

What you do not need to include

The lang module is included automatically. That is where built-in classes like c (console), json, Bool, Int, Double, and the methods on string, list, and map live. You can use c.log without an include.

Anti-patterns

  • Circular includes. Avoid module A including module B that includes module A. Refactor shared types into a third module that both can include.
  • Including everything. Only include what you actually use. Each include adds parse work at startup.

What to read next