Welcome to B3D
B3D is a modern, high-performance programming language designed for developers who want the power of compiled languages with the flexibility of interpreted languages.
Key Highlights
- High Performance: Built with Rust, offering near-native speed
- Python Integration: Seamlessly use Python libraries directly in B3D
- Modern Syntax: Inspired by Python, Go, and Rust
- Async/Await: Native support for concurrent programming
- Pattern Matching: Powerful language feature for elegant code
- Package Manager: Built-in dependency management
- Type Safe: Optional static typing for better error catching
- Cross-Platform: Works on Linux, macOS, Windows, and more
Installation Guide
Linux
For Debian/Ubuntu:
sudo apt-get install b3d
For Arch Linux:
sudo pacman -S b3d
# or from AUR
yay -S b3d
macOS
brew install b3d
Windows
Download the installer from the main website and run it.
From Source
git clone https://github.com/berkeoruc/b3d.git
cd b3d
cargo build --release
./target/release/b3d --version
b3d --version to verify.
Your First Program
Create a file named hello.b3d:
print("Hello, B3D!");
print("Welcome to the world of B3D programming!");
Run it:
b3d run hello.b3d
b3d shell
B3D Syntax Basics
B3D uses a clean, readable syntax inspired by modern programming languages.
Comments
// Single-line comment
/* Multi-line
comment */
Statements
B3D statements end with semicolons (optional in some contexts):
let x = 10;
print("x is " + x);
func greet(name) {
print("Hello, " + name);
}
Variables and Assignment
// Immutable binding
let x = 10;
// Mutable binding
mut y = 20;
y = 30; // OK
// Type annotations
let name: string = "B3D";
let version: number = 2.0;
Data Types
number- Integer and floating-point numbersstring- Text databool- Boolean values (true/false)array- Ordered collectionsdict- Key-value pairsnull- Null/nil valuefunction- First-class functions
let numbers = [1, 2, 3, 4, 5];
let person = {
"name": "Alice",
"age": 30
};
let isActive = true;
Operators
Arithmetic
let a = 10 + 5; // Addition: 15
let b = 10 - 3; // Subtraction: 7
let c = 4 * 5; // Multiplication: 20
let d = 20 / 4; // Division: 5
let e = 10 % 3; // Modulo: 1
let f = 2 ** 3; // Exponentiation: 8
Comparison
5 == 5 // true
5 != 3 // true
5 > 3 // true
5 >= 5 // true
3 < 5 // true
3 <= 3 // true
Logical
true and false // false
true or false // true
not true // false
Control Flow
If/Else
if x > 10 {
print("x is greater than 10");
} else if x == 10 {
print("x is equal to 10");
} else {
print("x is less than 10");
}
Loops
// For loop
for i in 0..10 {
print(i);
}
// While loop
mut x = 0;
while x < 5 {
print(x);
x = x + 1;
}
// Loop control
for i in 1..100 {
if i == 50 {
break;
}
if i % 2 == 0 {
continue;
}
print(i);
}
Functions
// Function definition
func add(a: number, b: number) -> number {
return a + b;
}
// Function call
let result = add(3, 5); // result = 8
// Functions without return type
func greet(name: string) {
print("Hello, " + name);
}
// Default parameters
func multiply(x: number, y: number = 2) -> number {
return x * y;
}
// Variadic functions
func sum(...numbers: array) -> number {
let total = 0;
for num in numbers {
total = total + num;
}
return total;
}
Async/Await
B3D provides built-in support for asynchronous programming:
// Async function definition
async func fetchData(url: string) {
let response = await fetch(url);
let data = await response.json();
return data;
}
// Calling async function
let data = await fetchData("https://api.example.com/data");
// Parallel execution
async func main() {
let result1 = await task1();
let result2 = await task2();
print(result1 + result2);
}
Pattern Matching
B3D supports powerful pattern matching for elegant data handling:
// Match expression
match value {
1 => print("One"),
2 => print("Two"),
3..5 => print("Three to Five"),
n if n > 10 => print("Greater than 10"),
_ => print("Other")
}
// Destructuring
let (x, y) = (10, 20);
print(x); // 10
print(y); // 20
// Array destructuring
let [first, second, ...rest] = [1, 2, 3, 4, 5];
print(first); // 1
print(rest); // [3, 4, 5]
Object-Oriented Programming
B3D supports OOP with classes and inheritance:
// Class definition
class Animal {
name: string;
age: number;
func new(name: string, age: number) {
this.name = name;
this.age = age;
}
func speak() {
print(this.name + " makes a sound");
}
}
// Inheritance
class Dog extends Animal {
breed: string;
func speak() {
print(this.name + " barks");
}
}
// Usage
let dog = Dog("Buddy", 3, "Golden Retriever");
dog.speak(); // "Buddy barks"
Modules and Imports
// Import a module
use std::math;
use std::file;
use mylib::utils;
// Use imported functions
let pi = math::PI;
let sin_value = math::sin(0.5);
// Import specific items
use std::array::{map, filter};
let numbers = [1, 2, 3, 4, 5];
let doubled = map(numbers, func(x) { return x * 2; });
Python Integration
One of B3D's most powerful features is seamless Python integration:
// Import Python module
import numpy as np;
import pandas as pd;
// Use Python functions
let arr = np::array([1, 2, 3, 4, 5]);
let mean = np::mean(arr);
// Call Python functions from B3D
func process_data(data: array) {
let df = pd::DataFrame(data);
let result = df::describe();
return result;
}
// Pass B3D data to Python
let b3d_list = [1, 2, 3, 4, 5];
let py_result = python_function(b3d_list);
Package Manager
B3D includes a built-in package manager for managing dependencies:
// Initialize new project
b3d new myproject
cd myproject
// Install packages
b3d pkg install requests
b3d pkg install numpy@1.20
// Create b3d.toml
[package]
name = "myproject"
version = "0.1.0"
[dependencies]
requests = "*"
numpy = "1.20"
// Use packages in code
import requests;
let response = requests::get("https://api.example.com");
CLI Reference
b3d --version # Show version
b3d --help # Show help
b3d run script.b3d # Run a script
b3d shell # Start interactive shell
b3d new project_name # Create new project
b3d build # Build project
b3d pkg install name # Install package
b3d pkg list # List installed packages
b3d fmt file.b3d # Format code
b3d check # Check for errors
b3d test # Run tests
Code Examples
Check out more examples in the examples directory
Frequently Asked Questions
Is B3D free?
Yes! B3D is open-source and licensed under MIT.
Can I contribute?
Absolutely! Visit our GitHub repository
How fast is B3D?
B3D is built on Rust and offers near-native performance for compiled operations.
Can I use B3D for production?
Yes! B3D is production-ready and used in various projects.
Where do I get support?
Join our community, check the GitHub discussions, or create an issue.