
Nim – Python-like statically-typed compiled language - tomrod
https://nim-lang.org/
======
Grimm1
I'm stuck in this cycle with langs like this. I want to use Nim I want to use
Crystal they to me represent real tangible improvements over the languages
they were based on but run into the issue of ecosystem and adoption every-
time.

I know it's chicken or the egg but I have real problems choosing these
languages when they just aren't as battle hardened or package wise versatile
as say python or ruby when making decisions for my own tech stacks in a
startup or for other companies I have or will work for.

~~~
Naac
Another problem I've found for me with Nim and Crystal is the lack of editor
support compared to other statically typed languages like Java and C++.

Arguably a really nice benefit of these languages is the inline error
highlighting, which speeds up development. I've found for Nim and Crystal I
have to run the compiler in the terminal, look where the errors were, and then
find those lines in my editor.

LSP support is minimal ( especially when a language is starting out ). My
ideal editor for Nim would be Pycharm-like ( open source edition ) with an LSP
backend.

~~~
aidenn0
If the compiler is fast enough, you don't need LSP support; many editors can
be configured to run any sort of compiler or linter for doing error checking,
and can be configured to do so when saving or as you edit &c.

Vim, for example, has a plugin called "syntastic" that is kind of a meta-
plugin aggregating lots of these, and indeed it seems to have support for nim
error checking.

LSP _is_ a nice step forward, but people had error highlighting for decades
before it was invented.

[edit]

Doesn't change anything above, but someone pointed me at ALE which is a newer
tool that can run lint engines asynchronously (using interfaces that didn't
exist when syntastic was created). For vim specifically that may be a better
tool, but I haven't tried it yet.

~~~
Naac
>> and can be configured to do so when saving or as you edit

That's true, but being able to quickly click on the line that has the error
and have your editor navigate to the file automatically is slightly more
painful to setup, and is bespoke for whatever tool you are using.

My point was just that a tight integration between language and IDE/editor
makes the overall language experience much nicer. For example:

Racket/Dr. Racket Python/Pycharm Java/Intellij Emacs lisp/Emacs

~~~
aidenn0
>> That's true, but being able to quickly click on the line that has the error
and have your editor navigate to the file automatically is slightly more
painful to setup, and is bespoke for whatever tool you are using.

In the event that the tool doesn't output in one of the common formats, it's
usually just a regex; again I had this in Vim for several different languages
back in the 90s.

>> My point was just that a tight integration between language and IDE/editor
makes the overall language experience much nicer.

I agree (happy SLIME user here), but it often seems like I'm in the minority.
I've literally never met someone in person besides me that uses pycharm, and
you are about the 3rd person online I've seen mention it in a favorable light.

------
FRidh
For a while now I've been looking at using Nim, and this weekend I did my
first project with it: a tool for creating binary wrappers. In Nixpkgs we
often create wrappers, but those have thus far been shell scripts causing
trouble at times on e.g. OSX.
[https://github.com/NixOS/nixpkgs/pull/95569](https://github.com/NixOS/nixpkgs/pull/95569)

I found it easy to get up to speed and do something useful with it. The
language is also in my opinion very readable. The documentation could use some
more (larger) examples though.

For this wrappers tool I needed a front-end for which I wanted to create an
interface with argparse. Unfortunately the standard library lacks an
implementation, and third-party packages did not deliver what I needed. In the
end I wrote that part in Python still.

The biggest issue I currently find is the lack of a lock file format for its
package manager. It's being developed, and as soon as its there I intend to
implement support for it in Nixpkgs. [https://github.com/nim-
lang/nimble/issues/127](https://github.com/nim-lang/nimble/issues/127).

The compiler gives very useful output and is fast as well, and the generated
binaries are small. I like this language!

~~~
disruptek
Nimph has had lockfiles for months.

[https://github.com/disruptek/nimph](https://github.com/disruptek/nimph)

~~~
FRidh
Thanks! I was only aware of Nimble. I'll have a look at it.

One thing I noticed right away that it seems to be lacking (judging from the
`nimph.json` assuming that is the lock file) are checksums over the data or
hashes of revisions the references correspond to. References such as tags are
mutable, and thus hashes are needed to validate them. See e.g. the discussion
over at
[https://github.com/NixOS/nix/pull/3216](https://github.com/NixOS/nix/pull/3216).

~~~
disruptek
Please open an issue if you want to change the semantics; it's trivial to use
the hash instead.

~~~
FRidh
Done!
[https://github.com/disruptek/nimph/issues/138](https://github.com/disruptek/nimph/issues/138)

------
darthrupert
Nim is an amazing language that suffers from a lack of momentum and hype.
Technically, there’s little reason why it shouldn’t be a good choice for many
programming problems.

Reality doesn’t work like that, of course. Hype is important, and not just
because that will mean more libraries. Hype motivates people to do things they
wouldn’t have otherwise done at all. Rust demonstrates this well.

~~~
planetis
Is it hype, or controversy then? :P Latest development in Nim is reference
counting is planned to replace the GC [https://forum.nim-
lang.org/t/6549](https://forum.nim-lang.org/t/6549). However this is done in a
non-breaking way and their isn't much criticism, except the development effort
and the countless bugs that were introduced. Hopefully this will lead to
better multi threading which is a shortcoming of the language, thus opening
new fields.

------
NateEag
Shouldn't the title be "with static typing?"

Python has strong types. It's just that it checks them at runtime, not before.

If you don't use MyPy or similar, anyway.

~~~
phoe-krk
It should. It's the same as with Common Lisp, which is strongly dynamically
typed. Strongly, because it is impossible to confuse a given value's type via
some sort of implicit casting; dynamically, since types are checked at
runtime.

~~~
guenthert
I think in modern parlance Common Lisp uses a gradually typed system, at least
some implementations.

Common Lisp allows for type inference and some compilers use that to various
degree, as well as to declare a type of a given symbol (or the signature of a
function). Depending on compiler and optimization settings, that information
is then used to generate optimized code, much like a compiler for a (weakly)
statically typed language would or detect mismatches. SBCL is probably one of
the most advanced Common Lisp compilers in this regard.

~~~
phoe-krk
Sure, that's the case in SBCL - the type inference engine in it is rather
advanced; with type declarations here and there (which are capable of turning
Common Lisp into a _weakly statically typed_ language), they are capable of
type-optimizing a lot of code. It also generates warnings in case type
mismatches are detected at compile-time.

------
cpach
If anyone wants to know how Nim can be used in practice, you might want to
take a peek at the NimSvg library. It’s a DSL for generating SVG files and GIF
animations and to me it looks quite compelling.

[https://github.com/bluenote10/NimSvg](https://github.com/bluenote10/NimSvg)

~~~
Igelau
The contents of the examples dir are pretty slick. I've never even touched Nim
but these make more sense to my brain than svg. It says DSL but reads more
like an improved alternate syntax. Thanks for sharing this and there goes my
afternoon :)

------
fwsgonzo
It has a RISC-V backend in case anyone was curious. And it can compile down to
C/C++! I have a C/C++ runtime environment that is _very_ unique, and I don't
even know how to begin explaining it, but the fact that I potentially don't
have to build shims on top of it is just very interesting to me. I'm going to
tinker with it.

~~~
elcritch
Exactly, llvm doesn’t support many unique backends. Be sure to use the ARC
garbage collector! Certainly checkout c2nim.

------
open-source-ux
I like Nim. It's almost a year since version 1.00 of the language was released
(in September 2019), but I wonder how the language has fared since then. Has
usage grown since that key milestone? Gaining 'mindshare' among developers is
obviously important but also difficult. Of course, supporting libraries are
also important in encouraging adoption, but that is just one piece of the
picture.

I see a pattern of sorts for some new(ish) languages: without a prominent,
well-known sponsor, the language might struggle to gain attention among
developers. I wonder what will be the fate of other languages without generous
sponsors as they head to their version 1.00 e.g. Crystal or Zig?

Julia is doing relatively well without a big main sponsor - interest seems to
be growing in the language.

Rust and Go are two languages that have benefited hugely from support from
Mozilla (Rust) and Google (Go).

But back to Nim. Who's using Nim? What are you using it for and how are you
finding it?

~~~
DennisP
One of the near-production clients for Ethereum's proof-of-stake blockchain is
written in Nim.

~~~
exdsq
Didn’t know that! Any good articles on why the chose Nim?

~~~
planetis
It's called Nimbus, since it wasn't mentioned, here's their website:
[https://nimbus.team/](https://nimbus.team/) and why Nim is explained here:
[https://our.status.im/status-partners-with-the-team-
behind-t...](https://our.status.im/status-partners-with-the-team-behind-the-
programming-language-nim/)

~~~
DennisP
Ooh, I didn't realize Status (the company behind Nimbus) is financially
supporting the Nim team now.

~~~
exdsq
The amount of PL support from crypto is insane!

------
thom
Loads of interesting stuff available in the talks from NimConf 2020:

[https://www.youtube.com/playlist?list=PLxLdEZg8DRwTIEzUpfaIc...](https://www.youtube.com/playlist?list=PLxLdEZg8DRwTIEzUpfaIcBqhsj09mLWHx)

------
pbsds
Worth mentioning is NimScript, a subset of nim which can be interpreted, and
embedded like lua: [https://nim-lang.org/docs/nims.html](https://nim-
lang.org/docs/nims.html)

If for some reason the nim compiler starts becoming slow, then this could also
drastically speed up development

~~~
gw
Yeah it really is a hidden gem. You can use it as a bash replacement, and with
the new compiler API you can embed the entire interpreter in your program. My
only complaint is that the interpreter aborts the process when the nimscript
code has an error, so you can't really use it for hot code reloading right
now. I hope they fix that eventually.

~~~
ilaksh
There is really no way to trap it? Maybe fork the NimScript stuff to give the
option to try to hang around?

~~~
gw
I did manage to fork it and prevent it from aborting, but i don't want to
maintain it forever. I tracked it down to this function:

[https://github.com/nim-
lang/Nim/blob/cd28fe2ef7a204721efa720...](https://github.com/nim-
lang/Nim/blob/cd28fe2ef7a204721efa72082c9f65f8d13bcfb3/compiler/msgs.nim#L408-L421)

It's calling `quit` which cannot be caught in a try statement.

------
pansa2
Other than having superficially similar syntax, is Nim really Python-like?

Also, Nim seems to be targeting a different niche from Python. As Nim is
statically-typed and AOT-compiled, its closest competitor is probably Go. The
difference is that Go deliberately tries to be a simple language, while Nim is
much more complex.

~~~
nafey
In what ways will you say Go is simpler than Nim? I did try out Go but found
it a bit difficult. Maybe would need to spend some more time.

~~~
auxym
Nim has more features like generics and metaprogramming via templates and
macros. You don't have to use them, but if you read someone else's code that
uses it, you might have trouble understanding it, which probably doesn't
happen with Go.

~~~
mesaframe
That's a poor excuse. You cannot do everything in just few things and would
want things that help you do more, or create abstractions easily. That will
require additional syntax. In Go absence of generics will make you write more
code that will increase code length unnecessarily.

~~~
auxym
FWIW, my answer was not meant to be trashing nim. I like and use nim.

And to be perfectly transparent, I know relatively little of Go. My impression
is that nim has more features in general, which could be considered to make it
more complex. That can be a good and/or bad thing depending on perspective.

------
airocker
Has there ever been an analysis of what percentage of total bugs can be
prevented by static typing? I moved from static to dynamic languages and in my
experience static languages dont provide too much upside but then I have
always worked in smaller teams.

~~~
pansa2
[https://softwareengineering.stackexchange.com/questions/1003...](https://softwareengineering.stackexchange.com/questions/10032/dynamically-
vs-statically-typed-languages-studies)

~~~
airocker
This is good read. In a nutshell, Would it be fair to say start with Python
and move to Java when team grows to 50+?

------
xrisk
My main gripe with Nim is that documentation (even for the standard library!)
is in absolute shambles. Not to mention the lack of an ecosystem.

I think that authors of Nim libraries get so tied up in their superiority over
having types and being compiled that they forget that most devs don’t really
care about these things _on their own_. It’s only when these things are
combined with good documentation and tooling (see Rust for example) that they
become useful.

~~~
planetis
Hey that's unfair :(. Nim's dev team had done user surveys for three years now
[https://nim-lang.org/blog/2020/02/18/community-survey-result...](https://nim-
lang.org/blog/2020/02/18/community-survey-results-2019.html) and improved the
docs significantly. Rust has excellent docs but also a larger dev-team.

------
sergiotapia
When I started learning Nim I noticed the docs and even the getting started
tutorial just threw the kitchen sink at you, it totally overwhelemed me.

So here's a simple project I wrote that's easier to understand. I work on this
every couple of weeks on Saturdays.

[https://github.com/sergiotapia/torrentinim](https://github.com/sergiotapia/torrentinim)

For example: parsing html
[https://github.com/sergiotapia/torrentinim/blob/master/src/c...](https://github.com/sergiotapia/torrentinim/blob/master/src/crawlers/leetx.nim)

I wish the Nim team worked on an easier onboarding process to the language.
The documentation is in depth but it just throws everything it has at you all
at once with no progression.

~~~
open-source-ux
Yes, if you search on the web or YouTube there are surprisingly few tutorials
for Nim. Compare that to Julia which has a couple of books published, and also
has courses available on Udemy, LinkedIn Learning and YouTube. Some of these
Julia courses are pre-1.0 Julia while Nim doesn't even have a course post 1.0
release which is a shame. Let's hope that changes soon - more learning
resources can only help interest in Nim grow.

~~~
ilaksh
Nim has a book. The one Dom made. Nim in Action or whatever.

------
manishsharan
I debated whether to start learning Rust vs Nim... Rust does seem to have more
libraries to get stuff done.

~~~
Waterluvian
I find that with JavaScript, Rust, and Python, my tool belt is pretty well
equipped these days.

~~~
adamnemecek
Also consider julia.

~~~
collyw
I would say that you need to present a case where Julia would be needed. I do
Python and Javascript it covers most stuff that isn't low level. Rust does
that, so what is the need for Julia?

~~~
adamnemecek
Numerics and ml.

~~~
Majestic121
Python handles that pretty well. Maybe Julia does it marginally better, but I
don't think it's worth learning a whole new language for this unless your day
job is only 'Numerics and ml'

~~~
sesuximo
This is only true because other people wrote the hot parts in other languages
and exposed a python library. That’s fine but isn’t really fair in a battle of
languages

~~~
swsieber
I think it's fair. We're not talking about that intrinsic language qualities,
we're talking about what you can do. Or that's my take anyway. That's what I
think of comparing when the lead line for the whole conversation is "tool
belt".

~~~
adamnemecek
The two are related. If i can't write fast code in the langauge itself but
have to resort to another langauge, then that's very much a "what can you do
with it" problem.

~~~
swsieber
And I'm saying doing stuff with numpy counts as doing stuff in python. Just
because numpy is mostly implemented in c doesn't prevent me from writing ML in
python.

~~~
adamnemecek
I understood. What if you need a feature that is not implemented in C and
exposed? You need to write C.

~~~
swsieber
I agree with you there. I just haven't hit that need yet. I suspect most
people don't.

~~~
dunefox
I suspect many people do but just don't (yet) realise that there's an
alternative.

------
planetis
NimConf 2020 [1] also took place just recently, was great success.

[1]: [https://conf.nim-lang.org/](https://conf.nim-lang.org/)

Hacker news coverage:
[https://news.ycombinator.com/item?id=23585006](https://news.ycombinator.com/item?id=23585006)

------
fiatjaf
RosettaCode comparison between Rust and Nim:
[https://rosetta.alhur.es/compare/Rust/Nim/#](https://rosetta.alhur.es/compare/Rust/Nim/#)

------
efgha4351
Another language, which is a possible alternative to Nim, is Slider, available
at [http://mrsename.blogspot.com/](http://mrsename.blogspot.com/)

------
mlthoughts2018
If you like Nim but you are looking for something that can be practical for
corporate use cases where adopting a new language with a young ecosystem is
extremely hard, consider Cython.

Cython is a superset of Python that allows super easily compiling custom
Python extension modules directly in C or C++, interoperates easily with
Python packaging, and is very battle tested.

It allows you to “just write for loops in native Python” and get the
statically typed & compiled optimizations you’d get in C or C++ for free. It
also supports fused types for multiple dispatch of compiled functions.

I’ve used it in production workflows at many companies. It’s very easy to use.

The best part is that you can apply it gradually, only bothering to implement
small sections of code as Cython extension modules when there’s real proof
from a profiler that the code is a bottleneck for reasons addressable with
static typing. You don’t have to live with the huge premature optimization
baked in as a premise to languages that enforce this for all code. “Static
typing when _you_ need it.”

[https://cython.org/](https://cython.org/)

~~~
montebicyclelo
Cython is excellent. The Numba [1] and NumPy combination is also strong.

> Numba translates Python functions to optimized machine code at runtime using
> the industry-standard LLVM compiler library.

[1] [http://numba.pydata.org/](http://numba.pydata.org/)

------
planetis
A very informative interview with Araq (the creator of Nim) was posted a few
months ago:
[https://www.youtube.com/watch?v=-9SGIB946lw](https://www.youtube.com/watch?v=-9SGIB946lw)
It's mostly up-to-date.

------
Aardappel
Another statically typed language that "looks like Python":
[http://strlen.com/lobster/](http://strlen.com/lobster/)

------
pansa2
What concurrency support does Nim have?

Anything like coroutines, async-await etc? Or just OS threads?

~~~
elcritch
All of the above. Though the coroutine library looks out of date. Most network
libraries use async. Threads are possible, but weave looks promising:
[https://github.com/mratsim/weave](https://github.com/mratsim/weave)

------
xiaodai
I am just surprised this hasn't been on HN before.

~~~
emit_time
Nim has been mentioned on here many times.

~~~
xiaodai
then why is this on the front page?

~~~
gameswithgo
we ran out of new things

~~~
tomrod
To be fair, I discovered it on exercism.io and am thoroughly enjoying learning
it.

~~~
mroche
What are your thoughts on exercism, if you don’t mind me asking? I personally
liked it when I dove into Go and Rust and was searching for practice material.

~~~
tomrod
Absolutely love it to learn syntax. Work through the logic once in language of
choice, then apply to several languages to learn its syntax. If there is time,
go through code review to get antipatterns worked out. Also fun to mentor, I
would reckon.

------
zeeone
Nim is just right down ugly and borrowed the worst from Pascal and Python. The
multi-paradigm concept is a mess. Tried it a couple of years ago and moved on
to better, more simple tools.

~~~
ilaksh
Lol. The diversity of worldviews never ceases to amaze me.

What might those "pretty" "simpler tools" be? Perl? Heh.

