nim
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNim
Nim
Nim v2.0 (2023/2024) made ORC (Deterministic Memory Management) the default. It compiles to C/C++/JS and offers Python-like syntax with C-like speeds.
Nim v2.0(2023/2024版本)将ORC(确定性内存管理)设为默认选项。它可编译为C/C++/JS,兼具类Python的语法与类C的运行速度。
When to Use
适用场景
- Game Development: Hot reloading and performance.
- Embedded: Compiles to small C code requiring no runtime.
- Scripting: Compiles so fast it feels like a script ().
nim r
- 游戏开发:支持热重载,性能出色。
- 嵌入式开发:编译后的C代码体积小巧,无需运行时环境。
- 脚本开发:编译速度极快,使用体验近似脚本(通过命令运行)。
nim r
Core Concepts
核心概念
Metaprogramming
元编程
First-class support. You can rewrite the AST to create DSLs.
原生支持元编程。你可以重写AST来创建领域特定语言(DSL)。
ORC
ORC
Cycle-collecting ARC. Automatic memory management without pauses.
支持循环引用回收的ARC。无需暂停的自动内存管理机制。
Backends
编译后端
Can compile to C, C++, Objective-C, or JavaScript.
可编译为C、C++、Objective-C或JavaScript。
Best Practices (2025)
2025年最佳实践
Do:
- Use : The default in v2.0. Clean up is deterministic (destructors).
ARC/ORC - Use :
f-strings.fmt"Hello {name}" - Use : For frontend (compiling Nim to JS).
karax
Don't:
- Don't mix styles: Choose PascalCase or camelCase (Nim is style-insensitive but consistency matters).
推荐做法:
- 使用:v2.0版本的默认选项,确定性清理(通过析构函数)。
ARC/ORC - 使用:示例:
f-strings。fmt"Hello {name}" - 使用:用于前端开发(将Nim编译为JS)。
karax
不推荐做法:
- 不要混合代码风格:选择PascalCase或camelCase(Nim对代码风格不敏感,但一致性很重要)。