The premise you are highlighting is one of the most actively discussed topics in modern software engineering. Python won the world by being the "glue" language for C/C++, but as you noted, its 1990s-era design choices (the Global Interpreter Lock, dynamic typing, slow execution, fragmented packaging) created a massive maintenance overhead for modern codebases.
What would a "Modern Python" look like today?
Strongly Typed with Aggressive Inference: Instead of Python's purely dynamic typing (which requires massive test suites to catch runtime typos), it would use a TypeScript-style or Rust-style type system. You wouldn't have to write out types everywhere, but the compiler would infer them and catch errors before the script runs. Data-Race Free Concurrency (No GIL): A modern language wouldn’t have a Global Interpreter Lock. It would feature native async/await and lightweight threads (like Go's goroutines or Erlang's actors) that map efficiently to multi-core processors. Rust-Like Error Handling: Instead of Python’s try/except blocks—where any function can crash unexpectedly—it would use Rust’s Option and Result types, combined with pattern matching. This forces the scripter to acknowledge that a function might fail, but with a highly ergonomic, readable syntax. Zero-Cost Interoperability: It would have a first-class Foreign Function Interface (FFI) for Rust. You would be able to import a Rust crate directly into your script, and the language would automatically understand Rust’s structs, enums, and traits without needing manual C-bindings. A "Cargo-like" Toolchain: It wouldn't rely on the chaotic pip/venv/conda ecosystem[1]. It would come with a single, unified tool (like Rust's cargo or JavaScript's deno) that handles formatting, linting, testing, and package management out of the box.
Known Efforts and Languages Filling this Niche
1. Embedded "Rust-Native" Scripting Languages
Rhai: Often described as "the Lua of Rust"[2][3]. Rhai is a dynamic, embedded scripting language[4] that uses a syntax very similar to Rust/JavaScript but completely removes the concept of lifetimes and borrowing[5]. It is incredibly easy to expose Rust functions to Rhai scripts[6][7]. Rune: An embeddable dynamic language for Rust that is "async-first."[5] It natively supports modern asynchronous programming and macros, allowing developers to script high-performance async Rust backends without wrestling with Rust's strict compiler rules[8]. Dyon: A dynamically typed scripting language written in Rust that uses a "lifetime checker" instead of a garbage collector. It’s an experiment in making a scripting language that feels structurally like Rust but without the cognitive overhead[9].
2. Evolving Python Itself via PyO3
3. The "Python but Fast" Languages (Systems-Level Python)
Mojo: Created by Chris Lattner (the creator of LLVM and the Swift programming language), Mojo is a superset of Python. It aims to have the exact same syntax as Python but allows developers to gradually drop down to systems-level memory management and strong typing. While its current focus is AI and the C++ ecosystem, conceptually, Mojo is exactly what "Python created today" looks like. Erg: A statically typed language that compiles down to Python bytecode[10]. It looks like a modern, functional Python but provides the strictness and safety guarantees of a language like Rust[10], running perfectly alongside existing Python libraries.
Summary
Here are the GitHub links to all the projects mentioned, categorized by how they approach the problem:
1. Embedded "Rust-Native" Scripting Languages
Rhai: https://github.com/rhaiscript/rhai (A lightweight, fast, and easy-to-use scripting language for Rust that feels like a mix of Rust and JavaScript.) Rune: https://github.com/rune-rs/rune (An embeddable dynamic language for Rust with native support for Dyon: https://github.com/PistonDevelopers/dyon (A rusty, dynamically typed scripting language that relies on a lifetime checker instead of a garbage collector.)
2. Evolving Python Itself via Rust Interop
PyO3 (Rust bindings for Python): https://github.com/PyO3/pyo3 Maturin (Build system for PyO3): https://github.com/PyO3/maturin
Polars (Blazing fast DataFrames): https://github.com/pola-rs/polars Pydantic (Data validation): https://github.com/pydantic/pydantic (Note: The core validation engine was rewritten in Rust as Ruff (Extremely fast Python linter): https://github.com/astral-sh/ruff
3. The "Python but Fast/Strict" Languages
Mojo: https://github.com/modularml/mojo (Chris Lattner's project to build a strict, systems-level superset of Python. The core compiler is proprietary to Modular, but the standard library and issue tracking are hosted here on GitHub). Erg: https://github.com/erg-lang/erg (A statically typed language that compiles to Python bytecode, giving you Rust-like strictness while running alongside normal Python.)
Because Python is written in C (specifically CPython), it has always had an API that allows you to write C code and expose it to Python. PyO3 is a framework that interacts with that C API so you can use Rust instead.
1. Write Python modules in native Rust (The main use case)
Speed: If you have a massive loop or heavy math in Python, you can move just that specific function into Rust and make it 10x to 100x faster. Bypassing the GIL: PyO3 allows you to temporarily release Python's Global Interpreter Lock (GIL). You can pass data to Rust, let Rust spawn 16 threads to process it simultaneously, and then hand the result back to Python. Safety: Unlike writing C extensions (which often crash Python with memory leaks or segfaults if you make a mistake), Rust's compiler guarantees memory safety.
2. Embed Python inside a Rust application
Summary
1. Are they embedded or standalone?
Rhai & Rune: Designed as general-purpose embedded scripting languages for any Rust backend (web servers, data processors, automation tools). Dyon: Designed specifically to be embedded into game engines (it was created by the developers of the Piston game engine for Rust). It includes native math features (like 4D vectors and hex colors) tailored for game development.
2. Are they interpreted or compiled?
Rhai (AST Walker): Rhai is interpreted. When you pass a script to Rhai, it compiles it into an Abstract Syntax Tree (AST), and then a Rust engine "walks" that tree to execute the logic. (Note: Rhai recently added an experimental bytecode VM called "Rhai Grain," but AST walking is its bread and butter). Rune (Bytecode VM): Rune is technically compiled to bytecode, which is then run on its own highly optimized Virtual Machine (the Rune VM). If you know how standard Python (CPython) or Java works, Rune works the exact same way. It compiles scripts to intermediate bytecode first, which gives it a performance edge and excellent async support. Dyon (AST Walker): Dyon is interpreted. What makes Dyon incredibly unique, however, is that it does not have a Garbage Collector. To prevent memory leaks, it borrows a concept from Rust and uses a runtime "lifetime checker" to track variables.
Why design them this way?
1. Can they be extended to serve as a DSL?
Rhai (The Ultimate DSL Builder): Rhai is explicitly designed to be stripped down and molded into a DSL. In fact, "Use Rhai as a DSL" is a dedicated chapter in their official book. Disable Everything: You can surgically disable standard features. Don't want users to be able to write while loops, use floating-point math, or define variables? You can turn all of that off. Custom Operators & Syntax: You can define entirely new operators (e.g., registering # or => to do custom math) or write custom syntax parsers that allow your script writers to write domain-specific commands that Rhai evaluates behind the scenes.
Rune (Macro-Powered DSLs): Rune approaches DSLs exactly like Rust does: Macros. Rune natively supports token-stream macros. This allows you to define custom structural blocks (like html! { <div> </div> } or query!(SELECT * FROM users)) directly inside the script. This makes it incredibly powerful for writing declarative DSLs while still having a fully-featured programming language wrapped around it. Dyon (A Pre-built Game DSL): Dyon is less about building your own DSL, and more that it is a DSL for math and game programming. It has built-in syntax for 4D vectors (e.g., vec4(x, y, z, w)), HTML hex colors (e.g., #ff0000), and mathematical linkings that make it highly domain-specific out of the box.
2. Can these extensions run on WASM?
Rhai on WASM: Rhai compiles perfectly to WebAssembly. Because it can be compiled as a no_std (no standard library) crate, it is completely independent of the operating system. A full-featured Rhai scripting engine compiles to a tiny WASM payload of less than 400KB[1]. This means you can embed Rhai into a Rust web backend, compile the whole thing to WASM, and run the exact same scripts directly in the user's web browser using JavaScript. Rune on WASM: Rune also has exceptional WASM support. In fact, if you go to Rune's website and use their "Playground" to test code, that is a full Rune Virtual Machine running entirely in your browser via WebAssembly[2]. It is also being heavily used in the "TinyML" space to compile Machine Learning pipelines that execute inside WebAssembly edge runtimes[3].
No comments:
Post a Comment