
Nim 0.19 - bpierre
https://nim-lang.org/blog/2018/09/26/version-0190-released.html
======
nepeckman
> func is now an alias for proc {.noSideEffect.}

So excited for this addition! I like to program Nim in a functional lite
style, and this is some nice sugar to write functional procedures. Its also
nice that the language reserved the function keyword for procedures that are
_actually_ functions.

~~~
narimiran
> So excited for this addition!

I've been using it for a while in the devel version (Nim v0.18.1), and it is
great — I like it very much and I completely understand your excitement!

Before I didn't bother with {.noSideEffect.} pragma, and now with `func` here
— my code is much more clear (at least to me ;)), and I can immediately tell
which of my procs are 'pure'.

~~~
k__
What does it do?

~~~
tyingq
It does some static enforcement of "no side effects[1]".

[1][https://en.m.wikipedia.org/wiki/Side_effect_(computer_scienc...](https://en.m.wikipedia.org/wiki/Side_effect_\(computer_science\))

~~~
Buttons840
How? Even Haskell, who makes a big deal out of separating pure vs impure code,
can't do it perfectly.

~~~
tyingq
I don't think they claim they do it perfectly. You can find bugs related to
that, false negatives and positives.

~~~
Buttons840
[https://nim-lang.org/docs/manual.html#pragmas-nosideeffect-p...](https://nim-
lang.org/docs/manual.html#pragmas-nosideeffect-pragma)

It looks really impressive.

------
androidgirl
I started playing with Nim last weekend, after the article on here about Nim.

I absolutely love it! I'm looking for an opportunity to use it at work for
something minor, and I have been porting a few of my (small) Rust applications
to Nim in my free time.

Such a pleasure to work with and so intuitive.

~~~
_zachs
May I ask what the nature of the Rust apps you're porting is? I'm currently
learning Rust and would be interested in knowing why you're moving away from
it.

~~~
3rdAccount
Not parent post, but to me, Nim is very easy to write coming from Python. For
virtually zero effort, I can get near C speeds in a tiny self-contained
executable.

Rust is probably more mature (more users) but requires me learning a lot of
low level concepts. If you already know Python and just want fast code and
easy deployment, Nim might be a better choice. Crystal is similar for Ruby
users.

~~~
thejvexperience
I'm feeling old. This is really at the top of a HN thread?

Since you self-describe as "coming from Python," you maybe haven't yet really
gotten that deep into the internals of computers and what kind of stuff you
might wanna do that isn't well supported by higher-level languages. This is
especially relevant when we get to talking about performance guarantees,
wherein very little can get "guaranteed" about a garbage-collected system, by
definition. So while it is a pain to deal with "low-level concepts" like in
Rust, it is also well worth it depending on what kind of tech you need to
make.

~~~
3rdAccount
I'm an EE, so I did take some microprocessor and FPGA classes and can write
some assembly.

With that being said, my day job isn't programming, but engineering which
involves a lot of managing data so scripting languages are very vital: Python,
Perl, R, Bash, Powershell...etc. Also, other technology like SQL and Excel are
daily drivers.

I've used Java & C# a bit in the past which are fast languages, but they're
missing the majority of linear algebra and optimization libraries that are
widely available in Python/Matlab/Julia.

So what if one of my simulations is too slow for comfort? Re-writing Python in
Julia or Nim isn't too hard (syntax is very similar) and i get a huge speed
boost. That's all I'm saying. I'm being pragmatic about the situation. Of
course I can rewrite performance critical code in C/C++/Fortran/Ada/Rust, but
that is a huge last resort as those languages (well Fortran isn't as bad as
they say) take me much longer to get something going and you're absolutely
correct that my hardware understanding has greatly atrophied since college.
For an engineer (in this case a traditional engineer and not a software
engineer), we generally need code to A.) automate processes B.) design and run
simulations C.) do data analysis.

We rarely write low-level software to twiddle bits unless we really have to.
There are simply better choices to make the things I care about run faster
even if I was good at C.

~~~
nimmer
> I can rewrite performance critical code in C/C++/Fortran/Ada/Rust, but that
> is a huge last resort

Random benchmark with the latest release. I don't know how reliable it is but
in my experience Nim can often be very fast:

[https://github.com/drujensen/fib](https://github.com/drujensen/fib)

------
planetis
I see Nim lately made some cleanup in the macros module. Thats great. Macros
now are much more easy to wrap my head around and I have already produced my
first usable macro:
[https://github.com/b3liever/protocoled](https://github.com/b3liever/protocoled).
Also others are trying to use the new caseStmt macros:
[https://github.com/alehander42/gara](https://github.com/alehander42/gara).
Great stuff!

------
hikarudo
I'm considering using Nim for an embedded project, because Nim can generate C
or C++ code, and a C and C++ compiler is all there is for my target platform
(a DSP).

I would like to use C++11, but the manufacturer only supports C++03, and will
never add support for C++11 because it's a legacy DSP.

~~~
dom96
Sounds like Nim would be perfect for your use case. Happy to help out if you
run into any problems.

~~~
eaurouge
I bought your book with the hopes that you would include a chapter on embedded
programming, but was disappointed to find it barely got a mention in the book.
I remember an earlier discussion here where you were considering and it seemed
like a real possibility.

Unfortunately, I haven't been able to find recent (ideally official)
documentation/discussion on embedded programming. Contrast this with Rust
where there's a significant focus on embedded bare metal, particularly for
Cortex-M MCUs. With the recently announced support from Status, are there any
plans to provide more support for embedded bare metal?

~~~
Araq
Support for embedded is indeed getting into focus. I hope to release an
article soon how the '\--gc:regions' switch works (which is misnamed, it's a
way to do memory management, not a GC...) and in the longer run the
destructor-based runtime will ensure that memory is freed sooner than a GC
would for memory constrained devices.

Having said that, "embedded" is a wide field and sometimes one cannot even
afford a heap, no matter if garbage collected or managed manually. But even
then Nim can be used, you still get array bounds checking, Ada-inspired strong
type checking plus the meta programming goodies.

~~~
eaurouge
Great! My interest is in bare metal environments where you typically don't use
a heap. I'm not familiar with the `--gc:regions` switch, but I think a good
start could be a guide on how to implement simple non-garbage collected
programs.

~~~
snaky
That's region-based memory management. ML guys tried it
[http://mlton.org/Regions](http://mlton.org/Regions)

~~~
ptx
Looks like they concluded that having the compiler automatically choose an
appropriate region but silently leak the memory when that fails doesn't work
well? Kind of like GC by reference-counting without a cycle collector.

Couldn't the compiler just reject code that would need to allocate in the
global region, unless the programmer explicitly annotates it to make it
global? It says the SML type system is too weak for this, but perhaps Nim's
type system is sufficient?

------
da02

      Nintendo Switch was added as a new platform target.
      See the compiler user guide for more info.

~~~
steveklabnik
Very intriguing! I'll have to look into how this works; my understanding is
that you can't do this without signing NDAs, and only distributing to people
who have also signed NDAs...

~~~
jyapayne
I wrote the implementation of the Nintendo Switch support. It currently uses
the publicly available open source library Libnx and Devkitpro.

See [https://github.com/switchbrew/libnx](https://github.com/switchbrew/libnx)
and my wrapper around that library (it has all functions exposed using nimgen,
a C wrapping library, but the Nim-friendly wrapper is a WIP)
[https://github.com/jyapayne/nim-libnx](https://github.com/jyapayne/nim-libnx)

In order to use this, you must have a homebrew enabled Switch. Google is your
friend!

~~~
steveklabnik
> In order to use this, you must have a homebrew enabled Switch

Ahh that’s the difference!

Home brew stuff is great, but that’s different than being able to sell games.

------
sergiotapia
I'm thinking about rewriting a very popular open source project of mine in a
language that can spit out a simple binary people can double click or have it
run in a terminal window to serve API requests.

Does Nim have true single-binary deploys like Go has? My original project is
written in Elixir and even with Distillery it still seems a little convoluted
for what I'm trying to deliver to end users.

I want a real, download this and run it boom, go to localhost:1234 for some
cool stuff.

~~~
dom96
Yes, Nim has this. There is a caveat though, but AFAIK Go has the same
problem.

Certain Nim modules/packages might wrap a C library. If you use those then
your binary will typically depend on a DLL for that C library. With some
effort you can statically link against those libraries, but I wouldn't call
that easy. This is in particular a problem when you're using regex or SSL, the
former depends on PCRE and the latter on OpenSSL/LibreSSl.

Go benefits from having native implementations of those written in Go. We also
now have a regex engine[1] implemented in Nim but it hasn't made its way into
the stdlib yet (that is planned though). But you can use it pretty easily as a
package if you want to avoid the dependency on PCRE.

1 - [https://github.com/nitely/nim-regex](https://github.com/nitely/nim-regex)

------
iffycan
I've really been enjoying using Nim for one-off data processing projects here
at work. I'm also excited to see where nimx [1] goes (a cross-platform UI
library).

[1] [https://github.com/yglukhov/nimx](https://github.com/yglukhov/nimx)

~~~
narimiran
I'll mention another great library from the same author:

[https://github.com/yglukhov/nimpy](https://github.com/yglukhov/nimpy)

A library which allows you to connect Python and Nim so you could, for
example, use Nim (instead of Cython) for speeding up some parts of your code,
compile it, and call it from your Python program.

------
sephware
Nim is fantastic, I especially like that it takes a pragmatic approach to all
its features, so that it doesn't get bogged down in theory but lets you get
productive with it right away. One example is that even though it says it's a
systems (and application) language, it has GC (ref counting + cycle
detection), which means you don't have to worry about memory management and
can focus on the core of your application. Honestly I think Nim is comparable
to Go, so if you're thinking of adopting Go, look into Nim, you might like
what you find.

~~~
enitihas
I too was enthusiastic about using Nim, as it is clearly a much superior
language to go. However, the ecosystems are not at all comparable. Even
without considering the huge amount of 3rd party packages for go, the go
stdlib itself is too good and has almost all batteries included. For Nim, if
you are going to develop any non trivial program, it is going to be really
difficult to find the relevant libraries.

~~~
mlevental
i don't understand why people make these kinds of criticisms. everyone already
understand that the assumption for a new language that the ecosystem won't be
as rich. you're basically saying something akin to "x high school football
player is much worse than y professional football player in a professional
game". of course. judge them in context.

~~~
bendmorris
>i don't understand why people make these kinds of criticisms.

Because language age doesn't make a difference. People have to actually use
the language, and this is a practical concern.

If you were choosing to put a high school football player or an NFL player on
your team _right now_ it'd be an easy choice, wouldn't it?

~~~
mlevental
>People have to actually use the language, and this is a practical concern.

do they? is it in the rules of building languages and ecosystems that every
new language has to be production ready from day 1? it is also possible that
you can use it for hobby projects and that that's sufficient merit to talk
about it and have posts about it too.

~~~
bendmorris
What on earth are we comparing when discussing Nim vs. other languages, if not
the language itself, in practice? Are we just discussing how good you feel
about it?

My point is, this is an actual deficiency that you need to consider when
evaluating Nim, that _isn 't_ just a function of the language being new. For
example, Zig is another option which puts any C libraries at your fingertips,
without requiring bindings. If Nim had better interop (not just relatively
good, but zero effort) this would no longer be a concern and you wouldn't need
all of your libraries to be in Nim.

~~~
mlevental
>if not the language itself, in practice?

...

>However, the ecosystems are not at all comparable.

......?

~~~
bendmorris
Not sure what you're getting at. People in this thread are discussing what
it's like to use Nim, including its ecosystem, vs. other languages and
ecosystems. You don't seem to have anything substantive to add to that other
than that Nim is "new" which as I mentioned isn't relevant to the experience
of actually using it.

~~~
mlevental
you asked about merits of the language itself. what does the ecosystem have to
do with the language /itself/

------
treeform
I am switching all my work to him now. It's a super fast python with types.
The non nil string and sequence in this version are cleaver.

~~~
vfclists
You mean "nim" not "him"? Or does your native language use gender based "it"
equivalents.

grammar Nazi - can't help myself.

~~~
e12e
Thought it was a great typo. Like, oh wow, this person is devoting themselves
to templeos full-time, and they're porting it to nim. Or something ;)

------
MR4D
Has anybody thought to submit some benchmarks to the Benchmarks Game? I know
that benchmarks aren't perfect, but would be nice to at least have an idea of
how it stacks up against some of the other languages.

[0] [https://benchmarksgame-
team.pages.debian.net/benchmarksgame/](https://benchmarksgame-
team.pages.debian.net/benchmarksgame/)

~~~
mratsim
I don't think they accept new languages anymore.

~~~
dom96
Indeed. They even specifically named Nim in their FAQ[1]:

> Why don't you include language X?

> Because I know it will take more time than I choose. Been there; done that.

> Measurements of "proggit popular" programming language implementations like
> Crystal and Nim and Julia will quickly attract attention and be the basis of
> yet another successful website (unlike more Fortran or Ada or Pascal or
> Lisp).

1 - [https://benchmarksgame-
team.pages.debian.net/benchmarksgame/...](https://benchmarksgame-
team.pages.debian.net/benchmarksgame/play.html)

------
vesak
Does Nim have (or plan to have) (non-)nullable types?

~~~
PMunch
With version 0.19.0 Nim also moved away from nilable seqs and strings, so they
are much safer to use. An empty string and a nil string is now the same, and a
nil seq and a seq without elements is the same. Saves you from that one
missing nil check that crashes your entire program.

If you want the behaviour of nilable seqs and strings you can use the options
module.

------
mrath
I have been learning Rust recently. Nim looks interesting, is there a quick
comparison page with Rust somewhere?

I just skimmed through the doc, and looks like the language is huge. Is it
expected to have a big learning curve?

also could not find any info on Async and threading is there any documentation
around it?

And the GC, is it optional or more like compiler determines it using set of
rules?

~~~
chris_mc
I found it was easy to write Nim coming from Python and doing a few tutorials
I found around the web and some programming puzzles. The advanced features
like macros, tempates, generics, etc. are harder to learn, but I haven't
needed them yet so far. I did have to dig into the actual library source code
several times because the documentation is quite sparse, and for things like
async and parallel programming there aren't many examples to pull from at all.
However, I find it's _way_ easier to program in Nim with static typing and the
applications I write are _much_ faster than Python, even without the crutches
of numpy operations, pandas dataframes, and the huge Python ecosystem.

------
vvpan
There is now an Ethereum 2.0 client being written in nim:
[https://github.com/status-im/nimbus](https://github.com/status-im/nimbus)

------
h3rald
Great news! I have been using Nim almost exclusively for my open source
projects for years now, since when it was called Nimrod...

It is simply amazing to see how it evolved and improved over time. I love the
fact that it runs seamlessly on several different platform, that is so fast
and so syntactically expressive and elegant.

Way to go guys, Araq, dom, and everyone who made Nim possible! Really glad you
are finally getting the momentum and the attention that you deserve. Keep it
up!

------
ospohngellert
Does anyone know any good learning resources for this language aside from the
tutorial. Just tried jumping in and got weird compile errors when trying to
work with lists.

~~~
FraaJad
There is a book "Nim in Action" [https://www.manning.com/books/nim-in-
action](https://www.manning.com/books/nim-in-action) by @dom96

~~~
dom96
Author here :)

I understand that it might suck to be buying a book to learn a language, so
just in case you don't want to commit to that there are two chapters of the
book which are free. You can find them listed in the link above or here:
[https://book.picheta.me/](https://book.picheta.me/)

~~~
ospohngellert
Thanks so much! Want to get started with it before I decide to buy a book on
it, but seems like a great language to program functionally in without all the
hurdles :)

~~~
Kihashi
Also worth noting that Manning has sales quite frequently.

------
Serow225
How is Nim's package manager, given the love for Cargo and churn with golang
it seems like a thing people really care about.

~~~
nathancahill
Nimble is quite nice. It's still beta so occasionally rough around the edges
(maybe mostly so in the docs).

------
Serow225
Is there IDE debugging support for Nim yet (language server?). Or a REPL,
Online or off? Thanks

~~~
nepeckman
Both in progress.

Language server:

[https://github.com/nim-lang/langserver](https://github.com/nim-
lang/langserver)

[https://github.com/nim-lang/langserver/issues/1](https://github.com/nim-
lang/langserver/issues/1)

As for a REPL, there is already `nim secret`, but there is work being done to
create a better interactive environment.

[https://github.com/nim-lang/Nim/issues/8927](https://github.com/nim-
lang/Nim/issues/8927)

~~~
Serow225
Thanks!

------
Kip9000
Is GRPC available for Nim?

~~~
dom96
Sadly no, but sounds like a fun project :)

~~~
Serow225
:)

------
uvtc
Nim appears to be quite similar to Haxe, though Haxe compiles to numerous
additional targets. Aside from that, and the syntax, what are the main
differences between Nim and Haxe?

~~~
lasagnaphil
I think the one downside of Haxe (which is also is strength) is that it
doesn’t only support compiling to C/C++, but to every major language possible
(Java, C#, PHP, Javascript), so the language ends up being too complex. You
constantly have to think about how the languages features will map to your
target language if you care about performance, which can be pretty
unintuitive. And the C++ target (hxcpp) is quite heavyweight and takes a lot
of time to compile (at least the last time I checked out). Also C interop
doesn’t seem that convenient.

On the other had Nim only transpiles to C, so the language is simpler and
easier to reason about performance. (And it probably has faster compile
times). It is also explicitly designed to interop with C, so you can easily
use all those C libraries in the wild...

But I still have some hope on Haxe, because the main developer is working on
Hashlink, which can run Haxe code on a virtual machine but can also transpile
it to C for production builds... It seems a more simple and “focused” Haxe
target that doesn’t have all the warts of hxcpp...

[https://hashlink.haxe.org](https://hashlink.haxe.org)

~~~
isr
> On the other had Nim only transpiles to C

Nim also compiles to javascript too, right?

~~~
dom96
Yep. C/C++/obj c and JS

------
chris_mc
I've been waiting for this for a while! I never could get `develop` to run.

~~~
gekkonier
I'm curious what where the problems? It's imho straight forward.

~~~
chris_mc
It would change day to day, obviously, and my code wouldn't run sometimes. I
guess I really meant I prefer stability in this case over new features.

------
haarts
Who is funding the development of Nim?

~~~
dom96
This shows who is sponsoring us currently: [https://nim-
lang.org/sponsors.html](https://nim-lang.org/sponsors.html)

Status has recently become a large sponsor, but over the past years it was all
donations from our users (who were and continue to be incredibly generous!)

~~~
haarts
I'm glad to see that ICO money is put to good use! I'm genuinely excited for
the future of Nim. Keep it up!

