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
purescript , and
reason . 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.” Cool… wait. What the hell is
nim ? 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.
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.nimconst hand* = ":wave:"
Create another file called
hello.nim and paste this in:
# this is hello.nimimport waveecho "Hello World " & hand
Now let’s compile !
$ nim c hello.nim
$ ./helloHello World :wave:
You have a binary that is fast (
2 ms ), small (
107 kB ) and dependency-free .
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. Run
nim c --app:lib wave.nim and we just made a dynamic library. Run
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.
cprogram 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 . Down to
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
44 kB . Better.
ccompiler 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? The
c stands for compile to c and it’s the default backend.
Then we can use the tools of the backend’s ecosystem (like code coverage and debuggers). Seriously.
You bet. That’s one of the strengths.
Use libs like
redis , you name it. Use static libraries or link to dynamic ones like
openssl . 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.
$ nim js -d:release hello.nim$ node nimcache/hello.jsHello World :wave:
Here’s one reason:
The correct answer, of course, is .
With big funding comes big reach and big communities. Although
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.
|Web Site||The project’s entry point|
|Source||The github project|
|nimble||The nim package manager|
|Forums||An async discussion board|
|On Twitter||Nim’s Twitter account|
|On Reddit||A subreddit community|
|Documentation||Links to documentation and tutorials|
|Nim In Action||A book published by Manning Press|
|Intro Video||Dominik Picheta gives an overview|
|nimble directory||Web front-end for nimble|
|Awesome Nim||Curated projects (awesome style)|
|Github Projects||open source project; sorted by recently update|
|Vim Plugin||Nim rhymes with Vim|
|VS Code Plugin||Visual Studio Code plugin|
|Go Write Some Apps|
|Jester||Write some web services|
|Karax||Write some single page web apps|
|NiGui||Write GTK+ 3 / Win32 desktop apps|
|Winim , wNim||Write Windows apps|
|objc||Write macOS apps (wip)|
|android||Write Android apps|
|Arraymancer||Write deep learning apps|
|serial.nim||Write serial-port apps|
|libusb||Write USB apps|
|Ethereum 2.0||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.