Hacker News new | ask | show | jobs
by nooorofe 1570 days ago
I have mixed feeling about Nim. I've tried to learn it few years ago. It was "sold" like a Python replacement, it looks like a Python a bit, but when you write code it feels nothing like python at all.

Few things made me confused a bit

* With objects, when I need to use ref and when not.

    nim> type
    ....   Node = ref object
    ....      le, ri: Node
    ....      data: int
    ....
    ....
    nim> var n = Node(data: 9)
    nim> n.data
    9 == type int

    nim> type
    ....   NodeO = object
    ....     lw, ri: ref Node
    ....     data: int
    ....
    ....
    nim> var no = NodeO(data: 9)
    nim> no.data
    9 == type int
    nim>

* Two ways to import modules, specifically the C style import. I understand the need for it - applying macros and templates, but that makes Nim very different from big family of "no magic" languages. Ability to change syntax is very powerful and probably a big selling point of the language, but in the same time makes it hard to use Nim as casual language.

That time development/coding wasn't my full time job, Python was the "to go" option of automating some tasks, sometimes Java. In both cases there was no magic in the code - `module.something` easy to track to the origin.

Nim's orientation to standard library is nice. I've started checking Nim when I need a faster alternative for parsing big json and csv (compressed and flat) files. I both cases to was easy to archive, easier than Java (with Java I need to match version and bring dependencies) and the speed was fantastic.

Probably the main reason I haven't continued with Nim, was the company's antivirus at some point started to blocks nimble.exe execution on Windows. Another reason is switching to work into data engineering aria and there is no real need for fast compiled program. IDE support wasn't great too, VScode suggested a lot of irrelevant things, but I think it is kind of broken for any language now (out of box).

3 comments

The best way I can describe Nim is that it marries Python syntax with Modula-3 semantics. It's not just "static-typed, compiled Python", it's the modern inheritor of the entire Algol-Wirth superfamily of languages.

The syntactic differences between Modula-3 and Nim don't mean much in the long run. It's just the fourth phase of this particular superfamily's syntax. It's a bit of an oversimplification, but the preceding syntactic phases can be clumped into "Algol", "Pascal", and "Modula". All of them have significant syntactic differences between them but ultimately come from the same heritage, and I see "Nim" as just the next phase of that.

(to elaborate a bit: when Wirth evolved Algol 60 into Algol W, he only made small tweaks to the fundamental syntax. He then siginificantly overhauled it when he evolved Algol W into Pascal and then Pascal into Modula(-2). Borland/Embarcadero's evolutions of Pascal are of the same category as Algol W in that they made small tweaks while keeping the core syntax the same. Wirth's further languages Oberon and Oberon-2 all kept the same fundamental structure as Modula-2, despite various small syntactic tweaks, as did Modula-3 which wasn't by Wirth but had his blessing.)

Clearly you never tried converting existing Python to Nim. It's quick, feels natural and you get idiomatic Nim.

You can even use objects named "self" to ease the transition.

https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programm...

Nim never looked even close to Python for me, no matter how hard I squinted.
I think most confusions come from how divisive significant white space can be and Python being the most popular among that class of surface syntaxes. I am aware (and maybe you are, too) that there is a long list besides Nim: https://en.wikipedia.org/wiki/Off-side_rule, but this does not seem to be very common knowledge.
I think this is a big part of the aesthetic similarity. Without curly, or ordinary, brackets delimiting code blocks you get that nice clean look. Having used Python a lot for a period (and having made one toy app in Nim) I now find especially curly brackets visually noisy.