nim

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Nim

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
    ARC/ORC
    : The default in v2.0. Clean up is deterministic (destructors).
  • Use
    f-strings
    :
    fmt"Hello {name}"
    .
  • Use
    karax
    : For frontend (compiling Nim to JS).
Don't:
  • Don't mix styles: Choose PascalCase or camelCase (Nim is style-insensitive but consistency matters).
推荐做法
  • 使用
    ARC/ORC
    :v2.0版本的默认选项,确定性清理(通过析构函数)。
  • 使用
    f-strings
    :示例:
    fmt"Hello {name}"
  • 使用
    karax
    :用于前端开发(将Nim编译为JS)。
不推荐做法
  • 不要混合代码风格:选择PascalCase或camelCase(Nim对代码风格不敏感,但一致性很重要)。

References

参考资料