Nice! Nim has been great for us - fast to code in and even faster once compiled! We're using it for the backend and microservices at https://cxplanner.com and loving it.
Nim doesn't have sum types and pattern matching, which are an essential part of an expressive type system. It also appears to have `nil` be a valid value for most types by default?
Sum types are built-in [1] for formal parameters. `nil` is only for `ref|ptr` types. In much code you can just use stack allocated value types and there is neither GC concern nor nil concern, but there is also a mode to help: https://nim-lang.github.io/Nim/manual_experimental_strictnot...
What's the experience of writing web backend with Nim ? Did you use existing libraries / framework ? How good is the concurrency compared to something like Go ?
One of the reasons for choosing Nim was the ease of getting a production ready web backend. For the core part of managing the backend we are using existing Nim libraries [1], and they are easy to expand and work with. I cannot give you a comparison with Go since I haven't managed that large Go projects - but for Nim we are all into the async and threading. I think the channels within the threading is hardest part in Nim, but work is being done it.
Have a look at Jackson from https://boxyhq.com . Spin up one container and a couple of simple endpoints - voila, up and running. And a really cool team too!
We use it at www.cxplanner.com for a mix of micro/mono-services. Statically typed and good compile time combined with really fast code makes Nim perfect for us.
Could you elaborate why you chose Nim over other languages? The advantages need to be pretty strong when picking a niche language like this I would assume? Curious what the thought process was like.
While I work somewhere different, the choice basically came down to C/C++, or Nim (which compiles to either, and gives us the simplest binding story out there for handling external libraries and tools that our project requires).
Zig and Rust of course both exist, as does TinyGo, but Zig’s embedded story isn’t anywhere near complete yet, Rust is closer but it’s tendency to rewrite the embedded world from scratch (which is great for safety! Just bad for rapid firmware dev when we have a whole host of vendor drivers we need to use that aren’t supported in Rust’s embedded story yet) make them a pain
TinyGo was genuinely considered, but using a not-quite-normal compiler gave me the willies — which turned out to be a good choice as we have a lot of code sharing between the firmware and the server that it talks to (with a custom message protocol over TCP that’s encrypted — libsodium is great).
The long and the short of it for us was: do we want to write C/C++? Not really, it’s a pain to hire for and a pain to teach. And right now, Nim is a good slot in replacement/addition.
Early on in the project we wrote C libs to encapsulate some C driver code, and exposed that to Nim — and slowly migrated it all to Nim directly. Now it’s just ESP-IDF with Nim on top, no custom C code at all!
For me it was. Python was everything for me - but too slow. It was a pretty quick to convert software to Nim, and I have never looked back. You don't get the whole ecosystem from python, but you get fast code and easy syntax. We even often use Nim instead of small shell scripting.
[Author here] This post was quite a surprise to see here! Guess who got busy checking out his old repository ;) . This is a blog post from 2019 during my Nim journey, which has now resulted in our entire SaaS[0] running Nim. Nim[1] has evolved a lot since the post - current stable 1.6.4, blog post was for 0.19.2.
Thanks for writing this! Is there anything major people should look out for with the newer language version or any advice you would offer to something looking into writing a webpage in Nim today?
I am working on a small side project in Nim and saw your post and thought it was very well done.
I'm glad you liked it! We have been using Nim from 0.18.x to now (1.6.x) with a minimal work with breaking changes - so no warning signals from here.
My advice would be to use the current stable version since 2.0.0 is just around the corner :) ! We are quite happy with the performance and system load using jester[1] with httpbeast for routing, but there are a couple of alternatives in the package repository[2].
if anybody is interested in running it I'm more than happy to get them involved. I haven't had anybody approach me though.
For what it's worth, HttpBeast has seen some love from me lately (with some big optimisations). HTTP2 would require effectively a new project IMO so if someone wants to make it happen I'd love to advise where I can.
I just started using Nim this weekend, so this is some nice serindipity :) Do you have more recommendations for someone who has programmed for years but new to Nim to get up to speed? Specifically I'm looking for using it to do hosting and websockets, but anything would be helpful.
I don’t know about other web-guides. Nim’s official website is made with Nim and available at Github[0], but it has become at bit more complicated after they switched to Karax[1]. Jester’s tests gives a good view on the routing procedures[2].
The official tutorials[3] are pretty good, when you get the grab on how to ”decode” them. For web development with websockets and microservices I would suggest you to have a look at the Redis package[4], and @treeform’s Websocket[5] and JsonParsing-packet[6].