Mastodon hachyterm.io

I’ve started dabbling in Nim some days ago.

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 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:

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 and Nim by Example)

Some pitfalls:
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.

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 yet.

For the beginner, there are tutorials and learning resources available. See Learn Nim. 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.
You can extend the language via macros. For example, I’m missing pattern-matching. But you could add a library like Patty.

Ecosystem

The ecosystem is small.

I would welcome a web-framework that holds your hand. 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.

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.