DEV Community

Sophia Brandt
Sophia Brandt

Posted on • Originally published at rockyourcode.com on

Nim First Impressions

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
Enter fullscreen mode Exit fullscreen mode

(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
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (7)

Collapse
 
juancarlospaco profile image
Juan Carlos • Edited

You can read the Nim for Python programmers.

If you need a web framework with more features then try NimWC,
just to name some features it has:

  • 2 Factor Authentication by default (TOTP) built-in.
  • App Store to publish your project and get others.
  • Admin Control Panel.
  • Admin Status Page.
  • Self-Firejailing security (it can Firejail itself).
  • Optional ReCaptcha built-in.
  • Optional WebP support built-in.
  • Bulma CSS (No JS) or Bootstrap CSS or WaterCSS (classless).
  • JavaScript framework agnostic.
  • Libravatar/Gravatar support built-in.
  • Upload/Download files and images (private or public).
  • Postgres or SQLite databases.
  • Auto-Rotating file Logger, with web Log Viewer.
  • Optional Email notifications.
  • Plugin skeleton creator to create your own new plugin projects.
  • Features are compile-time optional. And more, I dont want this to be too long ;P

When we started wasnt even documentation nor auth for Jester.
We keep making it better, we would love more users to try it!.

Live Demo at nimwc.org/login
All the code at github.com/ThomasTJdev/nim_website...

Collapse
 
sophiabrandt profile image
Sophia Brandt

Thanks. That's nice.

Still, my argument stands.
For web, you have Jester, but no help with OAuth, etc. There are just no many usable libraries at the nimble package library.

nimwc looks interesting though. I hope to see more solutions like this.

Collapse
 
0ctavia profile image
Octa

I think Nim has growing potential but might be easier with a good grasp of lower-level languages, and like you said, some more libraries would be useful. I've been meaning to try it, and I wonder where it'll end up in a few years.

Collapse
 
sophiabrandt profile image
Sophia Brandt

Yes, I agree.
I think that if you've experience with C or C++, Nim will be a breath of fresh air.
If you're only accustomed to higher-level languages, it's harder to understand.

Collapse
 
iambudi profile image
I am Budi

Thank you so much for the post. I never planned to learn Nim before. After reading your post and jumped to learn X in Y minutes, it changed my mind. Nim is so easy to learn.
I've been learning it for 1.5 weeks intensively hence i forgot to thank you 😃.
Nim is not perfect language, some feels like incomplete or makes me wonder, but yes it's improving and I'm starting to like it.

Collapse
 
jorjun profile image
jorjun

I adore the semantic whitespace in Nim. Given so many coders nowadays are not professional, and looking at the growth rate of Python it is surprising Swift & Rust haven't followed suit.

But unlike Python, if you define a class in Nim you can't indent all of the methods, so looking at a large program in Nim looks a bit like reading giant nerdy C source - just minus the {} braces and the ; semicolons.

Indentation really helps at the application layer. But as you suggest, Nim right now seem targetted at competent C programmers who want extra leverage. But it falls between two styles at the moment. One to watch though.

Collapse
 
ponyatov profile image
Dmitry Ponyatov

Nim works great with TCC -- compilation is very fast.