Show HN: Wyzer Programming Language

Show HN: Wyzer Programming Language

The Wyzer Programming Language “Simplicity is not the absence of power. It is power without pretense.” ~ Atiksh Sharma Feel free to use the pretentious quote anywhere lol. Wyzer is a statically typed, compiled, resource-oriented programming language with integrated distributed safety via choreographic programming and a perceus memory model. Wyzer 编程语言:“简单并非缺乏力量,而是无需伪装的力量。”—— Atiksh Sharma。欢迎随意使用这句自命不凡的引言。Wyzer 是一门静态类型、编译型、面向资源的编程语言,通过编排式编程(choreographic programming)和 Perceus 内存模型集成了分布式安全性。

Motive behind Wyzer: Rust guarantees safety within a process. It does nothing for: distributed deadlocks, protocol mismatches, cross-service correctness. To solve this problem, Wyzer introduces the concept of choreographic programming, which is one of the few serious attempts to solve it. Contributions are welcome; if you want to contribute to the language, please read RESEARCH.md. Join our discord server as well :)) https://discord.gg/RhpPhkTrVu Wyzer 的动机:Rust 保证了进程内的安全,但它无法解决分布式死锁、协议不匹配以及跨服务正确性等问题。为了解决这些问题,Wyzer 引入了编排式编程的概念,这是目前为数不多试图解决该问题的严肃尝试之一。欢迎贡献代码;如果您想为该语言做出贡献,请阅读 RESEARCH.md。也欢迎加入我们的 Discord 服务器 :)) https://discord.gg/RhpPhkTrVu

Documentation

文档

To learn how to program in Wyzer, check out our official documentation: Introduction, Variables and Types, Control Flow, Functions and Structs, Memory Model. 要学习如何使用 Wyzer 编程,请查看我们的官方文档:简介、变量与类型、控制流、函数与结构体、内存模型。

How to Code in Wyzer

如何在 Wyzer 中编写代码

Wyzer is designed to be simple, explicit, and easy to read. Here is a quick look at how you write code in Wyzer. Wyzer 的设计目标是简单、显式且易于阅读。以下是 Wyzer 代码编写的快速概览。

1. Variables and Types 1. 变量与类型 Everything has a clear type, and variables are immutable (cannot be changed) by default. If you want to change a variable, you must explicitly use var instead of let. You can also use const for compile-time constants. 所有事物都有明确的类型,变量默认是不可变的(不能被修改)。如果你想修改一个变量,必须显式使用 var 而不是 let。你也可以使用 const 来定义编译时常量。

fn main() {
    const MAX: u32 = 100; // Compile-time constant
    let x: u32 = 10;      // Cannot be changed
    var y: u32 = 20;      // Can be changed
    y = y + x;
    std::io::println(y);
}

2. Structs and Data 2. 结构体与数据 You can define custom data structures and access their fields directly. 你可以定义自定义数据结构并直接访问其字段。

struct Point { x: u32, y: u32 }
fn main() {
    let p: Point = Point { x: 10, y: 20 };
    std::io::println(p.x);
}

3. Control Flow 3. 控制流 Wyzer supports standard if/else, while, and for loops. Note that loops don’t need parentheses around the condition. Wyzer 支持标准的 if/else、while 和 for 循环。注意,循环条件不需要括号。

fn main() {
    let mut i: u32 = 0;
    while i < 3 {
        std::io::println(i);
        i = i + 1;
    }
}

4. Error Handling and Match 4. 错误处理与匹配 Errors are not hidden. Functions that can fail return a Result<T, E>. You use match expressions to safely handle both the success (Ok) and error (Err) cases. Note that match is an expression, so if used as a standalone statement, it requires a trailing semicolon! 错误不会被隐藏。可能失败的函数会返回一个 Result<T, E>。你可以使用 match 表达式来安全地处理成功(Ok)和错误(Err)情况。注意,match 是一个表达式,因此如果作为独立语句使用,它需要一个结尾分号!

fn main() {
    let result: Result<u32, str> = Ok(42);
    match (result) {
        Ok(value) => std::io::println(value),
        Err(err_msg) => std::io::println(0)
    };
}

FAQ: What It Is, Why It Exists, and What’s Actually New

常见问题解答:它是什么,为什么存在,以及有什么新意

A simple guide with no math. Use this to explain the project quickly. 一份不含数学公式的简单指南。用它来快速解释这个项目。

1. What Wyzer Is, In One Paragraph 1. 一段话概括 Wyzer Wyzer is a programming language built on one idea: most hard problems (like memory bugs, deadlocks, and network errors) happen because it is not clear who owns a resource. Instead of using three different tools to fix memory, concurrency, and networks, Wyzer uses just one ownership rule for all three. Wyzer 是一门基于一个核心理念构建的编程语言:大多数难题(如内存错误、死锁和网络错误)的发生,是因为不清楚谁拥有某个资源。Wyzer 不使用三种不同的工具来分别修复内存、并发和网络问题,而是对这三者使用统一的所有权规则。

2. Why Make a New Language At All? 2. 为什么要开发一门新语言? This is a fair question, and the honest answer starts with what is already good about existing options, not what is wrong with them. Rust proved you can have safe memory without a garbage collector. This is great, but Rust is hard to learn, and its rules make some common code structures difficult to write. Go, Java, C#, and Python use garbage collectors. This makes them easier to use but slower and less predictable. This is bad for real-time or low-level systems. Network programming is still mostly done by hand. You write two programs and hope they talk to each other correctly. When they don’t, you get bugs. Wyzer’s goal: Get the safety of Rust without the difficulty, and use the same rule to make network programs safe too. 这是一个合理的问题,诚实的回答应从现有方案的优点出发,而不是它们的缺点。Rust 证明了无需垃圾回收器也能实现内存安全。这很好,但 Rust 学习曲线陡峭,且其规则使得某些常见的代码结构难以编写。Go、Java、C# 和 Python 使用垃圾回收器,这使它们更易用,但速度较慢且不可预测,这对实时或底层系统不利。网络编程目前大多仍是手动完成的:你编写两个程序,并希望它们能正确通信,一旦出错,就会产生 Bug。Wyzer 的目标是:在获得 Rust 安全性的同时降低难度,并使用相同的规则使网络程序也变得安全。

3. What’s Actually New About It? 3. 它到底有什么新意? Most of Wyzer’s pieces already exist. What is new is putting them together. Perceus reference counting: Fast memory management without Rust’s complexity. We borrowed this from Koka and Lean 4. Choreographic programming: Writing one network rule that creates code for every computer. We borrowed this from academic research. What is new: We use the choreography idea for more than just networks. We use it for threads and interrupts too. The exact same rule proves memory safety, interrupt safety, and network safety. The benefit: You only need to learn one rule to manage memory, threads, and networks safely. Wyzer 的大部分组件早已存在,新意在于将它们整合在一起。Perceus 引用计数:无需 Rust 的复杂性即可实现快速内存管理(借鉴自 Koka 和 Lean 4)。编排式编程:编写一条网络规则即可为每台计算机生成代码(借鉴自学术研究)。新意在于:我们将编排理念的应用范围扩展到了网络之外,还将其用于线程和中断。完全相同的规则证明了内存安全、中断安全和网络安全。好处是:你只需学习一条规则,即可安全地管理内存、线程和网络。

4. Core Design Principles 4. 核心设计原则 These are the values that drive our decisions. They explain why Wyzer looks the way it does. One way to write a thing. If there are two ways to write the same thing, we remove one. No hidden magic, but keep it clean. Important things should be visible in the code, but you shouldn’t have to write extra boilerplate. Let the compiler do the work, unless it is confusing. We want the compiler to figure things out, but we require clear rules when things get tricky. Be honest about what is not finished. We mark unsolved problems clearly so people know what needs work. 这些价值观驱动着我们的决策,解释了 Wyzer 为何呈现出现在的样子。做一件事只有一种方式:如果实现同一功能有两种方式,我们就删掉一种。没有隐藏的魔法,但保持代码整洁。重要的事情应在代码中可见,但你不必编写额外的样板代码。让编译器去工作,除非这会造成困惑。我们希望编译器能处理好逻辑,但在情况复杂时,我们要求有明确的规则。诚实面对未完成的部分:我们清晰地标记出未解决的问题,以便人们知道哪些地方需要改进。

5. The Core Semantics, In Plain Language 5. 核心语义(通俗语言版) This section is a simple map of the formal rules. Read this first to understand the basics. Memory (Section 5): You write functional code that does not change data. Behind the scenes, if a piece of data has only one owner, the compiler changes it directly in memory. This makes it as fast as C without a garbage collector or lifetime rules. Ownership is everything (Sections 3, 6, 7): The one rule is that once you use a resource, you cannot use it again. This applies to memory, network messages, and hardware interrupts. Safe networks (Section 6): You write regular functions, and the types show who owns the data. The compiler figures out the network rules and checks them for you. This catches deadlocks and dropped messages before the code even runs. No hidden control flow: There is no async/await split. Errors are returned as standard types, not hidden exceptions. 本节是形式化规则的简单映射。请先阅读此部分以了解基础知识。内存(第 5 节):你编写不修改数据的函数式代码。在底层,如果一段数据只有一个所有者,编译器会直接在内存中修改它。这使得它像 C 一样快,且无需垃圾回收器或生命周期规则。所有权是一切(第 3、6、7 节):核心规则是,一旦你使用了某个资源,就不能再次使用它。这适用于内存、网络消息和硬件中断。安全网络(第 6 节):你编写常规函数,类型系统会显示谁拥有数据。编译器会计算出网络规则并为你检查。这能在代码运行前捕获死锁和丢包问题。没有隐藏的控制流:没有 async/await 的区分。错误作为标准类型返回,而不是隐藏的异常。

6. Frequently Asked Questions 6. 常见问题解答 “Isn’t this just Rust with extra steps?” No. We want Rust’s safety without its steep learning curve. We use a different method (Perceus) for memory, and Rust does not have our network features. “这不就是加了额外步骤的 Rust 吗?”不是。我们想要 Rust 的安全性,但不想承受其陡峭的学习曲线。我们在内存管理上使用了不同的方法(Perceus),而且 Rust 并不具备我们的网络特性。