Introduction to Desi¶
Welcome to the Desi tutorial series! This guide will teach you Desi from the ground up.
What is Desi?¶
Desi is a programming language designed for developers who:
- Love Python's syntax and readability
- Need native performance
- Want memory safety without garbage collection
The name "Desi" (દેશી) means "local" or "native" in Gujarati - representing code that compiles to native machine code.
Design Philosophy¶
Python-Inspired Syntax¶
Desi uses indentation-based syntax like Python:
Strong Static Typing¶
Types are checked at compile time, catching errors early:
Type inference makes this less verbose:
Memory Safety¶
Desi uses arenas and RAII for memory management - no garbage collector pauses, no manual memory management:
using arena = Arena():
let data = arena.alloc(1024) # Allocated in arena
# Memory automatically freed when arena goes out of scope
Desi vs Python¶
| Feature | Desi | Python |
|---|---|---|
| Syntax | Indentation-based | Indentation-based |
| Typing | Static, compile-time | Dynamic, runtime |
| Execution | Compiled (LLVM) | Interpreted |
| Performance | Native speed | Slower |
| Memory | Arenas, RAII | Garbage collected |
A Complete Example¶
Here's a taste of what Desi code looks like:
# A simple class with generics
class Stack<T>:
pub mut items: list<T>
pub def __new__(self):
self.items = []
pub def push(self, item: T):
self.items.append(item)
pub def pop(self) -> T:
return self.items.pop()
pub def is_empty(self) -> bool:
return len(self.items) == 0
def main() -> int:
# __new__ takes no argument mentioning T, so state it with turbofish
let stack = Stack::<int>()
stack.push(1)
stack.push(2)
stack.push(3)
while not stack.is_empty():
print(str(stack.pop()))
return 0
Contents of This Tutorial¶
This tutorial is organized into chapters:
- Variables & Types - Declaring variables, understanding types
- Functions - Defining and calling functions
- Collections - Lists, dicts, and sets
- Classes - Object-oriented programming
- Generics - Type parameters
Each chapter builds on the previous, so we recommend following them in order.
Ready?¶
Let's start with Variables & Types!