Est. 2008 Beginner

Nim

A statically typed compiled systems programming language combining Python's elegance with C's performance, featuring powerful metaprogramming and compilation to multiple backends.

Created by Andreas Rumpf

Paradigm Multi-paradigm: Procedural, Object-Oriented, Functional, Metaprogramming
Typing Static, Strong, Inferred
First Appeared 2008
Latest Version Nim 2.2.4 (April 2025)

Nim is a statically typed, compiled systems programming language that combines Python’s readable syntax with C’s performance. Created by Andreas Rumpf, Nim compiles to C, C++, JavaScript, and other backends, offering remarkable flexibility while maintaining efficiency.

History & Origins

Nim began in 2005 when Andreas Rumpf, a German software engineer, started developing a language that would combine the best features of his favorite programming languages while avoiding their weaknesses.

The Birth of Nimrod

The language was originally named “Nimrod” - a reference to the biblical figure known as a mighty hunter. Rumpf wanted a language that would be:

  • As readable as Python - Clean, indentation-based syntax
  • As fast as C - Direct compilation to efficient machine code
  • As expressive as Lisp - Powerful metaprogramming capabilities
  • As practical as Ada - Strong typing and safety features

The first compiler was written in Pascal using the Free Pascal compiler, demonstrating Nim’s philosophy of pragmatism over purity.

Self-Hosting Milestone

A crucial milestone came in 2008 when Nim became self-hosting - the compiler was rewritten in Nim itself. This bootstrap moment proved the language’s maturity and capability for systems-level programming.

The Rename to Nim

In December 2014, with version 0.10.2, the language was renamed from “Nimrod” to simply “Nim.” The change reflected the community’s preference for a shorter, more modern name that avoided potential cultural sensitivities associated with the biblical reference.

Design Philosophy

Nim embodies several key principles that set it apart:

Efficiency Through Compilation

Unlike interpreted languages, Nim compiles to C (and optionally C++, JavaScript, or Objective-C). This means:

1
2
3
4
5
6
# This Nim code
proc factorial(n: int): int =
  if n <= 1: 1
  else: n * factorial(n - 1)

echo factorial(10)

Gets compiled to efficient C code, then compiled again by your C compiler with all its optimizations. The result is performance comparable to hand-written C.

Python-Inspired Syntax

Nim uses significant whitespace and emphasizes readability:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Clean, Python-like syntax
type
  Person = object
    name: string
    age: int

proc greet(p: Person) =
  echo "Hello, ", p.name, "!"

let alice = Person(name: "Alice", age: 30)
alice.greet()

Powerful Metaprogramming

Nim’s macro system operates on the abstract syntax tree (AST), enabling compile-time code generation:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import macros

macro generateProcs(names: varargs[untyped]): untyped =
  result = newStmtList()
  for name in names:
    result.add quote do:
      proc `name`() = echo astToStr(`name`)

generateProcs(foo, bar, baz)
foo()  # Prints: foo

Key Features

Multiple Compilation Targets

Nim’s most distinctive feature is its ability to compile to multiple backends:

  • C - Default target, maximum compatibility
  • C++ - For projects requiring C++ libraries
  • JavaScript - Full-stack development with shared code
  • Objective-C - iOS and macOS development

Memory Management Options

Nim 2.0 introduced a revolutionary approach to memory management:

  • ORC (default) - Cycle-collecting reference counting with deterministic destruction
  • ARC - Reference counting without cycle collection (faster, if you avoid cycles)
  • Traditional GC - Opt-in garbage collection for compatibility
  • Manual - Full control for systems programming

Type System

Nim’s type system balances safety with flexibility:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Strong static typing with inference
let x = 42        # Inferred as int
var y: float = 3.14

# Distinct types for extra safety
type Meters = distinct float
type Feet = distinct float

let distance: Meters = 100.Meters
# let wrong: Feet = distance  # Compile error!

Effect System

Nim tracks side effects at compile time:

1
2
3
4
5
6
7
proc pureCalculation(x: int): int {.noSideEffect.} =
  # Can only call other pure procedures
  result = x * 2

func alsosPure(x: int): int =
  # 'func' is shorthand for 'proc {.noSideEffect.}'
  x + 1

The Path to 1.0

After over a decade of development, Nim 1.0.0 was released on September 23, 2019. This milestone represented:

  • A stable, backwards-compatible API
  • Production-ready tooling
  • Comprehensive standard library
  • Mature package ecosystem via Nimble

Nim 2.0 and Beyond

Version 2.0, released in August 2023, marked another major evolution:

  • ORC as default - Deterministic memory management without GC pauses
  • Improved JavaScript target - Better web development support
  • Enhanced tooling - Better IDE integration and error messages

The language continues to evolve with quarterly releases, balancing innovation with stability.

Nim Today

Nim has found its place in several domains:

  • Systems Programming - Native compilation and C interop make it suitable for OS development
  • Web Development - JavaScript backend enables full-stack Nim applications
  • Game Development - Performance and ease of use attract game developers
  • Blockchain - Status and other projects leverage Nim for secure, high-performance code
  • Scientific Computing - Libraries like Arraymancer enable machine learning and data science

Why Nim Matters

Nim represents an important experiment in language design: can a language be simultaneously high-level and low-level? Can readability coexist with raw performance? Can a small team create something that competes with decades-old languages backed by major corporations?

The answer, increasingly, seems to be yes. Nim proves that programming language design still has room for innovation, and that thoughtful synthesis of existing ideas can produce something genuinely new and useful.

For Python developers seeking performance, for C programmers seeking productivity, and for anyone frustrated by the traditional tradeoffs in programming languages, Nim offers a compelling alternative.

Timeline

2005
Development begins under the name 'Nimrod'
2008
First public release; compiler rewritten from Pascal to Nim (self-hosting)
2014
Language renamed from 'Nimrod' to 'Nim' with version 0.10.2 release
2016
Nim 0.14 introduces concepts and improved generics
2019
Nim 1.0.0 released on September 23rd - first stable version
2023
Nim 2.0 released with ARC/ORC memory management as default
2024
Nim 2.2 brings significant improvements to ORC memory management
2025
Nim 2.2.4 released with continued performance and stability improvements

Notable Uses & Legacy

Karax

A single-page application framework for Nim, enabling reactive web development.

Arraymancer

A deep learning and tensor library, showcasing Nim's capabilities in scientific computing.

Prologue

A full-featured web framework inspired by Flask and Django, demonstrating Nim's web development potential.

Status

A secure messaging app and Ethereum client built with Nim for performance and security.

NimCrypto

A cryptographic library providing various encryption and hashing algorithms, used in security-critical applications.

Language Influence

Influenced By

Python Ada Modula-3 Lisp C++ Object Pascal Oberon

Running Today

Run examples using the official Docker image:

docker pull nimlang/nim:alpine

Example usage:

docker run --rm -v $(pwd):/app -w /app nimlang/nim:alpine nim c -r hello.nim

Topics Covered

Last updated: