🪷 Lotus

A elegant and modern systems programming language

Lotus Style Guide

This style guide outlines conventions and best practices for writing Lotus code. Following these guidelines ensures consistent, readable, and maintainable code across the Lotus ecosystem.

Code Formatting

Indentation

Line Length

Blank Lines

Whitespace

Naming Conventions

Variables and Constants

Functions

Types

Comments and Documentation

Inline Comments

Block Comments

Function Documentation

Example:
// Calculate factorial of n
// Parameters: n (int) - non-negative integer
// Returns: int - factorial of n
fn int factorial(int n) {
    if n <= 1: {
        ret 1;
    }
    ret n * factorial(n - 1);
}

Control Flow

If Statements

Good:
if x > 10: {
    printf("x is large\n");
}

if condition1 && condition2 &&
   condition3: {
    // Handle case
}

Loops

Error Handling

Functions

Function Declaration

Good:
fn int add(int a, int b) {
    ret a + b;
}

fn void process_data(int count, 
                     int max_size) {
    // Implementation
}

Function Length

Return Values

Memory Management

Allocation

Deallocation

Good:
int* data = malloc(100 * sizeof(int));
if data: {
    // Use data
    free(data);
}

Printf Usage

Formatting

Format Verbs

Good:
int value = 42;
printf("The answer is %d\n", value);
printf("Hex: %x, Oct: %o\n", value, value);
printf("String: %s\n", "hello world");

Best Practices

General Guidelines

Performance Considerations

Code Organization

Common Pitfalls to Avoid

Memory Issues

Logic Errors

Style Issues

Quick Checklist

Before submitting code, verify:

← Back to Documentation Get Help