
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.
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.
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.
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.
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.
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.
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.
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.
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.
0
4
0