A Programming Language Underdog
As devs in late 2018, we’ve got lots of programming language choices.
Mainstream ones alone, there’s about a dozen or so of them.
They’re all awesome.
As you wander a bit further down the obscurity path, you’ll find languages like
And just past those, you’ll find
I found out about
nim by accident.
I was looking at a library for ui development and it said, “We also have bindings for
nim and others.”
What the hell is
Out of curiosity, I gave it a try.
A couple of throw-away examples. A rewrite of an old project. A few new prototypes of incredibly cringey ideas. You know, mostly trying to get a sense of where the edges are.
5 months later, this language has still got me captivated.
First, A Speed Run
We’re going to make a small CLI app so we have something to talk about for the rest of this article.
So let’s install
nim and get a feel for the toolchain.
mkdir fun, then
cd fun, and create a text file called
wave.nim with this nonsense:
# this is wave.nim
const hand* = "👋"
Create another file called
hello.nim and paste this in:
# this is hello.nim
echo "Hello World " & hand
Now let’s compile!
$ nim c hello.nim
Hello World 👋
You have a binary that is fast (
2 ms), small (
107 kB) and dependency-free.
A Crafty and Capable Compiler
We fed the compiler the entry point (
hello.nim) and it found its dependencies (
wave.nim) by examining the code.
If we were to drop a 3rd file in there, well, it wouldn’t have included it if we didn’t use an
We didn’t give it a
main() function, and it just made an executable!
But that’s not the only option.
nim c --app:lib wave.nim and we just made a dynamic library.
nim c --app:staticLib wave.nim and now it’s a static library.
Windows, macOS, Linux are supported, as are a few other platforms like Raspberry Pi and Nintendo Switch!
With the right setup, cross-compilation can be a thing, but the story is nowhere near what
go can do.
Honestly, nothing I’ve seen touches
go in the build arena.
c program is only
nim bakes in a bunch of functions and constants including file I/O and a configurable garbage collector which adds overhead.
This ain’t your grandfather’s garbage collector. You can pick the algorithm (6 choices) and the time budget per activation. And it doesn’t run “whenever” like most do. You can even turn it off if you live in YOLOville.
Also, we compiled in debug mode, lol.
In debug mode you get fancy stack traces and other things to help you, well, debug.
Try compiling with
nim c -d:release hello.nim.
89 kB. Better?
With another compiler flag, you can optimize for size instead of speed.
nim c -d:release --opt:size hello.nim and now we’re
c compiler is faster!
Ya, that’s true because
nim compiles to c!
Then it compiles to a binary by using
clang (for example).
Remember when we typed
nim c hello.nim to compile?
c stands for compile to c and it’s the default backend.
It can compile to
Then we can use the tools of the backend’s ecosystem (like code coverage and debuggers). Seriously.
So good language interop?
You bet. That’s one of the strengths.
Use libs like
redis, you name it.
Use static libraries or link to dynamic ones like
There are language features to deal with name-mangling, namespacing, linking, and more.
Hell, you can even type
c code in a string within
nim and the compiler will do the right thing.
There’s also a c2nim tool for helping you automate wrappers.
So Cross Platform / Cross Language? That’s crazy!
$ nim js -d:release hello.nim
$ node nimcache/hello.js
Hello World 👋
Why Haven’t I Heard Of
Here’s one reason:
The correct answer, of course, is 🤷.
With big funding comes big reach and big communities.
nim hasn’t had that kind of sponsorship, it looks to be heating up.
What I find amazing is that despite the grassroots nature of this project, it has features that run alongside the current mainstream leaders.
Here’s a big ol’ stack of URLs to get going. I’ve also heard Google is a pretty good world wide web site too.
|The project’s entry point
|The github project
|The nim package manager
|An async discussion board
|Nim’s Twitter account
|A subreddit community
#nim on irc.freenode.net
|Links to documentation and tutorials
|Nim In Action
|A book published by Manning Press
|Dominik Picheta gives an overview
|Web front-end for nimble
|Curated projects (awesome style)
|open source project; sorted by recently update
|Nim rhymes with Vim
|VS Code Plugin
|Visual Studio Code plugin
|Go Write Some Apps
|Write some web services
|Write some single page web apps
|Write GTK+ 3 / Win32 desktop apps
|Write Windows apps
|Write macOS apps (wip)
|Write Android apps
|Write deep learning apps
|Write serial-port apps
|Write USB apps
|Ethereum .. uh.. things - (seriously was my best attempt)
That’s a fun start, but there is so much more. I’ll get to work on some more articles.