9 ms·
I learned Nim last year by rewriting some of the core Arduino functionality in C, and then wrapping them in Nim. (I also wanted to better learn C and better und
by wiremine 5y ago
I learned Nim last year by rewriting some of the core Arduino functionality in C, and then wrapping them in Nim. (I also wanted to better learn C and better understand how Arduino's internals work, thus the convoluted approach)
A few observations:
* The community was very helpful and responsive. I identified a bug in compiling Nim to bare metal C, and it was fixed in 24 hours.
* The C/Nim bindings were a breeze to use, even for a relatively novice C programmer like myself.
* The language is fairly sparse, in a good way. It feels a bit like Go in that regard, but with better metaprogramming support.
* I personally like meaningful, Python-style whitespace, but I could see how that could be a turnoff. But I'd hope people can look beyond that and give the language a try.
* I could _actually_ use Nim to write code for an Arduino Uno, so the project was a success. The firmware sizes weren't that bad, either, which was my biggest concern. Nim's memory management is very flexible, and the ARC system seemed to work great without the need for GC. [1]
[1] https://nim-lang.org/blog/2020/10/15/introduction-to-arc-orc-in-nim.html https://nim-lang.org/blog/2020/10/15/introduction-to-arc-orc...
- PMunch 5y agoOh it definitely can run on those devices! I wrote my own keyboard firmware from scratch in Nim, and the firmware sizes are vanishingly small compared to even simple "hello world" level stuff in Arduino. I did a talk on it for NimConf2021: https://www.youtube.com/watch?v=dcHEhO4J29U https://www.youtube.com/watch?v=dcHEhO4J29U
- wiremine 5y agoThis is great! I've wondered if Nim could be the foundation for a sort of "next-generation" Arduino. It's easy to learn, compiles to small binaries, and can wrap a ton of existing C code. My experiments taught me wrapping Arduino from scratch, while possible, might not be ideal. There's some cruft in that code base, and the abstractions could use some updating.
- dom96 5y agoThere is definitely room for this, it just needs somebody passionate enough to write a nice Arduino/embedded framework and document/promote it well.
- elcritch 5y agoYes, yes Nim could be. Actually I’ve been working on that idea for a while now. I’ve been working on getting an Embedded Nim project going on GitHub. Come stop by! Also some discussions on Nim forum: https://forum.nim-lang.org/t/7731#49050 https://forum.nim-lang.org/t/7731#49050 PS I’m wrapping Zephyr as a basis, but working on better Nim abstractions on top.
- mumblemumble 5y agoI have decided that meaningful whitespace is an anachronism. 20 years ago, I liked it a lot. Today, after the invention and normalization of opinionated autoformatters, it means that the autoformatter can't figure out for me how my code should be indented. Which means that, assuming I am using an autoformatter, it creates one more thing that I have to do manually, because the editor can't accurately do it for me. And, since the whitespace is significant, it ends up being one more potential source of bugs. I also don't love love love that (at least with the keys I know well) significant whitespace is more awkward to edit with vanilla vim than curly braces and parens are.
- boardwaalk 5y agoSome counterpoints: Your auto formatter can’t figure out where you missed braces either. Missing brackets in languages where they are optional for single statements (C) has been a source of serious bugs. Also, in Vim, indenting/dedenting a block is just highlighting the lines and using > or <.
- GoblinSlayer 5y agoA botched merge conflict resolution can repeat a block statement just fine, it will have the same effect. And repeating a statement inside a block isn't necessarily better.
- bobbylarrybobby 5y agoPractically speaking, it’s almost impossible to miss braces. If you’re copying and pasting, you can place your cursor anywhere inside the desired pair of braces, paste, and the autoformatter will figure it out. Ideally an autoformatter would also add braces around a one-line if statement as well.
- je42 5y agoit is very possible... I often paste parts of some code into a lambda and missing a brace here and there.
- 5y ago