
Nim 1.2 - narimiran
https://nim-lang.org/blog/2020/04/03/version-120-released.html
======
intrepidhero
I've been doing the nim track on exercism.io (no affiliation, just a user) for
the last two weeks. The mentors on the track have been fantastic. If you're
looking for a "solve a problem and get some external feedback" approach to
learning the language it's pretty good.

~~~
zelphirkalt
Personally I stopped using exercism, when it started to require me to work for
Google for free and would not let me log in, if I did not. It's not an ethical
platform, unfortunately.

~~~
mikebelanger
What do you mean by 'work for Google for free?' I don't see that being
required anywhere on the site.

~~~
afiori
Probably it is a reference to the reCapcha hell Google may drop you into if
you are deemed "suspicious"

~~~
mikebelanger
ah ok. I never saw those captcha things as work per say, but yeah I guess they
are. Free work for some model data somewhere.

------
iimblack
Dup is very interesting to me. Does that mean that in Nim all functions will
be impure by default, and that it's considered idiomatic to modify the input?
I guess it's nice that they're trying to make behavior consistent. It just
seems like the opposite of the recent directions I've seen other languages
take.

~~~
treeform
Mutating in place is often times faster and is more straightforward.

I do feel Nim embraces mutation more than other recent languages.

~~~
eindiran
Yeah, the 'discard' keyword is a pretty cool way to note that you're using a
procedure only for its side effects.

------
sergiotapia
If you would like to see some simple to parse Nim code and get a feel for what
a "1 month of experience during weekends" Nim looks like, check out my
project:

[https://github.com/sergiotapia/torrentinim](https://github.com/sergiotapia/torrentinim)

Nim is a very interesting language, with a lot of upsides. It just needs that
killer framework to get the ball rolling and allow devs to solve business
needs quickly. Once that's done I think Nim will grow a lot! Tiny binaries,
static binaries, fast, low memory usage, macros, compiles to C.

~~~
MaxBarraclough
It uses a rather primitive garbage-collector though, right?

~~~
sp33der89
It really doesn't! It's GC story is pretty great, because you can choose out
of several GC's, one of them being good for real-time systems: [https://nim-
lang.org/docs/gc.html](https://nim-lang.org/docs/gc.html)

Recent versions also use this fancy thing:
[http://www.gii.upv.es/tlsf/](http://www.gii.upv.es/tlsf/)

~~~
MaxBarraclough
'TLSF' sounds very interesting, I'll have to keep an eye on that project. What
are the reference-counting options for though, given the absence of weak
references? Under what circumstances is it acceptable to permit memory-leaks
in case of cycles? Short-lived processes (i.e. arena-based memory management)?

When I say 'primitive GC', I mean Boehm, which is obviously decades behind the
state of the art, but easy to get off the ground. GNU Guile uses it, for
instance. Serious garbage collectors are tremendously complex, and are
something less popular languages unfortunately tend to lack. I believe even D
is miles behind Java.

Can't say I know much about Go's GC.

 _Edit_ Oops I misread, TLSF isn't a GC, it's an allocator. It sounds then
like Nim doesn't have a proper real-time solution, does it? _useRealtimeGC_ is
actually a leaky reference-counting system?

~~~
rayman22201
Did you see the parent comments about the new -gc:arc? It's suitable for hard
real time.
[https://www.youtube.com/watch?v=yA32Wxl59wo](https://www.youtube.com/watch?v=yA32Wxl59wo)

~~~
MaxBarraclough
> Reference cycles cause memory leaks, beware.

It isn't acceptable to just permit memory-leaks in case of cycles. There's no
way we'd ever see something like that in a serious JVM.

Unless there's some serious machinery to provide assurances against reference
cycles, of course. Which sounds like an interesting research project, come to
think of it.

~~~
beagle3
> It isn't acceptable to just permit memory-leaks in case of cycles.

That's only in the new --gc:arc which is still somewhat experimental. The old
gc, --gc:markandsweep IIRC, does detect cycles, and has a deadline schedule
(i.e. you can tell it "I now have 5ms, collect as much as you can"); But it
has per-thread heaps, which means passing data between threads often entails a
copy. You also have --gc:boehm (no cycles, shared heap), and --gc:none (no gc,
you should take care of freeing memory yourself).

------
nepeckman
The collect macro is awesome, and way more idiomatic Nim than list
comprehensions. Nim continues to hit the sweet spot between performance and
developer ergonomics.

------
DeathArrow
Nim might be great. But how can a great language get traction if nobody big is
behind it?

Java and Python are being pushed by Silicon Valley and universities, Go is
being pushed by Google, Kotlin is being pushed by Google, C# is backed by
Microsoft and some big companies.

Who can help Nim, or Crystal, or Rust or other new language?

I look at many of them from time to time, see interesting developments, see
exciting things but I refuse to learn the languages, their ecosystem and
frameworks from the fear I have I will lose lots of valuable time since I
might not be able to earn my living using them.

~~~
moonduster
Surprisingly, a lot of large companies use Rust in-house. I work at Nando's,
one of our biggest systems is in Rust, and we're a chicken restaurant
business, so it's not just limited to bleeding-edge SV companies.

Hoping we can open-source some of this stuff in the near future too to kind of
show the world that Rust is ready.

~~~
chris_j
Please tell us more - I'd be really interested to hear what system it is and
to learn about your experiences.

------
dom96
By far my favourite feature of this release, dark mode in docs: [https://nim-
lang.org/docs/lib.html](https://nim-lang.org/docs/lib.html)

~~~
treeform
I feel like dark mode is a sign that people care. I think it's a user feature
that is easy to do, but not done often. Mostly done by people who care. It
brings so much polish to the experience.

~~~
qqssccfftt
What if I care specficially not to add a dark mode?

~~~
yjftsjthsd-h
Why exactly would caring about users lead you to omit something that makes
things nicer for them?

~~~
SaxonRobber
Maybe the same reason why others choose to omit light modes, despite that
being my preference.

------
alberth
I really with more people used NIM for web development. It really seems like
the best of all worlds (e.g. perf, developer ergonomics, productivity, etc).

~~~
andybak
How would the dynamism and expressivity of something like Django port to Nim?
I love the whole declarative paradigm of the Django forms and models API. Is
Nim good at this kind of DSL-ish plasticity?

~~~
PMunch
Extremely well I'd say. Nim has a very powerful macro system, and DSLs are
very common across various modules. Haven't used Django myself, but something
like Jester
([https://github.com/dom96/jester](https://github.com/dom96/jester)) or Karax
([https://github.com/pragmagic/karax](https://github.com/pragmagic/karax)) is
a good place to start if you want to do web development in Nim.

------
jakear
> If you were relying on some edge case and/or buggy behaviour which is now
> fixed, try if --useVersion:1.0 gives you back the results you expect to see.
> If that doesn’t work and you need the old behaviour, please open an issue in
> our bug tracker and we will try to make it work in future bugfix releases

So useVersion doesn't simply checkout the old codebase, but they still promise
to maintain all prior version's bugs? Seems like a losing battle to me... why
not just tell people relying on version 1.0 behaviour to use version 1.0 and
create tooling to make sure switching between versions is easy (a. la. nvm)?

~~~
_0ffh
My impression was that using "choosenim" switching between versions is easy
already, but I might be missing something.

~~~
rayman22201
choosenim is still supported :-)

The idea is more like the gcc -std flag (gcc -std=gnu++11 for example). to
emulate certain versions to ease upgrading.

~~~
jakear
Do you think the gcc -std flag would exist if every distribution of gcc
included a command to easily download alternate versions and swap them out
depending on project configuration? -std seems more like a bandaid around a
difficult install/config than a feature, in my opinion.

Obviously nim is free to make implement whatever options they want, but it
seems to me like every second spent triaging/fixing/etc bugs about not
properly maintaining broken things (not to mention the end user time spent
experiencing them and debugging them!) is time that could be better spent
improving the language.

~~~
tomsmeding
Yes, the -std flag would definitely still exist: the thing being changed by
that flag is a lot of stuff in the parser, some stuff in the standard library,
and some semantics bits further towards the backend, but at some point the
versions converge and go through the same optimisation pipeline. A pipeline
that definitely has seen improvements in more recent versions, so it's totally
worth it to use a new compiler with an old language standard on old code: it
might very well produce a faster executable. Just using an older compiler
would also revert back to the old performance.

Additionally, a C/C++ compiler in an older standard mode would disable certain
features, of course, but not completely: it's still able to give diagnistics
in the vein of "this thing isn't valid with the current version setting, but
it _would_ be valid in C++17", for example. That's useful to a programmer.

~~~
marvy
Also useful in the other direction: your code works now, but in C++17 that's a
keyword so you'll have to rename it.

------
hartator
Very bullish on Nim. It's Python with C-level performance.

------
rishav_sharan
I am currently working on a tiny game in nim using Raylib. I had some initial
friction with Nim, but i like using the language now. You'll do well to stop
trying to use Nim as an oops language and just use it as a better C. The
language syntax is clean, and the std lib has all that I need.

One bit which I still hate is simply how imports work in Nim. My project
pretty much has a header like file containing function and variable signatures
which can be called from other files.

For someone used to modern languages, it just feels so archaic.

But overall it is still a fantastic language and I am excited to try the ARC
gc

~~~
dom96
> One bit which I still hate is simply how imports work in Nim. My project
> pretty much has a header like file containing function and variable
> signatures which can be called from other files.

You mean how `import` works or are you using `include`? If the latter then I
would strongly discourage you from using it.

As for the former, you can use `from module import nil` everywhere if you
really want.

------
wmock
As someone who's heard of Nim, can someone who's used it tell me a little bit
more about its benefits and how it compares to other common languages like
JavaScript, Python, etc?

~~~
rayman22201
The major features are: Python like syntax, Lisp like macro system, potential
for C like performance (YMMV of course).

This is my person opinion here: Nim is part of the "new generation of system
programming languages" from the last decade or so. Some other examples in this
category include Zig, D lang, Go lang, Swift, Rust, etc...

The whole idea is to provide "modern high level" language features and
ergonomics while still producing efficient low level code.

For Pythonistas, The familiar syntax is attractive to Python programmers
looking for a more performant language (data science is a prime example.)

Nim is also attractive to lispers looking to move to a more traditional Algol
or C like language while still keeping much of power and flexibility that they
are used to from macros.

------
iffycan
Among other great additions, I like the addition of compilesettings [1], which
will give programs more visibility into how they were compiled.

[1] [https://nim-lang.org/docs/compilesettings.html](https://nim-
lang.org/docs/compilesettings.html)

------
dzonga
hope they nim developers, port a lot of python data science tools e.g pandas,
numpy etc so they can increase adoption in the language. Julia is supposed to
fill that space, but feel strongly nim is better positioned

~~~
eigenspace
Out of curiosity, what do you feel makes Nim better positioned in this space?

~~~
rayman22201
As I said in another comment, the familiar python like syntax, while having
the potential for much better performance.

Many data scientists are familiar with Python. They can write similar code and
will run much faster by default (or with very little tweaking).

Then, if that's not fast enough, The language is positioned such that you can
optimize the code to a much higher degree than you can with Python.

I'm not saying that Python code can't be optimized, but there is a limit to
the speed of python code even with optimization. At some point you have to
drop down to a C extension (what Numpy, Pandas, etc... does) and then you are
just writing glue code in Python to drive the C. You could also use one of the
Python optimized compilers, but that has limits and edge cases as well. There
is "developer friction" there.

In Nim you can just have the whole program in one language. The program can be
optimized to the same level as optimized C code with no special tools. This is
much less friction.

What's missing is the libraries. But that will come with time.

~~~
eigenspace
I guess I'm asking what you think Nim offers that julia doesn't here. Is it
just syntax?

------
totalperspectiv
Very excited to see gc:arc make it into stable.

~~~
sergiotapia
For the layman Nim dev, would you say "always use gc:arc" is a safe bet?

~~~
dom96
Definitely not. --gc:arc is still experimental.

~~~
treeform
I would still try out --gc:arc on your programs. For mine it just runs without
issue. But keep in mind if you do have issues you might have to create a bug
report and wait for a fix. You would not reply on --gc:arc working. But it's
fun to play around with. It's real now.

------
war1025
Irrelevant, but I spent the entire day reading this headline as NVim, i.e.
Neovim.

These comments make a lot more sense now.

------
predators372
Oooo, wow collect looks so much cleaner. I can't wait to get home and play
with it!

~~~
adwww
> I can't wait to get home and play with it

A. Where are you that you are not already at home??

And B. I wonder how many people are using nim at work, and what sort of
workplaces that might be?

~~~
ilaksh
B.

[https://github.com/nim-lang/Nim/wiki/Companies-using-
Nim](https://github.com/nim-lang/Nim/wiki/Companies-using-Nim)

------
rattray
Does Nim have an ORM or querybuilder as good as SQLAlchemy yet?

~~~
pietroppeter
There is
[Norm]([https://github.com/moigagoo/norm](https://github.com/moigagoo/norm))
that goes in that direction.
[ormin]([https://github.com/araq/ormin](https://github.com/araq/ormin)) takes
a different twist

------
flywind
Nice!

