Ssekirya Cosmah

Mar 05, 2026 • 2 min read

The Art of Simplicity: Variable and Number Design in the Lwanga Programming Language

The Art of Simplicity: Variable and Number Design in the Lwanga Programming Language

When designing the Lwanga programming language, we made deliberate, sometimes unconventional, choices about how variables and numbers work. Here’s a look at the reasoning behind these decisions, and why we believe they make Lwanga both powerful and approachable.

1. Immutable by Default, Explicitly Mutable

In Lwanga, variables are immutable unless declared with mut:

let x: u64 = 10; // Immutable

let mut y: u64 = 20; // Mutable

y = 30; // OK

Why?

  • Prevents accidental changes and bugs.

  • Encourages functional, predictable code.

  • Forces the programmer to think about state changes, making intent clear.

2. Explicit Types, No Type Inference

Every variable must have an explicit type:


let age: u8 = 25;

let name: ptr = "Alice";

Why?

  • Eliminates ambiguity and surprises.

  • Makes code self-documenting.

  • Enables strong compile-time checks and better error messages.

3. Unsigned Integers Only

Lwanga supports only unsigned integer types (u8, u16, u32, u64):

let a: u8 = 255;

let b: u64 = 18446744073709551615;

Why?

  • Simplicity: Fewer types to learn and fewer edge cases.

  • Systems programming: Most low-level operations use unsigned.

  • Bitwise operations: Unsigned types are clearer and safer.

  • If you need negatives, you handle it explicitly.

4. Constants vs Variables

Constants are compile-time, variables are runtime:

const MAX_SIZE: u64 = 1024;

let mut buffer: u64 = MAX_SIZE;

Why?

  • Constants improve performance (inlining, constant folding).

  • They make code more readable and maintainable.

  • Compile-time errors for accidental changes.

5. Scope and Lifetime

Variables are scoped to their block:

fn main() -> u64 {

let x: u64 = 10;

if x > 5 {

let y: u64 = 20;

}

// y is out of scope here

}

Why?

  • Prevents leaks and confusion.

  • Encourages small, focused blocks of logic.

6. Number Literals and Parsing

Lwanga supports decimal, hexadecimal (0x), and octal (0o) literals:

let dec: u64 = 42;

let hex: u64 = 0x2A;

let oct: u64 = 0o52;

Why?

  • Familiar to systems programmers.

  • Easy parsing and clear intent.

7. Overflow and Underflow

Unsigned arithmetic wraps on overflow/underflow:

let x: u8 = 255;

let y: u8 = x + 1; // y = 0

Why?

  • Matches hardware behavior.

  • Predictable for low-level code.

8. Type Safety and Explicit Casting

No implicit type conversions:


let x: u32 = 42;

let y: u64 = x as u64; // Explicit cast

Why?

  • Prevents subtle bugs.

  • Makes conversions visible and intentional.

Conclusion:
By making variables immutable by default, requiring explicit types, and focusing on unsigned numbers, Lwanga aims for clarity, safety, and performance. These choices may seem strict, but they empower you to write robust, maintainable, and efficient code—qualities we believe every language should strive for.

Join Ssekirya on Peerlist!

Join amazing folks like Ssekirya and thousands of other builders on Peerlist.

peerlist.io/

It’s available... this username is available! 😃

Claim your username before it's too late!

This username is already taken, you’re a little late.😐

0

4

0