News for hackers. Stuff that matters.
Re:Porting a NES Emulator from Go to Nim by def- on Friday May 01, 2015 @03:26PM (#9473931)
Two of my old posts may answer that question:

- http://hookrace.net/blog/what-is-special-about-nim/

- http://hookrace.net/blog/what-makes-nim-practical/

Summary by benhoyt: 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
Re:Porting a NES Emulator from Go to Nim by jedi_stannis on Friday May 01, 2015 @03:58PM (#9474105)
Thanks, 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.

Re:Porting a NES Emulator from Go to Nim by dom96 on Friday May 01, 2015 @04:06PM (#9474155)
> * 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.

Re:Porting a NES Emulator from Go to Nim by TJSomething on Friday May 01, 2015 @08:19PM (#9475327)
For 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
Re:Porting a NES Emulator from Go to Nim by adrusi on Friday May 01, 2015 @09:45PM (#9475543)
Rust isn't working with Emscripten yet.
Re:Porting a NES Emulator from Go to Nim by TJSomething on Saturday May 02, 2015 @05:48AM (#9476488)
Re:Porting a NES Emulator from Go to Nim by Peaker on Friday May 01, 2015 @05:45PM (#9474726)
That'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

Re:Porting a NES Emulator from Go to Nim by def- on Friday May 01, 2015 @05:54PM (#9474770)
I'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/
Re:Porting a NES Emulator from Go to Nim by progman on Saturday May 02, 2015 @03:22AM (#9476215)
> 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.

Re:Porting a NES Emulator from Go to Nim by notsony on Friday May 01, 2015 @07:13PM (#9475098)
Thanks.

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?

Re:Porting a NES Emulator from Go to Nim by def- on Friday May 01, 2015 @07:40PM (#9475204)
C89, 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.