News for hackers. Stuff that matters.
Re:Nim 1.0 by peteforde on Tuesday September 24, 2019 @03:09AM (#21057335)
Congrats to the Nim team.

One thing that is frustrating for anyone hearing about Nim for the first time is that it's really hard to look at what appears to be yet another slightly different take on Rust or Go and intuitively understand why it exists.

There is absolutely a grid that can be populated: who started this, is it corporately affiliated, what languages is it similar to, what is the motivation of its creators, what is the philosophy driving its design, is it intended to be an eventual competitor or replacement for languages XYZ, where does it sit on the spectrum between raw assembly and MS Access, is it intended to be a "systems language" eg can you write a kernel or device driver using it, does it require a VM, is there corporate support available, how established is the developer community, are there books and courses, does it have garbage collection, is it a compiled language, is it a strongly typed language, what are the three perfect use cases, how stable is the API, what's the package management story, does it have a reasonable standard library, is there editor support for color coding and linting, what's the job market look like, is the documentation well-written, and most importantly, if we all got in the same room, would I want to hang out with the people excited about this language?

The cost of learning yet another language vs actually spending your finite spare time building something (or with your loved ones, or reading, or sleeping, or making art) is insanely huge.

Re:Nim 1.0 by arc776 on Tuesday September 24, 2019 @06:07AM (#21058248)
I would say metaprogramming (and maybe the excellent FFI) is the huge stand-out feature for Nim.

However whilst you can compare all these languages and find a particular niche or set of features that sell them, Nim is just good at pretty much everything.

I know that sounds pretty bombastic, but you can practically pick any task and know that Nim will let you get there rapidly and performantly. That's it's ultimate strength. It's just so productive! It puts the fun back into a day job.

It's as easy to develop in as Python (great type inferrence and strong, static typing), but fast as well written C, yet (AST based) metaprogramming allows it to be higher level than even Python.

On top of low developer friction, it outputs stand-alone executables for effortless distribution. It's my first choice for scripting, for CRUD work, web stuff, game development, and embedded coding.

Doesn't hurt that it can compile to c, c++ and javascript so you can write your backend and frontend in the same language.

Also since the FFI is so great, you can effortlessly use the entire library ecosystem of C and C++.

Of course, it's not perfect, but for me it's getting pretty close.

Re:Nim 1.0 by 6gvONxR4sf7o on Tuesday September 24, 2019 @11:35AM (#21061278)
> (AST based) metaprogramming allows it to be higher level than even Python.

I'm skeptical of this claim. Python's ast tools let you do just about anything you'd want to, and just about anything you'd never want to do as well.

Re:Nim 1.0 by nunchuckninja on Tuesday September 24, 2019 @12:05PM (#21061619)
Scala and rust both compile to JS too I think.
Re:Nim 1.0 by dom96 on Tuesday September 24, 2019 @03:05PM (#21063500)
Do they have first-party JS backends though? I think that's what sets Nim apart, the Nim compiler includes the JS backend which means the JS backend is always up to date with the latest Nim developments.
Re:Nim 1.0 by nunchuckninja on Wednesday September 25, 2019 @01:41AM (#21067961)
Sorry I was wrong it's asm.js for rust. Scala does have an amazing first party backend that I love using
Re:Nim 1.0 by nickitolas on Wednesday September 25, 2019 @07:32AM (#21069673)
I didn't know there was an asm.js backend for rust. I do know there are emscripten and llvm backends for webassembly.
Re:Nim 1.0 by steveklabnik on Tuesday September 24, 2019 @01:29PM (#21062536)
Rust sorta can, but prefers to be compiled to WebAssembly.
Re:Nim 1.0 by qwerty456127 on Tuesday September 24, 2019 @12:01PM (#21061574)
This sounds like everybody should be using Nim. Why do they still use Python, C# etc and why is Nim still so rare then?
Re:Nim 1.0 by dixego on Tuesday September 24, 2019 @01:58PM (#21062895)
Having had it's 1.0 release a day ago might have something to do with it.
Re:Nim 1.0 by greyfade on Tuesday September 24, 2019 @05:02PM (#21064590)
Python has been around since, what, 1994? C# goes back to '99 or '00 or something like that.

Nim goes back to maybe 2008 and only hit 1.0 today.

Re:Nim 1.0 by marble-drink on Tuesday September 24, 2019 @07:38AM (#21058846)
Talk of metaprogramming intrigues me. I'd like to hear what a Lisp user makes of it because I find non-Lisp users are usually amazed by any metaprogramming at all and can't be as critical about it.
Re:Nim 1.0 by PMunch on Tuesday September 24, 2019 @09:19AM (#21059805)
Not a Lisp user, but a heavy Nim macro user. Nim macros are AST based, which means that after the parser part of the compiler have read the code and created a tree structure of it your macro is called on this tree. Then you can modify this tree to your hearts desire and return a new tree that the Nim compiler will splice back into the main tree before continuing. This means that you rewrite pretty much anything into pretty much anything else. You also have access to reading files on the machine, or doing pretty much anything else that Nim offers. For examples of what you can do with it you can have a look at my macro to create GUIs: https://peterme.net/cross-platform-guis-and-nim-macros.html, my article on how I use macros to create more read- and maintainable code: https://peterme.net/metaprogramming-and-read-and-maintainabi... or perhaps see how Protobuf was written as a string parsing macro which reads a Protobuf specification and spits out all the types and procedures you need to use it: https://github.com/PMunch/protobuf-nim
Re:Nim 1.0 by lispm on Wednesday September 25, 2019 @06:34AM (#21069390)
> which means that after the parser part of the compiler

Lisp works slightly different. The macro form is an expression (a list) with the macro operator as the first element. The next elements in the expression can be anything as data.

Re:Nim 1.0 by thsealienbstrds on Wednesday September 25, 2019 @05:56AM (#21069239)
Disclaimer: I only did a hobby project in Lisp once. But I did use some of the macro functionality.

Judging by some of the comments here, it seems like the macro system has a similar approach as Lisp's macro system, which is also AST-based. Something I don't see here is macros that generate other macros, but the question is how much you really want that anyway (when I did that, I thought the syntax was horribly complicated because of all the quoting). I know Lisp also has reader macros (they run before the parser) that allow you to effectively change the language syntax, but I didn't use those.

Re:Nim 1.0 by arc776 on Wednesday September 25, 2019 @07:18AM (#21069609)
> Something I don't see here is macros that generate other macros, but the question is how much you really want that anyway

You can do that in Nim in a readable way.

  import macros
  macro genMacro(name: untyped): untyped =
    result = quote do:
      macro `name`: untyped =
        result = quote do:
          echo "Foo"

  genMacro(bar)
  bar # Generate and perform the echo
Surprisingly I've actually used this kind of thing!

In one of my projects I use a macro to parse a set of types for fields and generate constructor macros for them.

The generated constructor macro passes through the parameters it's given to the default built-in constructor but does some setup before.

The final generated code is a normal built-in construction without proc calling yet with special fields initialised automatically.

Re:Nim 1.0 by thsealienbstrds on Wednesday September 25, 2019 @09:03AM (#21070332)
> In one of my projects I use a macro to parse a set of types for fields and generate constructor macros for them.

Funny, I did a similar thing! :)

Re:Nim 1.0 by lispm on Wednesday September 25, 2019 @06:25AM (#21069358)
Lisp macros are not based on an AST. The macro forms in Lisp need to be valid s-expressions and begin with a macro operator. That's it.
Re:Nim 1.0 by thsealienbstrds on Wednesday September 25, 2019 @11:37AM (#21071779)
Still, isn't it AST-based in the sense that the input of a Lisp macro is effectively a parsed syntax tree, just as in Nim?
Re:Nim 1.0 by lispm on Wednesday September 25, 2019 @12:18PM (#21072183)
The only restriction is that it is a s-expression: a possibly nested list of data. There is no particular programming language syntax it is parsed against - it's parsed as data.

For example this is a valid Lisp macro form

    (loop for i below 10 and j downfrom 20
          when (= (+ i j) 9) sum i into isum of-type integer
          finally (return (+ j isum)))

    It returns 10.
The LOOP macro parses it on its own - it just sees a list of data. Lisp has other than that no idea what the tokens mean and what syntax the LOOP macro accepts.

    CL-USER 142 > (defmacro my-macro (&rest stuff)
                     t)
    MY-MACRO

    CL-USER 143 > (my-macro we are going to Europe and have a good time)
    T
Works.
Re:Nim 1.0 by kazinator on Wednesday September 25, 2019 @12:27PM (#21072306)
The data has an AST. The AST is made of conses, and atoms. The atoms have a large variety of types. They are not "tokens", but objects. Tokens only exist briefly inside the Lisp reader. 123 and |123| are tokens; one converts to an integer node, one to a symbol node. (1 (2 3)) has an AST which is

    CONS
   /      \
  FIXNUM   CONS
  |        /   \
  1      CONS   SYMBOL
        /     \     \ 
      FIXNUM   CONS  NIL
        |      /   \
        2   FIXNUM  SYMBOL
              |        |
              3        NIL
Re:Nim 1.0 by lispm on Wednesday September 25, 2019 @02:41PM (#21073824)
> The data has an AST.

(not (eq 'has 'is))

But for an Abstract Syntax Tree for code we have more categories: function, operator, call, control structure, variable, class, ...

Re:Nim 1.0 by kazinator on Wednesday September 25, 2019 @07:22PM (#21076658)
That kind of tree is stipulated a particular form of compiler (well, parser) writing dogma revolving around C++/Java style OOP. You set up classes with inheritance representing various node types; everything has methods, and "visitors" walk the tree, and various nonsense like that.

If our code walker dispatches on pattern matches on the nested list structure of conses and atoms, we don't need that sort of encapsulated data structuring. The shapes of the patterns are de facto the higher level AST nodes. The code walking pattern case that recognizes (if test [then [else]]) is in fact working with an "if node". That AST node isn't defined in a rigid structure in the underlying data, but it's defined in the pattern that is applied to it which imposes a schema on the data.

If that's not an AST node, that's like saying that (1 95000) isn't an employee record; only #S(employee id 1 salary 95000) is an employee record because it has a proper type with a name, and named fields, whereas (1 95000) "could be anything".

Re:Nim 1.0 by lispm on Thursday September 26, 2019 @01:32AM (#21078483)
Syntax trees are no nonsense and go way back before Java and visitors were hip.

The code walker is just another parser. It needs to know the Lisp syntax. It needs to know which parts of a LET form is a binding list, what a binding list looks like, it needs to know where declarations are and where the code body ist. It can then recognize variables, declarations, calls, literal data, etc, It needs to know the scope of the variables etc. Nothing of that is encoded in the LET form (since it is no AST), and needs to be determined by the code walker. Actually that's one of the most important uses: finding out what things are in the source code. Lisp does not offer us that information. That's why we need an additional tool. A code walker may or may not construct an AST.

No, (1 950000) is not an employee record. Only your interpretation makes it one. Other than that our default Lisp interpretation based on s-expressions: it's a list of two numbers. In terms of the machine it's cons cells, numbers, nil. Without further context, it has no further meaning.

Re:Nim 1.0 by kazinator on Thursday September 26, 2019 @01:45AM (#21078546)
Note that deciphering type tag info in a Lisp value can be called "parsing". Cases occur: for some values we have to chase a pointer into a heap to get more type info.

A Lisp function call does "parsing". (foo 1 2 3) has to figure out dynamically whether a (lambda (&rest args)) is being called or (lambda (a b c)) or (lambda (a b &optional c (d 42)) or whatever.

The #S(employee id 1 salary 95000) object also isn't an employee record without context and interpretation.

> it needs to know where declarations are and where the code body ist

The syntax can be subject to a fairly trivial canonicalizing pass, after which all these things are at fixed positions:

  (let ((a 3) b) (foo a)) ---canon-->  (let ((a 3) (b)) (declare) (foo a))
Now the variables are all pairs to which we can blindly apply car and cadr, the declarations are at caddr and the body forms at cdddr.
Re:Nim 1.0 by lispm on Thursday September 26, 2019 @03:10AM (#21078909)
> Note that deciphering type tag info in a Lisp value can be called "parsing".

No. You are still operating on the level of s-expressions, a data format. The type-tag of LET is SYMBOL.

Here we have some Lisp code in the form of an s-expression:

   (let ((let 'let))
     ((lambda (let)
        (let ((let let))
          let))
      let))
All above LET have the same type tag, but in terms of syntax they have a different purpose in the form above: we have special operators, variable declarations, variable usage, data objects. I can't just car/cdr down the lists and call TYPE-OF. This always returns SYMBOL for LET.

On the level of a syntax tree we would want to know what it is in terms of syntactic categories: variable, operator, data object, function, macro, etc. Lisp source code has no representation for that and we need to determine that by parsing the code.

Re:Nim 1.0 by kazinator on Thursday September 26, 2019 @12:03PM (#21082312)
The type tag is to be "parsed out" in some implementation specific way. For instance, we first look at the LSB of the Lisp value. If we find a 0 there, then it's a pointer; we dereference the pointer into some heap record, where we retrieve a second-level type tag. Except that, perhaps, if the whole thing is 0 bits, then it's nil; we must not chase that as a pointer. And we find a 1 in in the LSB, then perhaps we look at other surrounding bits for the type. All of this examination of bits with irregularities and cases looks like parsing.
Re:Nim 1.0 by thsealienbstrds on Wednesday September 25, 2019 @04:31PM (#21075043)
Fair enough I guess. If the Lisp macro system only sees parsed s-exps, in principle you still need to figure out for yourself what kind of construct you are dealing with on a higher level of abstraction. Nim's macro system seems to be operating on a higher level of abstraction in that regard.
Re:Nim 1.0 by arc776 on Tuesday September 24, 2019 @11:48AM (#21061427)
Metaprogramming is one of the core ideals in the birth of the language so is well supported. Personally I've not used Lisp, so can't comment there, but it is on the list of influences on the homepage.

Essentially there's a VM that runs almost all the language barring importc type stuff, and you can chuck around AST node objects to create code, so metaprogramming is done in the core Nim language. You can read files so it's easy to slurp files and use them to generate code or other data processing at compile-time.

Several simple utility operations in the stdlib make things really fluid; the easy ability to `quote` blocks of code to AST, and outputting nodes and code to string. This lets you both hack something together quickly and learn over time how the syntax trees work.

Quoting looks like this:

  macro repeat(count: int, code: untyped): untyped =
    quote do:
      for i in 0..<`count`:
        `code`

  repeat(10):
    echo "Hello"
Inspecting something's AST can be done with dumpTree:

  dumpTree:
    let
      x = 1
      y = 2
    echo "Hello ", x + y
To save even more effort, there's also dumpAstGen which outputs the code to create that node manually, and even a dumpLisp!

You can display ASTs inside macros:

  macro showMe(input: untyped): untyped =
    echo "Input as written:", input.repr
    echo "Input as AST tree:", input.treerepr
    result = quote: `input` + `input`
    echo result.repr
    echo result.treerepr
So it's really easy to debug what went wrong if you're generating lots of code.

Since untyped parameters to a macro don't have to be valid Nim code (though they still follow syntax rules) you can make your own DSLs really easily and reliably because any input is pre-parsed into a nice tree for you.

Here's a contrived example of some simple DSL that lets you call procs and store their results for later output:

  import macros, tables
  
  macro process(items: untyped): untyped =
    result = newStmtList()
    # Create hash table of 'perform' names to store their result variables.
    var performers: Table[string, NimNode]
  
    for item in items:
      let
        command = item[0]
        param = item[1]
        paramStr = $param
  
      case $command
      of "perform":
        # Check if we've already generated a var for holding the return value.
        var node = performers.getOrDefault(paramStr)
        if node == nil:
          # Generate a variable name to store the performer result in.
          # genSym guarantees a unique name.
          node = genSym(nskVar, paramStr)
          performers.add(paramStr, node)

          # Add the variable declaration
          result.add(quote do:
            var `node` = `param`()
          )
        else:
          # A repeat performance, we don't need to declare the variable and can overwrite the
          # value in the fetched variable.
          result.add(quote do:
            `node` = `param`()
            )
      of "output":
        let node = performers.getOrDefault(paramStr)
        if node == nil: quit "Cannot find performer " & paramStr
        result.add(quote do:
          echo `node`)
      else: discard
    # Display the resultant code.
    echo result.repr

  proc foo: string = "foo!"
  proc bar: string = "bar!"

  process:
    perform foo
    perform bar
    perform foo
    output foo
    output bar
The generated output from process looks like:

  var foo262819 = foo()
  var bar262821 = bar()
  foo262819 = foo()
  echo foo262819
  echo bar262821
Re:Nim 1.0 by arc776 on Tuesday September 24, 2019 @04:27PM (#21064274)
In hindsight maybe the "performers" table would be better named "resultVars", as that's what it really represents.
Re:Nim 1.0 by pjmlp on Wednesday September 25, 2019 @05:34AM (#21069143)
We do metaprogramming all the time on JVM and .NET languages.
Re:Nim 1.0 by narimiran on Tuesday September 24, 2019 @03:50AM (#21057551)
> yet another slightly different take on Rust or Go

From Wikipedia article of each language:

  Rust: First appeared    July 7, 2010; 9 years ago
  Go:   First appeared    November 10, 2009; 9 years ago
  Nim:  First appeared    2008; 11 years ago
Re:Nim 1.0 by lmm on Tuesday September 24, 2019 @04:07AM (#21057639)
The real question is what it offers over OCaml (1996). Nim people talk about GC being "optional" but have never been able to tell a clear story about what this does and doesn't mean (D has the same problem). Aside from that, even if the language puts everything together in a more polished package than its predecessors (and I've no idea whether Nim does or not), what's the unique selling point that would make it stand out?
Re:Nim 1.0 by arc776 on Tuesday September 24, 2019 @06:43AM (#21058476)
Basically you only use GC if you declare something using a GC type.

  type
    # A `ref` type is GC and will use the heap.
    MyGCType = ref object
      fieldA: int

    # Otherwise ALL types are stack based.
    MyStackType = object
      fieldA: int
Also GC is deferred, so if you use a GC type in a local scope that doesn't escape, you don't pay for reference counting.

The only other type that use GC is `seq` (equivilent to C++ vectors) IIRC.

The standard library uses seqs in various places so if you fully turn the GC off using the compiler switch --gc:none you'll get warnings for things you use that will leak. There's no GC 'runtime' stuff that you need though.

However in my experience all you need to do is just not use refs, and make your own ptr based seq (there's probably a library for this but its trivial to implement).

Nim's GC is thread-local (so no stop-the-world issues), only triggered on allocate, and has realtime support via enforcing collection periods. Plus you can use other GCs if you wish (eg Boehm).

More info about the GC here: https://nim-lang.org/docs/gc.html

Re:Nim 1.0 by lmm on Tuesday September 24, 2019 @08:21AM (#21059240)
> Basically you only use GC if you declare something using a GC type.

So similar to C# (2000)? A useful feature to be sure, but not a major innovation.

> The standard library uses seqs in various places so if you fully turn the GC off using the compiler switch --gc:none you'll get warnings for things you use that will leak. There's no GC 'runtime' stuff that you need though.

Running with the GC off (and accepting the leaks) was already a standard managed-language technique though.

> Nim's GC is thread-local (so no stop-the-world issues)

Well no wonder it has nice properties if it avoids all of the hard problems! What happens when you pass references between threads?

> only triggered on allocate, and has realtime support via enforcing collection periods.

Your link describes the realtime support as best-effort, and implies that it doesn't work for cycle collection. So honestly this doesn't seem to offer much over e.g. the tuneable GC of the JVM (which admittedly made a massive mistake in choosing defaults that prioritised batch throughput rather than latency).

I do appreciate the information, and hope this isn't coming off as overly confrontational. But honestly it sounds like Nim is overselling things that are mostly within the capabilities of existing managed languages (maybe even behind them if the "GC" is only thread-local and/or not cycle-collecting).

Re:Nim 1.0 by mumblemumble on Tuesday September 24, 2019 @09:43AM (#21060041)
So, the full gist is: Nim uses automatic reference counting with cycle detection. If you want to, you can disable the cycle detection, perhaps only temporarily. The compiler flag for turning GC off doesn't actually turn off all GC, IIRC. It still does automatic reference counting, and it can still do cycle detection, it's just that you need to initiate it manually.

The language does have pointers, and will let you do any C-style memory unsafe whatever you want to do with them. However, it doesn't have any library calls that I'm aware of that are equivalent to C's malloc() and free(). You'd have to supply your own.

There are also ambitions, of introducing real non-GC memory-safe memory management. Probably something along the lines of how Rust does it. Those haven't come to fruition yet, though.

So, long story short, yes you can completely disable GC, but I think that its capabilities on that front are somewhat overstated.

Re:Nim 1.0 by arc776 on Wednesday September 25, 2019 @06:50AM (#21069455)
> However, it doesn't have any library calls that I'm aware of that are equivalent to C's malloc() and free(). You'd have to supply your own.

The malloc/free equivilents are in the system module: https://nim-lang.org/docs/system.html#alloc%2CNatural

Re:Nim 1.0 by nimmer on Friday September 27, 2019 @05:30AM (#21090000)
This is the owned reference memory management: https://nim-lang.org/araq/ownedrefs.html
Re:Nim 1.0 by pjmlp on Wednesday September 25, 2019 @05:37AM (#21069159)
As shown by Mesa/Cedar, a systems language with RC coupled with a cycle collector can go a long way, like a full graphical Xerox PARC workstation.
Re:Nim 1.0 by arc776 on Tuesday September 24, 2019 @10:58AM (#21060870)
I wouldn't say separating the GC at the type level is a major innovation, but as you say it's useful. I don't think Nim really sells itself on a groundbreaking GC implementation either. However it does give you a fast GC with enough flexibility should you need it. For example, the Boehm GC is not thread-local.

GC types are copied over channels with threads, or you can use the usual synchronisation primitives and pass pointers.

As you say, thread-locality avoids the hard problems and this is a good default - I would argue that most of the time you want your data being processed within a thread and the communication between them to be a special case.

Certainly, there's a lot of talk of adding some sugar to threading, and Nim does offer some interesting tastes, such as the parallel statement: https://nim-lang.org/docs/manual_experimental.html#parallel-...

The performance of the default GC is good to very good, the JVM is almost certainly better in most cases, however this is comparing apples to oranges; it's a different language.

Nim's GC pressure is much lower in most cases, not least because everything defaults to stack types which not only don't use GC but tend to be much better for cache coherence due to locality. Using ref types is not required unless you use inheritance, however the language does encourage composition over inheritance, despite providing full OO capabilities, so you find inheritance isn't as needed as in other languages.

Plus it's not really much different to using refs to drop down to pointer level and avoid the GC without disabling it:

  type
    DataObj = object
      foo: int
    Data = ptr DataObj

  proc newData: Data = cast[Data](alloc0(DataObj.sizeOf))
  proc free(data: Data) = data.deAlloc

  var someData = newData()
  someData.foo = 17
  echo someData.repr
  # the echo outputs eg: ptr 000000000018F048 --> [foo = 17]
  someData.free
All this means that you can 'not use the GC' whilst not disabling it. I am a performance tuning freak and I still use GC seqs all the time because the performance hit is actually using the heap instead of the stack, and worse, the actual allocation of heap memory - regardless of the language. The GC overhead is miniscule even with millions of seqs and would only even come into play when allocating memory inside loops. At that point, it's not the GC that's an issue, but the allocation pattern.

Again though, it's nice to be able to drop down to pointers easily when you do need every clock cycle.

Re:Nim 1.0 by pjmlp on Wednesday September 25, 2019 @05:40AM (#21069171)
That is the gist of the anti-GC crowd doesn't get.

Languages like Nim allow for having the productivity of relying on GC's help, with language features for performance freaks available, when they really need to make use of them.

Java not offering a Modula-3 like feature set has tainted a whole generation to think that GC == Java GC.

EDIT: grammar errors

Re:Nim 1.0 by guggle on Friday September 27, 2019 @09:37AM (#21091776)
> has tainted a whole generation to think that GC == Java GC

We can extend this pattern:

> has tainted a whole generation to think that OOP == Java OOP

Re:Nim 1.0 by pjmlp on Wednesday September 25, 2019 @05:35AM (#21069150)
From that point of view, C# also had hardly new to bring to the table, given Algol 68, Mesa/Cedar or Modula-3, if we start counting GC enabled systems programming languages.
Re:Nim 1.0 by pjmlp on Tuesday September 24, 2019 @09:22AM (#21059833)
I think the biggest issue is that most equate GC with Java/Smalltalk style, instead of GC Modula-3/C# style.
Re:Nim 1.0 by balfirevic on Tuesday September 24, 2019 @09:27AM (#21059879)
Doesn't .NET (and C# with it) have stop-the-world GC, very similar to Java?

Or do you mean something else?

Re:Nim 1.0 by pjmlp on Tuesday September 24, 2019 @09:45AM (#21060053)
CLR was designed for multiple languages execution models, including C++.

In what concerns C#, besides GC, you get access to off heap unamaged allocations, low level byte manipulations, value types, inlined vector allocations, stack allocation, struct aligments, spans.

All GCs have eventually to stop the world, but they aren't all made alike, and it is up to developers to actually take use of the language features for writing GC-free code.

Re:Nim 1.0 by yellowapple on Tuesday September 24, 2019 @03:52PM (#21063910)
> All GCs have eventually to stop the world

Not entirely true. Erlang's BEAM definitely doesn't need to (unless you define "world" to be a single lightweight process). Perl6's MoarVM apparently doesn't need to, either.

Re:Nim 1.0 by pjmlp on Tuesday September 24, 2019 @04:26PM (#21064257)
Yes, I do define it like that, there is always a stop, even pauseless collectors actually do have a stop, even if a few microns.

Doing it in some local context is a way to minimize overall process impact.

Just like reference counting as GC algorithm does introduce pauses, specially if implemented in a naive way. More advanced ones end up being a mini tracing GC algorithm.

Regardless, having any form of automatic memory management in system languages is something that should have already become standard by now.

Re:Nim 1.0 by yellowapple on Tuesday September 24, 2019 @05:33PM (#21064862)
There's always a stop, yes, but there's not always a stop of the whole world, which is my point. "Stop the world" implies (if not outright definitionally means - explies?) that the execution of all threads (lightweight or otherwise) stops while the garbage collector runs - e.g. that of (the official/reference implementations of) Python and Ruby.

Erlang doesn't require stopping the world because every Erlang process is isolated from the others (no shared state at all, let alone mutable shared state). I don't know off-hand how Perl avoids it.

Re:Nim 1.0 by nimmer on Friday September 27, 2019 @05:31AM (#21090004)
> All GCs have eventually to stop the world

Not at all. Nim is an example.

Re:Nim 1.0 by fluffything on Tuesday September 24, 2019 @04:41AM (#21057812)
Nim compiles to C, so you can use any existing C toolchain to generate a native executable for whatever platform you care about.

That's a big advantage over Rust, D, OCaml, and similar languages without this feature.

Re:Nim 1.0 by lmm on Tuesday September 24, 2019 @05:29AM (#21058044)
I see that as a downside, personally. It makes it a lot harder to understand what guarantees there are about with a given piece of code (rather than being able to look at the assembly and the language's own compiler, you would have to also understand C's rather odd semantics and the complex behaviour of many C compilers).
Re:Nim 1.0 by arc776 on Tuesday September 24, 2019 @06:23AM (#21058358)
This is a bit like saying you wouldn't use LLVM languages because of the semantics of IR, or that you have to understand the guarantees IR provides, isn't it?

Ultimately if you're really interested in performance, regardless of the stages of compilation, the juice is the machine code output at the end.

In terms of guarantees, those should be satisfied higher up in the language itself, with C generation being output according to Nim's CGen spec. The compiler is fully open source though and easy to dig into.

Having said that, the CGen output is fairly readable if you're familiar with C and I must say I've investigated it when I wasn't sure how something was generated.

Re:Nim 1.0 by lmm on Tuesday September 24, 2019 @07:57AM (#21059017)
> This is a bit like saying you wouldn't use LLVM languages because of the semantics of IR, or that you have to understand the guarantees IR provides, isn't it?

Those languages tend to be a lot simpler than C, both in terms of what constructs they offer and in terms of how simply they translate into (platform-specific) assembly language. I'm not against the idea of intermediate languages in general, but IME C is the worst of both worlds: more complicated than most high-level languages and most assembly languages.

> In terms of guarantees, those should be satisfied higher up in the language itself, with C generation being output according to Nim's CGen spec. The compiler is fully open source though and easy to dig into.

The problem is being confident that those guarantees are preserved all the way down. It's very hard to be confident of the properties that any given piece of C code has, because it's extremely rare for C code to be 100% standards compliant and different compilers do radically different things with the same code. And it's hard to reason about the effects of changes because C compilers are so complicated: maybe you understand the Nim compiler and can see how two similar Nim functions will generate similar C code, but that doesn't help you much when two similar C functions can be compiled to radically different assembly (which happens a lot).

Re:Nim 1.0 by pjmlp on Wednesday September 25, 2019 @05:44AM (#21069187)
Nim is however not alone, with Haskell using C--, Eiffel using C (nowadays C++ as well) and Unity's IL2CPP/Burst.
Re:Nim 1.0 by lmm on Wednesday September 25, 2019 @06:00AM (#21069262)
C-- is very different from C.

Indeed several languages compile to C; I regard that as a downside for all those languages. I'm not sure what your point is?

Re:Nim 1.0 by pjmlp on Wednesday September 25, 2019 @06:31AM (#21069379)
That it is a very common approach.
Re:Nim 1.0 by fluffything on Wednesday September 25, 2019 @09:47AM (#21070712)
I don't follow. Nim uses C as an intermediate representation, just like many languages use LLVM-IR, Gimple, javascript, etc.

If you care about the assembly a piece of code generates, you can just look at that.

The generated C code that Nim emits looks like what it is: boring automatically-generated C code.

If you wanted to debug the compiler, you could take a look at that, but most users don't have to.

Re:Nim 1.0 by lmm on Thursday September 26, 2019 @04:21AM (#21079180)
C is a very complicated language with very complex compilers. The translation from C to assembly (under modern compilers) is hard to understand, even for "boring automatically-generated C code". Languages like LLVM-IR or Gimple are designed to be simple and translate more directly into assembly. I'd have the same complaint about javascript to a certain extent, but even though it's a full programming language it's a much simpler language than C and easier to introspect at runtime.
Re:Nim 1.0 by c-cube on Tuesday September 24, 2019 @10:46AM (#21060743)
For me it's more: what does it offer over Crystal (apart from being freshly 1.0). Crystal seems a lot nicer and a bit more, hum, uniform. Nim seems to have a lot of features to be aware of, and doesn't have type-safe nil.
Re:Nim 1.0 by lmm on Tuesday September 24, 2019 @05:35PM (#21064891)
Well Crystal is newer than Nim and gives me even more of a "what is the unique advantage of this language" feeling. As to the specific point, Crystal may be nil safe but union types have many of the same problems as unchecked null (particularly when used with generics). Nim has compiler-enforced not-nil types plus true sum types (and therefore an option type), which make it possible to program in a completely safe way - though I'm not sure how well the standard library supports that approach; I would certainly prefer a language that didn't have null at all, as OCaml does.
Re:Nim 1.0 by vfclists on Tuesday September 24, 2019 @12:47PM (#21062103)
> The real question is what it offers over OCaml

To you, that is

Re:Nim 1.0 by setr on Tuesday September 24, 2019 @10:22AM (#21060474)
It’s not actually important what came first, but rather whats currently being used/popular. Nim might have had the headstart, but its lost the race, so now it has to challenge its existence against the current popular set of languages people are looking at for transition
Re:Nim 1.0 by peteforde on Tuesday September 24, 2019 @07:37AM (#21058828)
While I'm happy to be informed after being clearly misinformed, I promise you that I'm a full-time developer working with reasonably bleeding edge stuff and I've never heard of it before last night.

I'm lucky to have folks here to set me straight. :)

Re:Nim 1.0 by nimmer on Tuesday September 24, 2019 @04:30AM (#21057763)
> appears to be yet another slightly different take on Rust or Go

Nim is nowhere close to that. Most people describe it as a very fast statically typed Python.

Re:Nim 1.0 by galangalalgol on Tuesday September 24, 2019 @07:20AM (#21058694)
Also nim came first, also, rust and go aren't even targeting the same use cases. Rust is for performant systems coding or webasm with far fewer footguns than c or c++. Go is for back end software with less cruft or boilerplate or latency than java but about the same throughput as java. It sounds like nim is "i just wan to get this working but I'm worried python wont run fast enough."
Re:Nim 1.0 by peteforde on Tuesday September 24, 2019 @07:51AM (#21058966)
Okay, but you're ignoring the thrust of my question, which is "why do I care". Your name is nimmer so it's safe to say we understand why you care, but help me understand why I care about the 3rd-runner:

https://trends.google.com/trends/explore?geo=US&q=%2Fm%2F09g...

I'm only comparing it to those languages because of the direct comparisons many others have many in this thread. And popularity != quality, but age is also a very poor measure of success.

Re:Nim 1.0 by Phillips126 on Tuesday September 24, 2019 @09:14AM (#21059753)
Had Nim been developed by or had funding from a large company (Google, Mozilla) I'm sure that chart would be much different. Instead, Nim is built by a group of volunteers contributing to a language they love.

I am not a contributor, but I also quickly fell in love with the language. I felt incredibly productive and being able to build tiny binaries that were cross platform was awesome compared to my old Golang binaries which tend to be heavy (bundling everything into a single binary). Also coming from a web background with little system/application programming knowledge I was able to pick it up really quick. It really is a "better python" in my opinion. The language is incredibly easy to read and write, has really good JSON support (which is a big plus for me) and is incredibly fast. To add more reasons to try, Visual Studio Code has a really good plugin for the language.

Re:Nim 1.0 by galangalalgol on Tuesday September 24, 2019 @09:14AM (#21059758)
Nimmer was the parent. I actually like rust more. Though all three are distant in popularity to java or python, so popularity is probably not going to be the distinguishing characteristic between them. The reason i chimed in is precisely because people keep directly comparing rust and go and they ar all horribly misguided. Sure, you vould write a web backend in rust (or just the slow bits like dropbox did) but you do it because go turned out to be too slow, not because that is a primary use case for rust. And while you could probably write drivers in go, why?
Re:Nim 1.0 by PMunch on Tuesday September 24, 2019 @04:28AM (#21057751)
Let's try to fill out some of this grid: Who started this? - That would be Andreas Rumpf, or Araq as he is known on IRC

Is it corporately affiliated? - No, it was created by Andreas, and has stayed independent. But it has corporate backing, which helps pay for development, and they do get a certain prioritisation in what gets implemented. But no closed door stuff.

What languages is it similar to? - Depends on what kind of similarities. Syntactically it will remind you of Python or maybe even Ruby. But when you use it the powerful type system might remind you of Ada, the macro system possibly of Lisp, the run-time speed of C/C++ or Rust, and the compilation time of, well, not C++ (it's really fast).

What is the motivation of its creators? - As far as I know the initial motivation was to have something that was as usable as Python and languages like that, but which was actually fast and type-safe. For me as a contributor these features allow me to focus on higher level things so I tend to mostly use the macro and type system to create wonderful abstractions that allow me to create nice readable code quickly.

What is the philosophy driving its design? - Haven't seen any guys with long white beards, pipes, and stacks of book in the community, so I'm not entirely sure there is an official philosophy. The design is mostly based on giving tools to the developer, and making sure they do "the right thing". If the developer then uses these tools to chop their arm of then that is their prerogative, but generally not advised.

Is it intended to be an eventual competitor or replacement for languages XYZ? - Well many people come to Nim from Python, seeking better performance, or from C or JS seeking better usability. While Nim doesn't try to position itself as a direct replacement or competitor for any one language in particular it is a probably candidate for most if not all of them.

Where does it sit on the spectrum between raw assembly and MS Access? - In terms of abstraction somewhere high up above with Lisp and friends (no personal experience with MS Access, so not sure where that actually ranks). The core language is pretty straight forward, but with the macro system the sky is the limit!

Is it intended to be a "systems language" eg can you write a kernel or device driver using it? - Yes, Nim does call itself a systems programming language, and there have been toy kernels written in it (not sure about drivers though, but I wouldn't be surprised). It can also run on micro-controllers and other embedded systems. Pretty much as long as you can run C, you can probably run Nim. That being said it also compiles down to JS, and has a lot of features that allow it to be used for anything from web-sites, through games and applications, to micro-controllers and kernels.

Does it require a VM? - Trick question, but yes and no. The compiler implements a VM to run Nim code on compile-time for the macro system, but this VM is not present at run-time.

Is there corporate support available? - It is possible to get a contract with the core developers to get support yes. Not that I've ever felt the need for any further support than the excellent IRC channel (which is also bridged to Gitter and Discord).

How established is the developer community? - The aforementioned IRC channel is very active, as well of course as the GitHub repository. There is also a yearly meetup at FOSDEM, and talks, articles, and videos about the language and development is coming out all the time.

Are there books and courses? - There is so far only one physical book, Nim in Action, and it's really good! As far as courses go there is no active course with a teacher and course material (as far as I know). But there are tutorials for all levels of programming skills, from never programmed before to picking it up as your n-th language. There are also more interactive things like Excercism where you can solve problems and have people from the community look over your solutions. Other than that people will often happily look over and comment on your project if you post in on Reddit or drop a link in the IRC channel.

Does it have garbage collection? - Yes, by default Nim has a garbage collector, but it is tuneable so you can control when and for how long it runs. And you can disable it completely and use manual memory allocation, for when you're doing kernels and micro-controller work for example. The garbage collector is also per-thread, meaning that running multi-threaded will not stop your entire application when it's collecting garbage. You also have an option regarding which garbage collector you want to use, all with different performance considerations, but in general all really fast.

Is it a compiled language? - Yes. Nim itself compiles down to C/C++/Obj-C or even JS. Then it is passed on to the target compiler to create native binaries, or in the case of JS left to either be run by node or loaded into a web-page.

Is it a strongly typed language? - Yes. Nims type system is strong and flexible. The basics similar to Adas type system. It also has type-inference however, so you might not guess that it is strongly typed by looking at the examples.

What are the three perfect use cases? - Hmm, this one is tough. I use Nim for pretty much everything, from scripting simple things on my own machine, to creating and deploying web-sites, graphical applications and games. But judging from the community I think the top three use cases are: High-performance computations, Web-dev, and games. The primary financial backer of Nim, Status, also uses it to create an Ethereum client focused on mobile devices. But not sure which category to bunch that into.

How stable is the API? - Now with the release of v1 the API of the core language and stdlib will be stable moving forward on the v1 branch. This means bug fixes will be back-ported, and any new features will only be added if they don't break this promise.

What's the package management story? - Nim has its own package manager, Nimble, and over 1000 packages ready to go with everything from bindings to popular C libraries to large pure Nim libraries and applications.

Does it have a reasonable standard library? - Indeed! The standard library is large, and has pretty much everything you need.

Is there editor support for color coding and linting? - Yes, there are plug-ins for various editors (most use the VSCode one, I personally prefer Vim), and also an LSP implementation if you want these features in an editor that doesn't yet support them.

What's the job market look like? - Not huge to be perfectly honest, there are a couple of opportunities around. But I was surprised to find people at my current job using it for some tinkering and internal tools. I'm personally lucky enough that I have fairly large autonomy in how I do my work, and I'm able to use Nim.

Is the documentation well-written? - Personally I find them pretty good, and recently they have been read through and improved, so they are better than ever. Nim also offers document comments directly in the code, so many libraries you find will be nice and documented as well.

And most importantly, if we all got in the same room, would I want to hang out with the people excited about this language? - I've tried this at FOSDEM for two years now and they are a wonderful bunch!

Re:Nim 1.0 by pietroppeter on Tuesday September 24, 2019 @06:16AM (#21058317)
> What is the philosophy driving its design?

I think that the [nim github tagline](https://github.com/nim-lang/Nim) expresses well the philosphy: "Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority)."

also Araq's blog post on 1.0 explains well how the guiding principles remained the same over time:

"When I started Nim's development I had a small simple language in mind that compiles to C; its implementation should not be more than 20,000 lines of code. The core guideline has always been that Nim should be a small language with a macro system, which should be capable of extending Nim with all the features that the small core is missing.

The current compiler plus the parts of the standard library it uses has roughly 140,000 lines of code, runs on a plethora of operating systems and CPU architectures, can also compile Nim code to C++ and JavaScript, and Nim's meta programming capabilities are top of the class. While the language is not nearly as small as I would like it to be, it turned out that meta programming cannot replace all the building blocks that a modern language needs to have.

For example, while Nim manages to implement async via its macro system, the macro system needs to be able to compile code into a state machine. And these state machines need some form of goto and a way to capture their environment. So Nim's core needed to grow so called "closure iterators" to enable this.

Furthermore, we don't really know yet how to leverage a macro system in order to give us extensibility on the type system level, so Nim's core needed generics and constraints for generics."

Re:Nim 1.0 by fluffything on Tuesday September 24, 2019 @04:45AM (#21057839)
> Yes, by default Nim has a garbage collector,

Does the standard library and all other user libraries work with the garbage collector turned off, or do I have to use a different ecosystem for those applications?

Re:Nim 1.0 by PMunch on Tuesday September 24, 2019 @05:40AM (#21058091)
They work only as long as they don't use any garbage collected types (the compiler will warn you of this when you turn the GC off). Unfortunately this means most libraries are out, and you have to do your own thing. Turning the GC off is more meant as a way to use Nim on micro-controllers and for things like kernels and such. In this case many libraries that aren't written for this use-case doesn't really make sense to use anyways, so I'm not sure how big of an issue this is in reality.
Re:Nim 1.0 by rkangel on Tuesday September 24, 2019 @06:00AM (#21058205)
> I'm not sure how big of an issue this is in reality

I agree - embedded programming is a sufficiently separate world that you'll always need a different foundation with different assumptions.

Rust which doesn't have a GC at all, but stillhas this problem to some extent. On a microcontroller you generally don't want to use the standard library with all its assumptions about heap allocations always succeeding. This is why 'nostd' and libraries like heapless exist.

Re:Nim 1.0 by fluffything on Wednesday September 25, 2019 @09:45AM (#21070697)
> Rust which doesn't have a GC at all, but stillhas this problem to some extent.

I agree, but there is a big difference between not being able to use almost any library, and being able to use most libraries.

There are many many libraries on embedded Rust, and my embedded and not embedded projects do share many libraries.

Re:Nim 1.0 by guggle on Tuesday September 24, 2019 @08:06AM (#21059103)
> so I'm not sure how big of an issue this is in reality.

I have audio programming in mind. Not that you can't do audio programming in GC-enabled languages, it's just that's it's quite frown upon in this circle (for good reasons). I'm sure there are workarounds though.

Re:Nim 1.0 by rayman22201 on Tuesday September 24, 2019 @01:54PM (#21062846)
Audio programming in Nim is completely possible and reasonable.

Here is an example of a super collider plugin written entirely in Nim with the GC turned off: https://forum.nim-lang.org/t/3625

The author seemed to find the experience very pleasant, and the performance was great.

Re:Nim 1.0 by etatoby on Monday September 30, 2019 @11:13AM (#21116189)
Not (yet) a Nim user, but another post mentioned that GC is thread-specific, so you can remove all traces of GC-types from your real-time thread(s) in order to avoid deallocations at the wrong times.

A related question is whether you can disable GC on a thread by thread basis.

Re:Nim 1.0 by PMunch on Tuesday September 24, 2019 @09:23AM (#21059840)
Audio programming? And why is it frowned upon? If it is because of the Java-like GC freezes that is something you can ensure will not happen in Nim by turning on manual control and only running it when its suitable.
Re:Nim 1.0 by monetus on Tuesday September 24, 2019 @01:00PM (#21062246)
Not the person you responded to, but yes. The audio must never be interrupted, everything else first.
Re:Nim 1.0 by peteforde on Tuesday September 24, 2019 @07:52AM (#21058972)
This is an AMAZING answer. I'm sad I can't buy you a sandwich.
Re:Nim 1.0 by PMunch on Tuesday September 24, 2019 @09:24AM (#21059854)
Well thank you :) Meet up at FOSDEM and you can buy me a sandwich there!
Re:Nim 1.0 by littlestymaar on Tuesday September 24, 2019 @07:36AM (#21058823)
> most importantly, if we all got in the same room, would I want to hang out with the people excited about this language?

Interesting, I wouldn't even thought someone could consider it a criterium for a language choice. Now I wonder if most people care about it like you do.

Re:Nim 1.0 by peteforde on Tuesday September 24, 2019 @07:40AM (#21058854)
Yes. A thousand times, yes.

https://en.wikipedia.org/wiki/Yukihiro_Matsumoto (see the first paragraph)

A huge part of the reason that people love Ruby even when there's so many Elixirs/Elms/Crystals/a hundred more around is simple: it's a community full of nice, smart, interesting people with varied interests that extend beyond coding.

Re:Nim 1.0 by littlestymaar on Tuesday September 24, 2019 @10:11AM (#21060357)
> it's a community full of nice, smart, interesting people

Isn't everyone describing the community they belong as such? I have yet to meet someone advertising his programming language of choice with “the community is full of morons, join us!”…

Re:Nim 1.0 by qpleple on Tuesday September 24, 2019 @03:30AM (#21057444)