5 ms·
Nim is new to me and I'm missing the "why" of it. From the website, I'm getting "we like Python but wanted to compile to native code and JavaScript". Is that fa
by CharlesW 8y ago
Nim is new to me and I'm missing the "why" of it. From the website, I'm getting "we like Python but wanted to compile to native code and JavaScript". Is that fair?
- dom96 8y agoThat's why I started using it. But Nim is much more than just this, it's more like "We like Python, but we also like static typing, efficient and dependency-free programs, super easy C/C++ FFI and metaprogramming. We also like to write all our software in the same programming language so we compile to JavaScript" :)
- wuschel 8y agoHow is the concurrency story with Nim. I know that this is a repeating question, just wondering how well it works and how safe it is. I am still eyeballing Pony-lang for it's design choices, but development seems to have slowed down there.
- dom96 8y agoConcurrency is achieved via async await. For parallelism each thread has its own GC so that makes things a lot safer, but sadly less efficient if your algorithm wants to share data between threads a lot (you can copy data between threads). You can also allocate shared memory but that's considered unsafe, this will hopefully be improved in the future. As for how well this all works, well, I recently implemented a high performance parallel HTTP server [1]. It's currently hosting the Nim Forum[2] and has been doing so for the past few months. Also it's proving very performant[3]. 1 - https://github.com/dom96/httpbeast https://github.com/dom96/httpbeast 2 - http://forum.nim-lang.org/ http://forum.nim-lang.org/ 3 - https://www.techempower.com/benchmarks/#section=test&runid=b9d29130-bd5a-4c2a-829d-352613d03cd2&hw=ph&test=plaintext https://www.techempower.com/benchmarks/#section=test&runid=b...
- wuschel 8y agoMany thanks for the detailed answer & ref.links.
- michaelsbradley 8y agoIt would be amazing if Pony Lang's[+] concurrency model could be realized in Nim, or if Nim could be extended as a language to optionally and cleanly support it. That's easier said than done, of course, since Pony's concurrency model is deeply wedded to its type system ("reference capabilities"). [+] https://www.ponylang.org/discover/#what-makes-pony-different https://www.ponylang.org/discover/#what-makes-pony-different
- spooneybarger 8y agoWe are still going strong in Pony land. There an ebb and flow to publicly seen development.
- mcintyre1994 8y agoThe writing style in your documentation is awesome! I haven't come across Pony before but it looks really nice, definitely going to give it a try. :)
- ilovecaching 8y agoThis is literally Go, save the fact that it compiles to WA instead of JS.
- jensvdh 8y agoGo is nowhere near as expressive/high-level as Nim or Python. The learning curve is significantly steeper.
- Fukkaudeku 8y agoExcept Nim doesn't make you copy/paste constantly.
- k__ 8y agoOr write code gens, haha
- kevin_thibedeau 8y ago> This is literally Go, save the fact that it compiles to WA instead of JS. Except Nim compiles to C and JS, no official WASM yet (though you can Emscriptenize the C output). Nim has macros, generics, inheritance, exceptions, deterministic GC, and more. Otherwise, yeah, exactly the same.
- ilovecaching 8y agoI was responding to the comment... the things they mentioned are available in Go. You're taking my comment out of context.
- TylerE 8y agoIt is literally un-go. Great support for meta programming and generics, and actual non-foot gun error handling
- qaq 8y agoIt's way nicer than Go (features and syntax) tooling and libs are not as developed obviously.
- jhasse 8y ago> super easy C/C++ FFI There's a HUGE difference between a C FFI and a C++ FFI. I doubt that Nim makes the latter easy (name mangling, exceptions, STL, ...).
- dom96 8y agoYou're very right to doubt me. But it does make it easy, Nim compiles to C/C++/Objective C (exceptions are mapped to C++ exceptions in C++ mode). This gives it the ability to wrap all C++ libraries, Nim takes advantage of this to make wrapping easy, here is a (very) barebones wrapper for sfml as an example: https://github.com/dom96/nim-in-action-code/blob/master/Chapter8/sfml/sfml.nim https://github.com/dom96/nim-in-action-code/blob/master/Chap...
- jhasse 8y agoThanks for the link, I stand corrected! :)
- nicoburns 8y agoThat seems about right. Another big benefit of this is performace. Nim is a lot faster than python.
- Symmetry 8y ago"A performant but garbage collected language with nice syntax that compiles to C. Plus hygienic macros."
- dvfjsdhgfv 8y agoMore or less - easy and intuitive like Python (or better), fast almost like C.
- mlthoughts2018 8y agoI would say Nim is far less intuitive than Python, and it’s better to only iteratively refactor occasional subsets of your code for heavy performance, and not presume you need all parts to have C-like speed (you don’t). This is why I think choosing to begin a project in Nim (or C++), is a form of drastic premature optimization, compared with Python and iterative usage of Cython.
- dvfjsdhgfv 8y ago> not presume you need all parts to have C-like speed (you don’t). Why not? If you can, if it's easy, not error-prone, you feel comfortable with it? Performance gain is something every user will appreciate.
- mlthoughts2018 8y agoI think that’s a false question. The point is that it’s actually not easy, not even in Nim (in fact, especially not in Nim). Writing safe and effective Python is easy. So then where do you go from there for the ~10% of the codebase where a user could conceivably ever care at all about performance enhancements? Wholesale switching to a different language is quite a drastic (premature) decision in such case, whereas Cython gives you the same (actually even better) facilities for type safety and detailed performance optimization, and offers it crucially on a case by case basis. I see a lot of cheering for Nim on this front. It makes me happy that some people enjoy Nim and like to use it. Cool! But it makes me sad to see the significantly wrong-headed discussions about it as a practical alternative to Python + Cython. It’s the opposite: choosing Nim is a wildly impractical way to get what Python + Cython does better.
- klibertp 8y agoThat's exactly what many said about Go. It was largely disproven since then. You can integrate Nim code into your Python codebase just as readily as any other compiled language, including Cython. Cython produces shared libraries conforming to Python C-API, and you can do the same in Nim. Having very similar, but different in surprising ways, language for extensions may be actually more of a problem then what developer familiarity might buy you. Instead of a mish-mash of two languages like Cython, using a proper language with its specific set of abstractions might be better, depending on a use case. I would like to know what you consider the "better facilities" for type safety and performance optimizations Cython has that Nim lacks?