News for hackers. Stuff that matters.
Re:Zig, parser combinators, and why they're awesome by FlashBlaze on Wednesday March 10, 2021 @10:07PM (#26419731)
Would very much like to read your thoughts on V[0]

[0] https://vlang.io/

Re:Zig, parser combinators, and why they're awesome by lhorie on Wednesday March 10, 2021 @11:10PM (#26420104)
Honestly, I was put off by the early marketing hullabaloo, so I haven't looked closely. What's most problematic in my mind is that from what I've seen, I don't feel that the V lead is as forthcoming about issues and limitations as other project leads are. I'd much rather talk to a project lead that will give it to me straight if their stuff doesn't work.

From a technical perspective, my understanding is that V similar to Nim, in the sense that it compiles to C source code. That's fine and all, but IMHO, zig has a huge leg up in this area because it does first class cross compilation of C source code to binary form. To my knowledge, no other tool does this (other than maybe cosmopolitan, if you ignore everything outside posix...)

If I were to use V, I'd probably end up using `zig cc` as the `cc` for it

Re:Zig, parser combinators, and why they're awesome by lelanthran on Thursday March 11, 2021 @09:44AM (#26424484)
> zig has a huge leg up in this area because it does first class cross compilation of C source code to binary form.

What's the advantage of this? Compilation speed?

Doesn't that then mean that zig can't gain compiler improvements the way using an external compiler can? For example, if C is the intermediate language for $HIGH-LEVEL-LANGUAGE, then $HLL benefits every time that the specific C compiler being used is upgraded.

Re:Zig, parser combinators, and why they're awesome by lhorie on Thursday March 11, 2021 @11:03AM (#26425453)
The advantage is cross compilation. Gcc and friends are notoriously difficult to setup for cross compilation (so much so that some don't even bother trying and either only offer source or just compile from different machines running the target platforms, and even this can be a bit of an ordeal)

Zig uses LLVM under the hood so it does benefit from LLVM upgrades. Also, there's devils in the details. For example, the copy ellision thing is something that required deliberate implementation; it doesn't just come for free if you're naively emitting C.

Re:Zig, parser combinators, and why they're awesome by lelanthran on Thursday March 11, 2021 @01:34PM (#26427328)
Thanks, that's a good answer.

> For example, the copy ellision thing is something that required deliberate implementation; it doesn't just come for free if you're naively emitting C.

I don't know what copy elision is. Can you explain that too?

Re:Zig, parser combinators, and why they're awesome by lhorie on Thursday March 11, 2021 @03:15PM (#26428482)
You can read more about it here: https://github.com/ziglang/zig/issues/2765
Re:Zig, parser combinators, and why they're awesome by MaxBarraclough on Thursday March 11, 2021 @06:57AM (#26423087)
How does V handle reference cycles?

> Most objects (~90-100%) are freed by V's autofree engine: the compiler inserts necessary free calls automatically during compilation. Remaining small percentage of objects is freed via reference counting.

> The developer doesn't need to change anything in their code. "It just works", like in Python, Go, or Java, except there's no heavy GC tracing everything or expensive RC for each object.

So how does V handle reference cycles? A partial solution based on static-analysis (autofree) isn't going to catch all reference cycles, by definition, and automatic reference-counting won't catch reference-cycles either.

I have to agree with lhorie's comment: I get the impression I'm only getting half the story.

The Nim folks also often seem to skim over the question of reference cycles.

Re:Zig, parser combinators, and why they're awesome by cb321 on Thursday March 11, 2021 @07:54AM (#26423450)
If the Nim folks seem to skim over this, it is probably because of the large diversity of options & concerns. You can --gc:none or --gc:arc to blow off the reference cycle problem, but the default gc handles it fine (and --gc:orc and --gc:markAndSweep and --gc:boehm and ...). Here is a nice, recent blog post about ORC [1].

So, in this case the skimming is just an "abbreviated story" which seems reasonable when the full story is long (the Nim project has been around since before 2008...).

For V, well it did have a huge initial hype/propaganda cycle and is also quite young, and I believe the V author made a bunch of extreme claims before publicly releasing the code for scrutiny/corroboration. So, that may be much more suspicious.

[1] https://nim-lang.org/blog/2020/12/08/introducing-orc.html

Re:Zig, parser combinators, and why they're awesome by MaxBarraclough on Thursday March 11, 2021 @09:59AM (#26424640)
You're right, ORC does look interesting, I was too dismissive. Their conventional GCs are way behind the state of the art though (e.g. in HotSpot), but I don't really blame them for that, implementing a cutting-edge GC is an mammoth task and extremely technically demanding.

From your linked article:

> it turns out there are lots of ideas that the GC research overlooked. Exciting times for Nim!

I wish them luck, this is a field where great progress has been made over the last decade, hopefully more to come. If they really can beat the JVM head-on, that would be very impressive, especially if they do so while using C as an intermediate language.

Re:Zig, parser combinators, and why they're awesome by cb321 on Thursday March 11, 2021 @10:20AM (#26424918)
Something often overlooked in comparisons is "The many dimensions of beat". In some ways ORC probably already beats the best JVM while in others it may never. The best benchmark is, as always, one's own code. :-) I've found Nim quite efficient, though.

The one time when I had trouble with Nim's GC perf was years ago implementing Wolfe Garbe's Symmetric Delete spell checking algorithm [0]. Even then, it worked with nim c --gc:boehm but blew up with others. So, there was nothing stopping me from doing it in Nim. This was my initial "in volatile RAM" solution before I went to a fully persistent on-disk memory mapped solution [1]. SymDel is an algorithm particularly demanding of prog.lang run-time basics as explained in that link. I've come to think of it as a good stress test. { Not the only one, of course :-) } I wonder how well Java's GCs would fare.

[0] https://github.com/wolfgarbe/symspell

[1] https://github.com/c-blake/suggest