142 points · by dom96 · 10y ago · 103 comments
We also have a BountySource campaign[3], so if you would like to support us please consider making a donation.
Finally, please feel free to AMA!
1 - https://manning.com/books/nim-in-action?a_aid=niminaction&a_...
2 - https://manning.com/books/nim-in-action?a_aid=niminaction&a_...
Also how does the gc trace variables on the stack? How do you determine if a value is a pointer to an object or an integer?
Since version 0.14 (iirc) however, Nim uses a traditional mark&sweep backup GC to collect cycles. Reasons: Trial deletion in practice is much slower.
For all versions of the GC is stack is scanned conservatively as precise stack scanning is simply too expensive when C is your main target.
But to ask a pointed question, doesn't that mean Nim gets the worst of both worlds? You have both the overhead of updating reference counts and the (relatively long) garbage collection pauses. I guess if the programmer codes in such a way that no cyclic garbage is created it is not a problem because the gc will never be triggered. But how common is that in practice? Does the language make it easy to avoid cycles?
As far as I know, variables are only traced if their type is `ref`. So the type system helps the GC a lot here I think.
This is great! There are a lot of little things like this in the nim standard library that make life a lot easier. I should write more nim.
but what is the return type? The multisync example shows separate generated methods that return `string` and `Future[string]` depending on the method argument.
If that's the case then blocking and non-blocking operations need to be treated separately since operations defined on a result of `Future[string]` are not the same as those available on `string`.
HKTs not only allow for both method argument and return type to be polymorphic, but also allow one to define the same operations (like map, flatMap/bind, fold, etc.) on the wrapped type.
Seems like Nim is the answer :)
Are Ada's range types similar to D's, or quite different?
https://dlang.org/phobos/std_range.html
The above page links to the one below - the one below is about the concepts, by Andrei Alexandrescu (who joined Walter Bright in developing D).
However, once I started a reasonably sized project, getting Nim to compile it became difficult. Lots of small little quirks that weren't greatly documented.
However, when it did build, it was reasonably fast, and allowed me to tweak the C code when I disagreed with the compiler.
Macros were still getting developed, last I played with Nim, but I'm not sure comparing with Lisp is fair.
I adore Lisp, and its macros. (Both CL style and Scheme).
But most languages are designed to constrain the programmer to a way of thinking, a series of patterns.
Lisp was the opposite.
Even in languages that try to give the programmer flexibility, they miss the power of Lisp's homoiconity.
That being said, I think Nim is trying to find a middle ground between Python's "only one way to do it" and Lisp's "get out of the programmers way".
Its a decent language, albeit with a tiny, rather opinionated, development team.
For instance?
> But most languages are designed to constrain the programmer to a way of thinking, a series of patterns. Lisp was the opposite.
Lisp is still the opposite. Exactly this is the problem of Lisp: It is too powerful. I admire Lisp for its power, and there actually is no other language with such a freedom. Everyone can write his own DSL to simplify his task. Writing DSLs is extremely easy in Lisp.
However, this doesn't profit maintainability, and it makes sharing code with others difficult. You actually need a lot of discipline that you code in such a way that it remains maintainable. In teams you need to constrain the way of thinking otherwise you can quickly run into chaos.
Java is the opposite of Lisp. You cannot code productively in Java unless you use a sophisticated framework. Such frameworks force you to a certain style of coding which profits maintainability. That is one factor which explains the huge success of Java in business.
Nim and Rust combine both paradigms. They provide a certain degree of freedom, and they require a certain degree of discipline. Haskell requires an extreme amount of discipline. In case of Haskell's freedom I am not convinced.
> For instance?
Nimble file naming [0]. It must end in '.nimble', and must have at least character in front of that suffix, but the prefix doesn't actually matter.
I'm not convinced on the maintainability argument. Many, many projects have a coding style guide. LISPs require one too. Once you have one, maintaining the code becomes as difficult as any other language. I've encountered unmaintainable Python code [1], and insanely well documented Scheme code [2]. I'm not sure the language has much to do with it, apart from supporting a wide range of paradigms and patterns.
I'm not sure black-boxing through use of a sophisticated framework is any better than the way you work in more flexible languages.
Here's my take:
* Nim is great. The use of the 'auto' keyword let me be productive using it.
* Scheme is great. It lets me do insane things, and the compiler will optimise it to work, and well. (Rather than breaking three similar function into pieces, I can make one function that generates all three functions using their commonalities).
* Java is the smart kid at college who always answers questions in the form of a thesis. He isn't wrong, but you don't really remember what he was saying.
[0] https://github.com/nim-lang/nimble/issues/166
[1] Hence why things like this exist: http://docs.python-guide.org/en/latest/writing/structure/
[2] http://cvs.savannah.gnu.org/viewvc/slib/slib/alist.scm?revis...
Does it? With the type system guiding me if feels like it requires less discipline.
As far as freedom is concerned, I can't offhand think of something I'd want to do but can't in Haskell.
1 - https://github.com/nim-lang/Nim/issues
2 - irc.freenode.net #nim
Snappy responses to Github Issues, with really clear, really polite responses. Even when I was an idiot.
I sort of find the idea refreshing myself. As a full time Clojure developer, I consider Nim to be the closest thing I can find to what I want for a great experience coding closer to the bare metal.
Even conditional logic constructs (if/else) should be an expression (i.e. return a value).
The language doesn't even have to be pure or hard core FP to follow this philosophy.
Together with immutable "variables" (let) this encourages a pretty functional style. I'd just wish their support for lambdas and list comprehensions would be a bit better.
let x = 5;
(That said, very nearly everything is an expression, yes)Yeah, looking at it from the perspective an utopical pure functional world this seems as much of an abomination as "out arguments" in C# ...but in real world code things look different :)
That's wrong. Nim has both macros and templates.
> Lisp macros are not necessarily shorter, but it's far easier to see what's going on.
Even Lisp macros are not perfect. You always have to care for new symbol names where the lexical scope could be affected.
I thought Lisp code was its own AST, although I don't really know much about Lisp.
Nim developed from the bottom up, being closely related to C which is nice and makes porting to other platforms easy. The Nim development team adds only features which really make sense. If they just remove those immature ugly features like strong spaces and the redundancy of underscores then Nim 2.0 could be a really great language.
Links: https://www.manning.com/books/nim-in-action and (for the free chapter) https://manning-content.s3.amazonaws.com/download/1/f2a2c55-... .
But in the specific case of Nim - AFAIK there aren't that many languages around with a similar set of characteristics. For me the killer is the combination of GC (I am quite fine with not having to bother with memory management), readability, reasonable high levelness including closures etc, nice OO support, extremely good C and C++ interop and really good performance.