DEV Community

Karac Thweatt
Karac Thweatt

Posted on

When Comments Become Contracts: The Idea of Architectural Programming

What if source code could describe not only what a program does, but what its implementation is permitted to do?

Most programming languages give programmers a vocabulary for describing computation. They provide types, functions, control structures, memory abstractions, and mechanisms for organizing software. Some go further: they introduce contracts, effect systems, ownership rules, static analysis, and formal verification.

There is a distinction that programming has historically struggled to bridge: the difference between describing an architectural requirement and actually enforcing it. A programmer can write that a function must be thread-safe, branchless, allocation-free, and side effect-free. They can document these requirements, establish coding conventions, and ask reviewers to verify compliance. Documentation does not constrain the compiler.

A comment saying that an allocator must never branch does not prevent the compiler from generating a conditional jump. A function described as allocation-free can still call another function that allocates memory. A library can document its behavioral expectations while providing no mechanism for the compiler to verify that its consumers respect them.

Ideka approaches this problem differently. Its design moves architectural requirements into the language itself, where they can become properties that the compiler checks and enforces.

The Central Idea - Programming as Specification
Ideka is built around a different relationship between the programmer and the compiler. Instead of treating source code exclusively as instructions describing computation, Ideka allows programmers to express constraints on how that computation is permitted to behave.

These constraints can describe properties of data, memory, object relationships, function behavior, and execution. This is why describing Ideka simply as a systems programming language misses an important part of its design. It’s also a language for specifying properties of programs. The programmer expresses intent, the compiler evaluates that intent against the program.

Effects as Architectural Vocabulary
Effect systems are not a new concept. They have been studied and implemented in various forms, generally to describe computational behavior and the side effects associated with functions.

Ideka takes a particularly interesting direction: effects are human-readable identifiers that can be composed into larger requirements.

Consider:

# effect {Pure & !Control.Branch}

This declaration communicates two requirements:

  • The function must satisfy Pure.
  • The function must not introduce Control.Branch.

These identifiers are not merely decorative labels. They participate in compiler-enforced analysis. The programmer can express requirements in terminology that is meaningful to other programmers, while the compiler uses the underlying effect relationships to determine whether those requirements are satisfied. This creates a useful convergence between documentation, specification, and verification.

A conventional comment might say:
// This function must never branch.

That comment communicates intent, but the compiler has no obligation to respect it. How could it with human language and no declarative syntax for the compiler to actually parse? In Ideka, the corresponding effect declaration can make that requirement enforceable. The declaration is simultaneously understandable to a human and meaningful to the compiler.

The stdheap allocator's bump allocation routine:

inline def bumpalloc(sizet bytes) -> u64
{
    Slab* slab = gslabhead;
    bool b = slab == NP_SLAB;
    switch (b) { case (1) { return 0; } default {}; };
    bool ret = ((slab!?) & (slab.frontier + bytes <= slab.capacity));
    u64 ptr = (u64)((byte*)slab.base + slab.frontier);
    slab.frontier = slab.frontier + bytes;
    return ptr * ret;
} # effect {Pure ///& !Control.Branch///};
Enter fullscreen mode Exit fullscreen mode

The implementation has a particular architectural intention: avoid branching in the bump allocation path. Ordinarily this intention would exist in a comment, a code review requirement, or a performance guideline. Ideka provides a way to express the requirement directly. Now the distinction becomes concrete and the compiler does not simply accept the programmer’s assertion that the implementation is branchless. It checks the relevant effects and can enforce the requirement against generated machine code.

In this particular implementation the branchless effect has been left disabled because the function does not currently satisfy it. Enabling the effect causes compilation to fail when the compiler detects the violation. Removing the /// pair and activating that effect then attempting to compile examples/helloworld.idk gives us this output:

x64 backend: unsupported in standard_memoryallocatorsstdheapbumpalloc_1dataE1ubits64_retdataE1_ubits64: the function excludes Control.Branch but the code needs a conditional jump (block entry), a loop needs a constant trip count to be written out, and data dependent control flow has no branchless form

x64 backend: 1 unsupported construct(s), not assembling.
Enter fullscreen mode Exit fullscreen mode

Effects which are tied into primitive language constructs like branching have an influence over code generation. The effect reaches the backend and changes ASM instruction selection.

The programmer is not asking the compiler to optimize toward a preference. The programmer is establishing a condition that the implementation must satisfy. The difference between a comment and a contract has become executable.

Beyond Individual Functions: Propagation
The usefulness of this model becomes substantially greater when requirements propagate through function calls. A function cannot necessarily satisfy its declared requirements merely because its own body appears compliant. It may call another function that introduces an excluded effect. Ideka’s effect analysis accounts for these relationships through the call graph.

For example, suppose a function excludes heap allocation:

effect {!Mem.Alloc.Heap};

If that function calls another function that eventually invokes an allocator tagged with Mem.Alloc.Heap, the effect can propagate back through the call chain. The original function can therefore violate its requirement even if it never directly calls an allocator. This is essential to making architectural constraints useful in real software.

Without propagation, programmers would have to manually inspect every dependency and every indirect call to establish whether their requirements remain satisfied. With propagation, the compiler can evaluate the larger behavioral structure. An architectural requirement can therefore extend beyond the function in which it was declared.

Composing Requirements

Ideka’s effects are not restricted to a fixed collection of predefined annotations. Programmers can compose effects into higher-level requirements.

For example:

effect Branchless {!Control.Branch};

foo(int a, int b) -> int
{
    -> (a + b) & true;
} # effect {Branchless};
Enter fullscreen mode Exit fullscreen mode

Here, Branchless is defined in terms of the absence of Control.Branch. The compiler understands the intrinsic behavior associated with its own language constructs. The programmer can build meaningful higher-level requirements using those underlying effects.

The name Branchless communicates the intended architecture to humans. Its composition establishes what that architecture requires. Control.Branch is produced by all branch producing constructs such as if or logical &.

[effect error] exclusion
  C:\Users\kvthw\IDEKA\examples\branchless.idk:9:16  Function foo excludes effect Control.Branch but contains a logical & which introduces it
  function foo declared effect !Control.Branch
    -> (a + b) & true;
---------------^

[Effects] 1 violation(s)  exclusion: 1
Enter fullscreen mode Exit fullscreen mode

The effect system does not need a dedicated compiler keyword for every possible architectural property. This opens up a vocabulary that can grow with the libraries and applications built using the language.

Effect hierarchies provide another dimension: related labels can be organized into broader categories allowing requirements to target an entire class of behavior rather than enumerating every individual effect. The result is a system where the programmer can define increasingly meaningful descriptions of program behavior using smaller, more fundamental properties.

The compiler becomes part of the architectural specification.

One of the more consequential aspects of Ideka is that not all effects operate at the same level. Some effects are associated with intrinsic language constructs. The compiler knows what those constructs do and can use that knowledge during analysis and machine-code generation where applicable.

Other effects are declared by programmers or libraries. The compiler can propagate, compose, constrain, and expose these labels without necessarily understanding their domain-specific meaning. This distinction allows the system to remain extensible without requiring the compiler to understand every possible library or application domain.

A library author can introduce meaningful effects such as:

  • Crypto.Random
  • Parser.SQL
  • Unsafe.DSL.Specific

The standard library establishes a semantic vocabulary while library authors remain responsible for accurately describing their own functions. This makes effect annotations useful beyond the implementation of a single application. They can communicate behavioral properties across library boundaries and the compiler can then reason about those properties as part of the larger program.

A Different Conception of Documentation
Perhaps the most immediately understandable implication is what this means for documentation. Programming has traditionally maintained a separation between source code and its architectural documentation.

The code implements behavior, comments explain intent, external documentation describes expectations, tests provide evidence that selected behaviors hold. These mechanisms are useful but they do not all carry the same authority. Ideka creates an opportunity to express some of that documentation directly in the language’s enforceable specification.

Consider the difference with conventional documentation:

“This function must not allocate memory.” somewhere // here (C/C++) or # there (Python).

Ideka specification:

foo()->void
{
} # effect {This.Is.An.Effect}; // this is a comment
Enter fullscreen mode Exit fullscreen mode

The second statement is not simply a comment written in a more convenient syntax. It participates in the compiler’s analysis. It can be checked against the function’s implementation and the behavior of its dependencies.

The same declaration communicates the architectural requirement to the next programmer while giving the compiler a condition to enforce. This does not eliminate ordinary comments. Comments still explain reasoning, implementation choices, and context. Properties that can be formally represented no longer need to exist exclusively as prose.

Architectural Programming
Traditional programming primarily concerns the construction of computations. Architectural programming also concerns the explicit specification of the conditions under which those computations are allowed to exist.

A programmer might want to establish that:

  • A subsystem cannot perform network operations.
  • A function cannot allocate memory.
  • An execution path cannot introduce conditional branches.
  • A component cannot access global state.
  • A function must preserve particular behavioral restrictions across its dependencies.

These are architectural decisions. A properly tagged library not only carries the full color of the stdlib or any other library also well-tagged. In many languages, enforcing them requires a combination of programming conventions, external analysis tools, custom build systems, code reviews, and discipline. Ideka’s approach is to bring such requirements into the language’s own semantic model.

The programmer describes the requirement, the compiler checks it. This gives the compiler an additional role. It’s no longer only translating an accepted program into machine instructions, it participates in determining whether the program’s implementation satisfies the architecture specified by its author and the code of libraries that program relies on.

In a way, Ideka can be thought of as proof language for code.

That description should not be confused with claiming that every program is accompanied by a complete mathematical proof of correctness. Rather, the programmer expresses claims about the program and the compiler checks those claims against properties it’s equipped to establish. The scope of each guarantee depends on the underlying analysis and its soundness. If those claims line up with reality you get a strong guarantee of your model. If you do:

foo() -> int
{
    -> 25;
} # effect {Mem.Alloc.Heap};
Enter fullscreen mode Exit fullscreen mode

Anything calling foo() that has !Heap will error telling you that !Heap was violated. If you tagged it with # effect {Pure} you’re telling the truth about the function to the compiler. The more the stdlib is tagged, the more colorful any Ideka program will be.

A compiler checking that a function introduces no prohibited effect is not automatically proving that the function is free of every possible bug. A branchless constraint does not prove that the algorithm produces the correct answer. The programmer can state it, and the compiler can reject an implementation that violates it. This is the foundation of a more expressive relationship between code and verification.

What comes next?

Ideka is also exploring compile-time introspection, allowing programmers to examine properties of functions and their effects as part of compile-time computation. It’s exploring ways for user-defined operators and compiler validation mechanisms to become extensible without requiring programmers to modify the language’s grammar or introduce new keywords.

These directions share an underlying philosophy: the programmer should be able to express more of the architecture of a program directly, and the compiler should have mechanisms to reason about those expressions. This is not simply about adding more annotations. It’s about expanding the set of properties that can be represented and enforced in source code.

The most interesting thing about Ideka isn't any individual feature.

It’s the relationship between them. Types describe representations. Interfaces describe permitted interactions. Effects describe computational behavior. Borrow checking reasons about memory access. Compile-time facilities expose properties of the program itself.

Together, these mechanisms move toward a model in which source code communicates not only what a program should do, but the constraints that its implementation must satisfy.

A comment can say that a function must be branchless. A specification can require it.

A compiler can enforce it.

That is the difference between documenting an architectural decision and making it part of the program. Ideka is exploring what happens when architectural intent becomes executable specification.

Top comments (0)