8 ms·
> Nim on the surface has a dream set of features It's "too good to be true" is for real. The lack of friction when developing in Nim is what makes it so fun to
by arc776 6y ago
> Nim on the surface has a dream set of features
It's "too good to be true" is for real. The lack of friction when developing in Nim is what makes it so fun to code in (IMO). Metaprogramming in particular is just great in Nim and give you a lot of scope for doing things that would otherwise require new language features.
> how do you cope with the ever increasing scope of the language?
I've been using Nim pretty intensively for several years. From my perspective the language design has been very stable, even since before 1.0. I don't feel like the scope is expanding, and I don't think it really needs to either because the core language is built to be expanded with metaprogramming.
None of my code breaks when updating versions (and I do a lot of heavy metaprogramming). Nothing seems to be abandoned, only refined, and there's a big effort towards backwards compatability so breaking changes are exceedingly rare. The only one I only remember was some time ago when seq (the variable sized list type à la C++ vector) became not nil, so I had to replace `if list != nil` with `if list.len > 0`, so a good change IMO.
Most of the new things have been mechanical under the hood improvements and ownership is one of those. As I understand it, when using gc refs, you'll get free extra speed, better multithreadding, and better compile-time checks. No code needs to be changed, and when it's considered ready it will replace the previous GC, and you can add extra annotations for performance. It's refinement of the GC using ownership rules rather than a whole new set of rules for your program.
The stdlib is very stable (at least from my experience), and again great effort is spent on backwards compatability. Stdlib focus is on being small and "essential", so there's a high bar for stuff getting into it, and probably why it's rare for anything to change API there.
So personally the pace of change has been great - basically my code's just got free speed boosts when it's already fast enough :)
- codetrotter 6y ago> Metaprogramming in particular is just great in Nim and give you a lot of scope for doing things that would otherwise require new language features. Metaprogramming is v alluring to me, but I’ve been wondering, people that write code super heavy on the metaprogramming, doesn’t revisiting code and debugging become much more taxing?
- planetis 6y agoI have written a lot of metaprogramming myself, like 5/10 of my repos are macro libraries. And I share your concern. Even the manual advices people to use the least "powerful" tool for the job. These are proc/func<template<macro. Macros are prefered for creating dsl like https://github.com/treeform/fidget https://github.com/treeform/fidget or https://github.com/pragmagic/karax https://github.com/pragmagic/karax Otherwise the advice is to use them when they "pull their weight". The reason is they're a lot harder to write and even "design" them right (how they function, what code they write, etc) takes a lot of effort. And in most cases the simpler "tools" will fit your needs.
- mratsim 6y agoYou have multiple ways to print the macros either as AST tree or even Nim code that can be copy-pasted to replace the macro: - dumpTree - lisprRepr - treeRepr - toStrLit This means that for debugging you can generate your code. Replace the macro by regular code temporarily and understand what's wrong and then fix the macros. I don't think I have a single library without macro but I try to keep them as reasonable as you can. But sometimes you need to give a Python feel (for example to provide a Numpy interface for a multidimensional array library) or you have to do code transformation (implementing async or multithreading as a library or autovectorizing high-performance computing code or implementing a GPU or Audio DSL) and there is no way around macros.
- arc776 6y agoYou generally want to use the simplest tool for the job first. Most of the time generics and templates really are as much as you need since Nim's generics are structurally typed and templates allow a lot of metaprogramming without getting into AST trees. My experience debugging complex compile time transformations is pretty positive thanks to the tools available to manipulate and debug the syntax trees. For example you can `echo node.repr` to display the code it represents at any point, and going the other way you can pass code to `dumpAstGen` to display the code that will generate the AST tree and so on. This also has the benefit of letting you quickly understand how the trees are structured by trying different bits of code, or for passing DSL syntax fragments to see the parsed tree structure for your macro to consume. The main important thing is that stack traces at compile time get you to the place where the error is happening. How hard that is to debug depends on how complex your tree manipulation is, and how you are doing that manipulation. For example if you're just got a load of `quote` statements that interpolate variables and you're chucking these together, the trace will usually lead to the start of the `quote` block, so if you've got a long `quote` block then you have to kind of find the error in that, but it's not too bad since the error messages are pretty precise and the language is strongly typed. For direct AST manipulation, the error will point to the place where the error is triggered, so for example if you add a bunch of statements in a node, the error may be the place that node is added to it's parent to be 'connected' to the program as a whole. Or, if it's an attempt at a duplicate variable declaration it will point directly to the place where you're creating the `ident` that represents the variable in your macro, so that's pretty nice. In short, yes it is more work, but it generally makes sense, is type safe, and we have tools that mean fixing stuff is often some `echo` statements to look at generated code.
- Isomorpheus 6y agoWhy does Nim have "nil"?
- gmfawcett 6y agoTo represent a null pointer. Nim is a systems language (or at least can be used as one), and you need null/nil when working at that level. Even Haskell has null pointers, if you know where to look: https://hackage.haskell.org/package/base-4.14.0.0/docs/Foreign-Ptr.html#v:nullPtr https://hackage.haskell.org/package/base-4.14.0.0/docs/Forei...
- Isomorpheus 6y agoLikewise unsafe Rust has null pointers, but I've never needed it or seen it used. (Same with Haskell). You just mentioned using "nil" in a simple example which doesn't appear to be related to systems programming.
- gmfawcett 6y agoI didn't mention "nil" in a simple example. I wasn't the poster of that comment.
- Isomorpheus 6y agoOh, thought you were same poster. Well, that other person mentioned it in a context which doesn't appear to be related to systems programming. Just checked Github for some of the top Nim projects. Forum software: https://github.com/nim-lang/nimforum/search?q=nil&unscoped_q=nil https://github.com/nim-lang/nimforum/search?q=nil&unscoped_q... Web framework: https://github.com/planety/prologue/search?q=nil&unscoped_q=nil https://github.com/planety/prologue/search?q=nil&unscoped_q=... Twitter front-end: https://github.com/zedeus/nitter/search?q=nil&type=Code https://github.com/zedeus/nitter/search?q=nil&type=Code These uses of "nil" don't appear to have anything to do with systems programming.
- 6y ago
- abledon 6y agowhat are you making in NIM? Finance stuff? Websites? Database tools? Science/Space? Kinda curious what you've done "using Nim pretty intensively for several years"
- bdl 6y agoI’m not the OP but have implemented a bioinformatics algorithm library with with Nim. I had an implementation in Python and just ported it to Nim. I have been incredibly impressed with Nim to say the least. I managed to make the Nim version orders of magnitude faster with fewer lines of code while having more features. With the excellent Nimporter library, I can easily make a Python API and have it be pip installable. I genuinely think Nim (or similar) may be the future of my field. Combined with its JS compile target and WASM support, it lets me target my three main “platforms“: web, Python API, and high-performance CLI.
- cl3misch 6y agoThis sounds very interesting! What are your thoughts on nim vs julia? In the scientific community, julia is popular for similar reasons as nim like easy syntax and compiled code. If you think nim will take over in bioinformatics, how is the support of numerical algorithms like BLAS and LAPACK?
- planetis 6y agohttps://forum.nim-lang.org/t/5242 https://forum.nim-lang.org/t/5242 There is https://github.com/mratsim/Arraymancer https://github.com/mratsim/Arraymancer n-dimensional tensor (ndarray) library Native plotting library: https://github.com/Vindaar/ggplotnim https://github.com/Vindaar/ggplotnim as well as many other packages.
- totalperspectiv 6y agoThis is a good write up imo: http://lh3.github.io/2020/05/17/fast-high-level-programming-languages http://lh3.github.io/2020/05/17/fast-high-level-programming-...
- 6y ago