Doo: Programming Language Ideas and Suggestions?

2 hours ago 1

Rust LLVM Native

Doo is a statically-typed, compiled programming language with a Rust-inspired syntax designed for simplicity and performance. It features automatic memory management through reference counting, a rich type system, and compiles to standalone native executables using clang and lld.

Want to contribute? See CONTRIBUTING.md

For testing and development, see TEST.md

  • Static Type System: Compile-time type checking with type inference
  • Automatic Memory Management: Reference counting for data types
  • Rich Data Types: Integers, strings, booleans, arrays, maps, and tuples
  • Module System: Organize code with a hierarchical import system
  • Control Flow: Conditional statements, for loops, and range iteration
  • Function System: First-class functions with parameter and return type annotations
  • Native Compilation: Compiles to standalone executables using clang/lld

Download the latest doo binary from the Releases page as per your operating system.

Your downloaded file will usually be saved in your Downloads folder. Please rename file(you will get in format doo-[os-name]-x.x.x) to doo, in windows keep .exe at end

Then, follow the steps below for your operating system:

  1. Move the downloaded doo.exe to a folder of your choice (e.g., D:\doo\).

  2. Add that folder to your PATH so you can run doo from any terminal:

    Open PowerShell and run:

    [Environment]::SetEnvironmentVariable("Path", $env:Path + ";D:\doo", [EnvironmentVariableTarget]::User)

    (Restart your terminal after running this to use the new PATH.)

  3. Verify installation:


  1. Install Clang (required for linking):

    • Linux:
      sudo apt update sudo apt install clang
    • macOS:
  2. Make the binary executable, move it to your user bin, and add to your PATH (if needed):

    chmod +x ~/Downloads/doo mkdir -p ~/.local/bin mv ~/Downloads/doo ~/.local/bin/doo
    • Add to your PATH if not already:
      • For Linux bash:
        echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc source ~/.bashrc
      • For macOS bash:
        echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bash_profile source ~/.bash_profile
      • For zsh (Linux or macOS):
        echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.zshrc source ~/.zshrc
      (Choose the config file that matches your shell and OS: ~/.bashrc for Linux bash, ~/.bash_profile for macOS bash, ~/.zshrc for zsh.)
  3. Verify installation:


  • Navigate to your project root (where main.doo is located):
  • Compile and run your project:

Create your first Doo program:

// main.doo fn main() { let message: Str = "Hello, doo!"; print(message); }

Place your main.doo file in a project directory and run:

# Compile and run your program doo run

That's it! Your program compiles to a native executable and runs immediately.

Doo combines the expressiveness of high-level languages with the performance of compiled languages, focusing on readability with clean and simple syntax that's easy to learn.

Doo provides a rich set of built-in types:

Type Description Example
Int 32-bit signed integer 42, -10
Str UTF-8 string "Hello, World!"
Bool Boolean value true, false
Type Description Example
[T] Array of type T [1, 2, 3], ["a", "b", "c"]
{K: V} Map with key type K and value type V {"name": "Alice", "age": 30}
Only support for loop as of now
Type Description Example
(T1, T2) Tuple of multiple types (42, "hello", true)

Variables are declared with let and can be mutable with mut:

let immutable: Int = 42; // Immutable variable with explicit type let mut changeable: Str = "hello"; // Mutable variable with explicit type let inferred = 42; // Type inferred from value

Functions use PascalCase for public functions and camelCase for private ones:

fn AddNumbers(a: Int, b: Int) -> Int { return a + b; } fn privateHelper(x: Str) -> Str { return x; } fn main() { let result = AddNumbers(5, 10); print(result); }
let condition: Bool = true; if condition { print("Condition is true"); } else { print("Condition is false"); } // Nested conditions if condition { if result > 10 { print("Large result"); } else { print("Small result"); } }
// Range iteration (exclusive) for i in 0..5 { print(i); // Prints 0, 1, 2, 3, 4 } // Range iteration (inclusive) for i in 0..=5 { print(i); // Prints 0, 1, 2, 3, 4, 5 } // Array iteration let numbers: [Int] = [1, 2, 3, 4, 5]; for n in numbers { print(n); } // Map iteration (key-value pairs) let scores: {Str: Int} = {"Alice": 95, "Bob": 87}; for (name, score) in scores { print(name, ":", score); }

Expressions and Operators

// Arithmetic operators let sum = 5 + 10; let difference = 20 - 5; let product = 6 * 7; let quotient = 100 / 5; // Comparison operators let is_equal = 5 == 5; let not_equal = 5 != 10; let greater = 10 > 5; let less_equal = 5 <= 10; // String concatenation let greeting = "Hello, " + "World!";

Doo uses a hierarchical module system with :: separators:

myproject/ ├── main.doo # Entry point ├── models/ │ └── User.doo # User-related functions └── http/ └── Client.doo # HTTP client functions
// main.doo import models::User::CreateUser; import http::Client::FetchUser; fn main() { let user = CreateUser("Alice", 30); let data = FetchUser(1); print(user); print(data); }
// models/User.doo fn CreateUser(name: Str, age: Int) -> Str { return "User: " + name + ", Age: " + age; }
// http/Client.doo fn FetchUser(id: Int) -> Str { return "User data for ID: " + id; }
// math.doo fn Add(a: Int, b: Int) -> Int { return a + b; } fn Multiply(a: Int, b: Int) -> Int { return a * b; } // main.doo import math::Add; import math::Multiply; fn main() { let x: Int = 10; let y: Int = 5; let sum = Add(x, y); let product = Multiply(x, y); print("Sum:", sum); print("Product:", product); }
fn main() { // Array creation and iteration let numbers: [Int] = [1, 2, 3, 4, 5]; print("Numbers:", numbers); // Simple for loop iteration for item in numbers { print("Number:", item); } // Map creation and access let scores: {Str: Int} = {"Alice": 95, "Bob": 87, "Charlie": 92}; print("Scores:", scores); // String operations let name: Str = "Doo"; let greeting = "Hello, " + name + "!"; print(greeting); }

File Organization Example

school/ ├── main.doo ├── students/ │ └── Student.doo └── grades/ └── Calculator.doo
// main.doo import students::Student::CreateStudent; import grades::Calculator::CalculateGPA; fn main() { let student = CreateStudent("Alice", 20); let gpa = CalculateGPA([95, 87, 92, 88]); print(student); print("GPA:", gpa); }

This project is licensed under the MIT License

  • LLVM Project: For the powerful backend infrastructure
  • Rust Community: For inspiration and excellent tooling
  • Programming Language Design Community: For theoretical foundations

Happy coding with Doo! 🚀

Want to contribute? See CONTRIBUTING.md

For testing and development, see TEST.md

Read Entire Article