Nim First Impressions
Tags: nim
Published: 2020-01-21 07:09:39

---
title: Nim First Impressions
published: true
date: 2020-01-20 00:00:00 UTC
tags: Nim
canonical_url: https://www.rockyourcode.com/nim-first-impressions/
---

I've started dabbling in Nim [some days ago](https://www.rockyourcode.com/reading-nim-in-action/).

**My experience level**: I'm a self-taught hobby developer. No professional experience, but a lot of enthusiasm.  
I've created some toy applications, but nothing production-grade.  
I'm most familiar with JavaScript and React.js, but also know a bit of Clojure, Elixir, Python, and Reason.

# What is Nim?

From the **[Nim][nimlang]** website:

> Efficient, expressive, elegant
>
> Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula.

# Learning Curve

The syntax reminds of Python, with similarities to a natural language and the use of indentation and whitespace.

Example:

```nim
proc getAlphabet(): string =
  var accm = ""
  for letter in 'a'..'z':
    accm.add(letter)
  return accm

var
  child: tuple[name: string, age: int]
  today: tuple[sun: string, temp: float]

child = (name: "Rudiger", age: 2)
today.sun = "Overcast"
today.temp = 70.1
```

(see [Learn X in Y Minutes][learnx] and [Nim by Example][nimbyexample])

**Some pitfalls:**  
[Reference and pointer types](https://nim-lang.org/docs/tut1.html#advanced-types-reference-and-pointer-types):
Objects are value types in Nim. References are like JavaScript objects, which are “pass-by-value.” The object variable points to a reference of the object in memory.

```nim
type
  Node = ref object
    le, ri: Node
    data: int
var
  n: Node
new(n)
n.data = 9
```

For me, the **syntax is a plus**, as it's easy to learn.

The mental models prove to be a bit trickier. Nim is an **imperative** language, with the declared goal of compiling to C or C++ (which I don't know).

I haven't looked at the advanced features like [meta-programming and macros](https://nim-lang.org/docs/tut3.html) yet.

For the beginner, there are **tutorials and learning resources available**. See [Learn Nim][learnnim]. Even the official docs are approachable.

# Aesthetics & Fun

Programming in Nim **feels fun**. The type system seems well-built (not as powerful as OCaml's though?). Programming in Nim doesn't feel like such a hassle (TypeScript anyone?).  
It has iterators; it has variant types/enums; it has [templates](https://nim-lang.org/docs/tut2.html#templates).  
You can extend the language via macros. For example, I'm missing pattern-matching. But you could add a library like [Patty](https://github.com/andreaferretti/patty).

# Ecosystem

The ecosystem is **small**.

I would welcome a web-framework that holds your hand. [Jester][jester] seems to be the sole framework for back-end development (it's like Sinatra).  
You can get a working "hello-world"-server in a short time. But when it comes to features like authentication and authorization, I'm stumped - and [I'm not the only one](https://forum.nim-lang.org/t/2075).

I get the sense that Nim targets advanced developers. At the moment, Nim might fit people that are not afraid to write libraries for their needs or who can build wrapper scripts around existing C or C++ solutions.

# First Thoughts

I want to like Nim. I appreciate the syntax, and I love that the language compiles to native C, C++, or JavaScript.  
Nim looks like a serious contender to lower-level languages while still being reasonably high-level. It feels "fun and easy" like a scripting language (Python), but it's strongly statically typed. Thus Nim offers the best of both worlds.

The small ecosystem is a hurdle for junior programmers.

I'm not sure if I can make Nim my home - for now.

[nimlang]: https://nim-lang.org/
[learnnim]: https://nim-lang.org/learn.html
[nimbyexample]: https://nim-by-example.github.io/
[learnx]: https://learnxinyminutes.com/docs/nim/
[jester]: https://github.com/dom96/jester