← Back to context

Comment by alberth

2 years ago

Q: what made you choose Nim over Swift?

(since they seem very similar at this point, yet Swift is more battle tested)

I did consider Swift for a brief moment, but was put off by the fact that targeting bare-metal was almost non-existent. It was more work than I would like to put into bootstrapping the dev environment.

  • What made you use nim in the first place vs any other lang?

    • I went over this in other comments, but basically the language appeals to me since:

      - it's close to Python in syntax (less noise, more readable)

      - has no garbage collector by default (it uses ARC)

      - has great C interop

      - can be optimized through the C backend compiler

      - can target bare-metal with minimal effort

      - supports inline assembly

      - has great template/macro system (I do use templates, but I haven't had the need for macros yet)

      There's probably other reasons, but those are the ones I could think of now. As for why not other languages, I think the only other languages suitable for this kind of work are: C, C++, Rust, and Zig. Here's my take on each:

      - C: The mother of all system languages, but outdated with lots of UB gotchas

      - C++: I don't like/need OOP, so why pay the prices of C++ complexity and manual memory management

      - Rust: I find the language too complicated for my taste. I know it's subjective, but it just doesn't feel right for me. Also writing a kernel involves a lot of unsafe code anyway.

      - Zig: I tried Zig and also found its syntax to be a bit too noisy. Also having to worry about allocators in most of the code distracts from the core logic I'm trying to focus on.

      5 replies →

  • Q1: Overall, are you happy with your choice of using Nim?

    Q2: What would you do different? (and what unexpected positives did you find)?

    • > Overall, are you happy with your choice of using Nim?

      Yes. It's a pleasant language to work with.

      > What would you do different? (and what unexpected positives did you find)?

      A couple of things I think need improvements are: (1) better IDE support (especially for JetBrains IDEs), and (2) better support for true sum types and pattern matching[0].

      As for unexpected positives, I found that the standard library covers a lot of functionality that I rarely (or ever) need a 3rd party package. Maybe that's because I'm not doing anything exotic.

      [0] https://github.com/nim-lang/RFCs/issues/548, https://github.com/nim-lang/RFCs/issues/525