Docs / Paradigms
15. Programming Paradigms
Dryad is a multi-paradigm language that supports object-oriented, functional, and procedural programming styles — often mixing them in the same file. There is no enforced paradigm; developers choose the approach that best fits the problem.
| Paradigm | Key Features | When to Use |
|---|---|---|
| Object-Oriented | Classes, inheritance, encapsulation, polymorphism, access modifiers | Domain modeling, large systems with stateful entities. |
| Functional | First-class functions, closures, higher-order functions, arrow syntax, immutability via const | Data pipelines, transformations, callback-heavy code. |
| Procedural | Top-level functions, global/local scope, structured loops, no class overhead | Scripts, automation, small-to-medium programs. |
1 class Animal { 2 public name: string; 3 constructor(name: string) { 4 this.name = name; 5 } 6 speak(): string { 7 return "..." ; 8 } 9 } 10 11 class Dog extends Animal { 12 constructor(name: string) { 13 super(name); 14 } 15 speak(): string { 16 return this.name ++ " says woof!"; 17 } 18 } 19 20 let pet = new Dog("Rex"); 21 console.log(pet.speak()); // "Rex says woof!"
Classes support single inheritance (extends), access modifiers (public, private, protected), and method overriding. super provides access to the parent class.
1 // First-class function assigned to a variable 2 let double: fn(number) -> number = (x) => x * 2; 3 4 // Higher-order function: takes a function as argument 5 function applyTwice(f: fn(number) -> number, x: number): number { 6 return f(f(x)); 7 } 8 9 console.log(applyTwice(double, 3)); // 12 10 11 // Closure: captures lexical scope 12 function makeCounter() { 13 let count = 0; 14 return function() { 15 return ++count; 16 }; 17 } 18 19 let counter = makeCounter(); 20 console.log(counter()); // 1 21 console.log(counter()); // 2
Arrow functions provide concise syntax. Closures capture variables from the definition scope and keep them alive as long as the closure exists.
1 // Top-level functions — no class or object required 2 function greet(name: string) { 3 return "Hello, " ++ name ++ "!"; 4 } 5 6 let users = ["Alice", "Bob", "Charlie"]; 7 for (let i = 0; i < 3; i++) { 8 console.log(greet(users[i])); 9 }
Procedural code with top-level functions, global and local variables, and structured control flow. Ideal for scripts and automation tasks.
Found an error in the spec? Open a PR.
Official Version: 1.0 · May 2026