Readit News logoReadit News
disruptek · 5 years ago
I want to remove a couple misunderstandings that I see in the comments.

Nim is "not done" and I hope it never will be. Watch Guy Steele's "Growing a Language" talk for my rationale. We want a language that can continue to evolve and introduce or research new programming language technology.

ARC is scope-based memory management computed at compile-time. It is deterministic and not stop-the-world. If you want to influence the memory management for performance reasons, it's quite trivial to do so by manipulating scopes. There are also knobs and levers if you need direct control of individual allocations.

ORC is ARC but with the tiny addition of a cycle-breaker.

ORC will be the default because it's more convenient than ARC while capturing all of the benefit. It simply adds calls to the cycle-breaker that you may be uninterested in typing in yourself.

pietroppeter · 5 years ago
What a delightful talk! And how it resonates well with Nim!

I went first for the transcript [2] but you should go for the video [1].

[1] https://www.youtube.com/watch?v=_ahvzDzKdB0

[2] https://www.cs.virginia.edu/~evans/cs655/readings/steele.pdf

delightful: full of good things that give joy

resonates: sounds in a way that is like the one you also say, and if you hear both you get more joy

transcript: a way to track down stuff that you can read and you do not need to see or hear

supakeen · 5 years ago
Congrats, Nim is really becoming more and more mature as time goes on and showing new features like these are great though they do come off a bit as "a not done language"?

What is the plan for ARC/ORC stability and possible default? Are we looking at 1.6 or later (1.8?). Will the GCs (since ARC isn't really a GC) be deprecated at that time?

Tiberium · 5 years ago
One of the links in the end of the article leads to the RFC which talks exactly about this, see last commit by Araq especially: https://github.com/nim-lang/RFCs/issues/177#issuecomment-696...

In short: yes, the current plan is to phase out other GCs over time.

supakeen · 5 years ago
Perfect, all except markAndSweep/go, thank you!
pjmlp · 5 years ago
> Will the GCs (since ARC isn't really a GC) be deprecated at that time?

Any form of reference counting is definitely a GC.

http://gchandbook.org/contents.html (chapter 5)

turbinerneiter · 5 years ago
I guess the more interesting questions is whether it happens at compile time or run-time - ARC definitely injects derefs at compile time and therefore there are no gc-"pauses" at runtime.

(Right?)

beagle3 · 5 years ago
> Will the GCs (since ARC isn't really a GC) be deprecated at that time?

Not sure why you don't consider ARC a gc - it is, with the caveat that it doesn't break cycles on its own. If you have cycles you aren't going to break on your own, use ORC.

loxs · 5 years ago
Is there a good reason to invest time in Nim for someone who already knows and likes Rust?
PMunch · 5 years ago
It entirely depends on what kind of things you want to do. For example if you want to program microcontrollers with a modern language and 0 overhead over C then Nim is a great language to learn. Or if you want to write a web front-end and back-end in the same language that compiles to JS and C respectively then Nim is yet again a great language. Or if you just want to get into programming with macros to boost your productivity or make nice patterns in your code, then Nim is a great language. Or if you are just curious as to what else that is out there, then Nim is a great language.
arc776 · 5 years ago
I would say one of Nim's biggest strengths is the productivity of Python with the performance of C; it feels like scripting, but you have production ready performance.

Another productivity benefit is compiling to C, C++, and Javascript means you can natively use libraries from those languages.

If you want to go deeper, check out the extremely powerful metaprogramming capabilities that rival Lisp and I would argue are much more advanced than Rust. The end result of this is very nice syntax constructions which means easy to read code, and again translates to high productivity with no performance loss.

arc776 · 5 years ago
Another reason: compile times are super fast compared to Rust and C++ even with lots of metaprogramming.
rattray · 5 years ago
Nim has always seemed like an incredible do-it-all language to me.

What sorts of most programs are most frequently built with it these days?

thom · 5 years ago
I started dabbling with chess engines written in Nim (lots of bit twiddling but also interesting concurrency challenges) and found it delightful. Genuinely the most fun I'd had with a language for years. I think the combination of native power with light, accessible syntax and a simple mental model is very promising indeed. The fact that you also get JavaScript compilation seems great, although I've not yet used it. I have tried, and will keep trying, to fall in love with Rust because I do buy into a lot of its philosophy but just never get there.
butterisgood · 5 years ago
I remember fondly programming on Inferno with Limbo that had reference counted GC and a cyclic version as well - but you were forced to declare data structures as cyclic.

Nim is interesting but I’ve been more closely following Zig lately. Perhaps it’s time to dig into Nim too!

elcritch · 5 years ago
For a good example of what ARC enables, I just did a [Show HN](https://news.ycombinator.com/item?id=24790239) for a project I've been doing for programming ESP32's in Nim.

You can use Nim on embedded devices without GC, but it eliminates many parts of the standard library, like JSON handling. The regular Nim GC's also have problems with threading, which shows itself on the ESP32's dual cores and multi-tasking.

StavrosK · 5 years ago
Your Show HN doesn't seem to have gotten much traction, but I am ecstatic about programming the ESP8266/ESP32 in something other than C. I don't care if it's Nim or Rust or whatever, I'm just tired of programming like it's the 80s.

I'll be watching your project with great interest.

elcritch · 5 years ago
Thanks! I was hoping it'd coincide enough but was probably too late. Maybe I'll do a write up article later and compare C/Nim/CircuitPython. It's amazing what even basic maps/tables with generics provide. No more `void ` blackholes.

That said, `Nesper` is basically stable. It'd be nice to make prettier Nim-first API wrappers. It's stable enough that I'm planning on shipping product out next couple of weeks with it.

P.S. all of the Nim runtime and a simple async http server only adds about 80kB vs the standard `smart_config` esp wifi example! Not sure even Rust matches that.

I'm curious, are you working on embedded devices for side projects or for work?

Rochus · 5 years ago
Why not using something like https://github.com/Ravenbrook/mps?
rattray · 5 years ago
What are the advantages of MPS (Memory Pool System) to ORC to your understanding?
Rochus · 5 years ago
Well, ARC/ORC is a reference-counting concept for one part and also a new implementation for Nim. MPS is a mature and proven implementation of a whole memory management infrastructure which offers different GC strategies (M&S, Copying, Incremental, etc.). And it's written in C, so it could well fit with the Nim runtime. Here is a paper: https://www.ravenbrook.com/project/mps/doc/2002-01-30/ismm20.... MPS is surprisingly unknown. I also only discovered it recently and currently try to use it in a project.

EDIT: maybe a reason why people didn't consider it so far was that earlier versions were only available under Sleepycat/dual license; current versions are BSD.

flywind · 5 years ago
Great article! I will try orc for my project.
vsskanth · 5 years ago
Is Nim a systems programming language ? can it operate at the same level as rust and zig ?
nimmer · 5 years ago
Absolutely yes. The default GC (not ARC/ORC) is not stop-the-world.

"Nim's memory management is deterministic and customizable with destructors and move semantics, inspired by C++ and Rust. It is well-suited for embedded, hard-realtime systems."

auxym · 5 years ago
Nim compiles to C, so you can use it as a "better C" like rust or Zig. That said, the main difference is that it comes with a GC, or more accurately, multiple GC options that are tunable. If you cannot have GC, as in embedded, you can compile without GC, but then you lose access to the vast majority of the standard library (which is similar to rust's --no-std, from my understanding).
Tiberium · 5 years ago
You can use ARC/ORC just fine on embedded :) Not sure why do you think that it's impossible.
gameswithgo · 5 years ago
Many people call Go a systems language, which by my reasoning means almost anything is.

Like many words programmers use, there appears to be no agreed upon definition. Memory management in Nim is not usually totally manual so may be not top notch for all systems type tasks. But you can probably do it if you need to given how configurable memory management it.

rattray · 5 years ago
Interestingly, they claim yes – the homepage says this:

> Nim is a statically typed compiled systems programming language.

> Nim's memory management is deterministic and customizable with destructors and move semantics, inspired by C++ and Rust. It is well-suited for embedded, hard-realtime systems.

However, this article says that ORC, a non-deterministic and non-hard-realtime GC system, is likely to become the new default GC in the future.

Perhaps they found that the "systems language for hard-realtime" wasn't as compelling a value proposition as they originally thought?

Or perhaps the tradeoffs of ORC and availability of manual memory management give them confidence that it won't materially harm hard-realtime systems use-cases in practice?

arc776 · 5 years ago
> the tradeoffs of ORC and availability of manual memory management

For those not familiar with the language, Nim only uses GC for `seq` (dynamically sized lists like c++ vectors), `string`, and types declared with `ref`.

Everything else is a stack allocated value type, or as noted in the parent, you can manually manage with pointers.

> won't materially harm hard-realtime systems use-cases in practice

I think this is true. I already find myself rarely using GC when writing Nim, but when you want it, it's nice yet painless.

Here someone is embedding an async messagepack/JSON RPC on an ESP32: https://forum.nim-lang.org/t/6916

Later they compare no async, and ORC with async and find that it's "only a few ms slower than the RPC calls running with ARC and no async."

While this example may not be the hardest of realtime, it does show that ORC competes with manual approaches to memory management in constrained environments.

Tiberium · 5 years ago
Even if ORC becomes the default no one stops you from using ARC which is 100% deterministic and hard-realtime.

ORC would be enough for most normal usages, and ARC is a switch away.

UnnoTed · 5 years ago
The first phrase in Nim's home page answers that question... "Nim is a statically typed compiled systems programming language."

also: "Support for various backends: it compiles to C, C++ or JavaScript so that Nim can be used for all backend and frontend needs."

babo · 5 years ago
Not really. As the intro of this article says, it's possible to disable GC, but you loose most of the libraries, which is one of the strengths of Nim.
Tiberium · 5 years ago
It can, ARC is really not a full-blown GC (people usually associate GC with a tracing garbage collector which ARC is not). ARC is fully suitable for writing any low-level stuff such as OSes and similar.