Design Principles

Understanding Constela's design philosophy and compile-time safety

Overview

Constela is designed with a core philosophy: catch errors at compile time, not runtime. This principle guides every aspect of the language design.

Limited Operations, Maximum Safety

Constela intentionally provides a constrained set of operations and expression types. This isn't a limitation—it's a feature.

Why Constraints Matter

ApproachBenefit
Limited expression typesExhaustive type checking possible
Predefined operationsInvalid operations caught at compile time
Declarative actionsNo runtime surprises
Structured JSONAI-friendly, less prone to errors

Exhaustive Handling Guarantees

Constela uses exhaustive switch checks inside the compiler and runtime.

This means that when a new expression kind or operation is introduced, all relevant evaluation and execution logic must be updated explicitly. If any case is missed, the build fails.

What This Means in Practice

When the Constela team adds a new expression type (like cond or get) or a new update operation (like toggle or merge), the compiler itself will not build until every handler is updated.

This design ensures:

  1. No unhandled DSL constructs at runtime - Every possible expression and operation has explicit handling
  2. Failures happen during development - Not in user applications
  3. Safer long-term evolution - New features cannot be partially implemented

Compile-Time Error Detection

Invalid Operation Errors

Using an operation on the wrong state type produces a compile-time error:

json
// Error: 'count' is number, 'toggle' requires boolean
{
  "do": "update",
  "target": "count",
  "operation": "toggle"
}

Type Mismatch Errors

Operations validate their target state types:

json
// Error: merge requires object target, 'items' is a list
{
  "do": "update",
  "target": "items",
  "operation": "merge",
  "value": { "expr": "lit", "value": { "key": "value" } }
}

Missing Required Fields

Operations with required fields are validated:

json
// Error: replaceAt requires 'index' field
{
  "do": "update",
  "target": "todos",
  "operation": "replaceAt",
  "value": { "expr": "lit", "value": { "title": "New" } }
}

State Type Requirements

Each operation has specific state type requirements:

OperationRequired State Type
incrementnumber
decrementnumber
toggleboolean
pushlist
poplist
removelist
replaceAtlist
insertAtlist
splicelist
mergeobject

Expression Type Requirements

Expressions also have type constraints:

ExpressionReturnsConstraints
litanyValue must be JSON-serializable
stateanyState field must exist
varanyVariable must be in scope
binvariesOperands must be compatible with operator
notbooleanOperand must be boolean
condanyif clause must be boolean
getanyBase must be object or array
paramanyOnly valid inside action steps

The AI Advantage

Constela's constrained design makes it ideal for AI-generated UIs:

  1. Structured JSON reduces hallucination - AI models generate valid syntax more reliably
  2. Limited vocabulary improves accuracy - Fewer options means fewer mistakes
  3. Type errors surface immediately - No debugging runtime issues
  4. Predictable patterns - AI can learn and replicate correct usage

Next Steps