4 ms·
Two of my old posts may answer that question: - http://hookrace.net/blog/what-is-special-about-nim/ http://hookrace.net/blog/what-is-special-about-nim/ - http
by def- 11y ago
Two of my old posts may answer that question:
- http://hookrace.net/blog/what-is-special-about-nim/ http://hookrace.net/blog/what-is-special-about-nim/
- http://hookrace.net/blog/what-makes-nim-practical/ http://hookrace.net/blog/what-makes-nim-practical/
Summary by benhoyt: https://news.ycombinator.com/item?id=8822918 https://news.ycombinator.com/item?id=8822918
* Run regular code at compile time
* Extend the language (AST templates and macros);
this can be used to add a form of list comprehensions to the language!
* Add your own optimizations to the compiler!
* Bind (easily) to your favorite C functions and libraries
* Control when and for how long the garbage collector runs
* Type safe sets and arrays of enums; this was cool:
"Internally the set works as an efficient bitvector."
* Unified Call Syntax, so mystr.len() is equivalent to len(mystr)
* Good performance -- not placing too much emphasis on this,
but it's faster than C++ in his benchmark
* Compile to JavaScript
- jedi_stannis 11y agoThanks, that first post is really interesting. Two things stand out to me: * Run regular code at run time - does this just error if you try to use const on something that depends on a runtime value? * Add your own optimizations to the compiler - isn't this very dangerous, especially if optimizations from various sources of code get combined? Even if your optimizations are valid (which there seems to be no guarantee of), computer math is notorious for being different from real math. People unaware of the nuances of integers rolling over or floating point seem like they could easily shoot themselves in the foot here.
- dom96 11y ago> * Run regular code at run time - does this just error if you try to use const on something that depends on a runtime value? Yep. For example `const foo = stdin.readLine()` would result in "Error: cannot evaluate at compile time: stdin". As for your second point. I haven't used this feature personally but I have heard that the compiler will tell you exactly where these optimisations are applied. You can also disable these optimisations very easily during compilation.
- deleted 11y ago[deleted]
- Peaker 11y agoThat's a great list, but the question was about stuff that's not in Haskell (among others) so a few nitpicks: * Haskell can run regular code at compile-time (But it is slow, using ghci/TH) * Haskell can add optimizations (rewrite rules and plugins). I think Haskell innovated rewrite rules and Nim probably was inspired by that? * Binding to C easily is also a Haskell feature * Type safe sets and arrays of enums: Is this not just a library? Haskell sets and arrays of enums are type-safe by default? * Unified call syntax is true of Haskell too * Compile to Javascript -- Haskell can do that too
- def- 11y agoI'm a big Haskell fan (it was my favorite language before discovering Nim), but here's my personal list of Nim advantages over Haskell: - Predictable performance (lazy evaluation is problematic) - Easy to achieve high performance - Easier to read, even for non-specialists - I'm much more productive in it - Multi-paradigm: Nim is mostly imperative, but OO and functional can be mixed as well. http://hookrace.net/blog/conclusion-on-nim/ http://hookrace.net/blog/conclusion-on-nim/
- progman 11y ago> I'm much more productive in it That's the point! I know many languages and Nim is by far the most productive one. It's like coding in Python with the assurance that the compiler will catch many errors that would cause runtime errors in Python. That assurance makes coding in Nim faster than in Python because I don't have to think so much about avoiding runtime errors.
- notsony 11y agoThanks. Does Nim compile to C99 ? If someone were to ask what's wrong with Nim, what would you say are the things that need to be fixed?
- def- 11y agoC89, so it's also compatible to Microsoft's vcc. There are quite some compiler bugs remaining in Nim and the standard library could be improved.
- TJSomething 11y agoFor reference, compared with Rust: * Yes, with compiler plugins * Yes, with macros * Maybe. I think that you could use a compiler plugin to do arbitrary transformations on all the code in a module, but I haven't seen an implementation. * Yes * What garbage collector? * Yep * Kind of. Any method can be invoked as a function with the <type>::func(val, args...) syntax, but the opposite's not true. * Check * Yep, via Emscripten
- adrusi 11y agoRust isn't working with Emscripten yet.
- TJSomething 11y agoThis made it sound like it was: https://www.reddit.com/r/rust/comments/2yfsi9/rust_to_js_with_emscripten/ https://www.reddit.com/r/rust/comments/2yfsi9/rust_to_js_wit...