Live data from Hacker News

Thoughts on Go vs. Rust vs. Zig

sinclairtarget.com

421–430 of 599 posts

Re: Thoughts on Go vs. Rust vs. Zig

#421
post #412

Earlier quoted context omitted.

Given the constraints I still haven’t seen an asynchronous proposal for Rust that would do things differently. Keep in mind that one requirement is being able to create things like Embassy. https://github.com/embassy-rs/embassy

I agree, I think they should have delayed it. In a different universe rust still does not have async and in 5 years it might get an ocaml-style effect system.

And in that universe Rust is likely an inconsequential niche language.

Re: Thoughts on Go vs. Rust vs. Zig

#422
Aside from right tool I’d add two more criteria.

1) Complementary tools. I picked python and rust for obvious reasons given their differences

2) Longevity. Rust in kernel was important to me because it signaled this isn’t going anywhere. Same for rust invading the tool stacks of various other languages and the rewrite everything in rust. I know it irritates people but for me it’s a positive signal on it being worth investing time into

Re: Thoughts on Go vs. Rust vs. Zig

#423
post #376

Earlier quoted context omitted.

No, Zig's error handling is decent - you either return an error or a value and you have some syntactic sugar to handle it. It's pretty cool, especially given the language's low-level domain. Meanwhile Go's is just multiple value-returns with no checks whatsoever and you can return both a valid value and an error.

But sometimes it is useful to return both a value and a non-nil error. There might be partial results that you can still do things with despite hitting an error. Or the result value might be information that is useful with or without an error (like how Go's ubiquitous io.Writer interface returns the number of bytes written along with any error encountered). I appreciate that Go tends to avoid making limiting assumpti…

Then just return a value representing what you want, instead of breaking a convention and hacking something and hoping that at use site someone else has read the comment.

Also, just let the use site pass in (out variable, pointer, mutable object, whatever your language has) something to store partial results.

Re: Thoughts on Go vs. Rust vs. Zig

#424
post #376

Earlier quoted context omitted.

No, Zig's error handling is decent - you either return an error or a value and you have some syntactic sugar to handle it. It's pretty cool, especially given the language's low-level domain. Meanwhile Go's is just multiple value-returns with no checks whatsoever and you can return both a valid value and an error.

But sometimes it is useful to return both a value and a non-nil error. There might be partial results that you can still do things with despite hitting an error. Or the result value might be information that is useful with or without an error (like how Go's ubiquitous io.Writer interface returns the number of bytes written along with any error encountered). I appreciate that Go tends to avoid making limiting assumpti…

But in most cases you probably want something disjoint like Rust's `Result`. In case of "it might be success with partial failure", you could go with unnamed tuples `(Option,E)` or another approach.

Re: Thoughts on Go vs. Rust vs. Zig

#425
post #222

Earlier quoted context omitted.

> languages where "trivial" things "just require" rapidly become "not so trivial" in the aggregate Sure. And in C and Zig, it's "trivial" to make a global mutable variable, it "just requires" you to flawlessly uphold memory access invariants manually across all possible concurrent states of your program. Stop beating around the bush. Rust is just easier than nearly any other language for writing concurrent programs,…

This is a miscommunication between the values of “shipping” which optimizes for fastest time to delivery and “correctness” which optimizes for the quality of the code. Rust makes it easy to write correct software quickly, but it’s slower for writing incorrect software that still works for an MVP. You can get away with writing incorrect concurrent programs in other languages… for a while. And sometimes that’s what bus…

In an ideal world, where computing software falls under the same liability laws as everything else, there is no shipping without correctness.

Unfortunately too many people accept using computers requires using broken produts, something that most people would return on the same day with other kind of goods.

Re: Thoughts on Go vs. Rust vs. Zig

#426
post #214
post #29

> In Rust, creating a mutable global variable is so hard that there are long forum discussions on how to do it. In Zig, you can just create one, no problem. Well, no, creating a mutable global variable is trivial in Rust, it just requires either `unsafe` or using a smart pointer that provides synchronization. That's because Rust programs are re-entrant by default, because Rust provides compile-time thread-safety. If…

> [...] is trivial in Rust [...] it just requires [...] This is a tombstone-quality statement. It's the same framing people tossed around about C++ and Perl and Haskell (also Prolog back in the day). And it's true, insofar as it goes. But languages where "trivial" things "just require" rapidly become "not so trivial" in the aggregate. And Rust has jumped that particular shark. It will never be trivial, period.

Well-designed programming languages should disincentivize from following a wrong practice and Rust is following the right course here.

Re: Thoughts on Go vs. Rust vs. Zig

#427

Earlier quoted context omitted.

ah i see, thanks. i have no idea what rust code looks like but from the article it sounds like a language where you have a lot of metadata about the intended usage of a variable so the compiler can safety check. thats its trick.

That's a fairly accurate idea of it. Some folks complain about Rust's syntax looking too complex, but I've found that the most significant differences between Rust and C/C++ syntax are all related to that metadata (variable types, return types, lifetimes) and that it's not only useful for the compiler, but helps me to understand what sort of data libraries and functions expect and return without having to read throug…

I think you’re misconstruing the argument. Those of us that dislike the rust syntax feel at least that strongly about c++. They’re both disasters.

Re: Thoughts on Go vs. Rust vs. Zig

#428

Earlier quoted context omitted.

I pretty new to Rust and I’m wondering why global mutables are hard? At first glance you can just use static variable of a type supporting interior mutability - RefCell, Mutex, etc…

That is correct. Kinda. Refcell can not work because Rust considers globals to be shared by multiple threads so requires thread safety. And that’s where a number of people blow a gasket.

A second component is that statics require const initializers, so for most of rust’s history if you wanted a non-trivial global it was either a lot of faffing about or using third party packages (lazy_static, once_cell).

Since 1.80 the vast majority of uses are a LazyLock away.

Re: Thoughts on Go vs. Rust vs. Zig

#429

The reason I really like Zig is because there's finally a language that makes it easy to gracefully handle memory exhaustion at the application level. No more praying that your program isn't unceremoniously killed just for asking for more memory - all allocations are assumed fallible and failures must be handled explicitly. Stack space is not treated like magic - the compiler can reason about its maximum size by exam…

I suggest studying the history of systems programming languages since JOVIAL in 1958, before praising Zig of being a first in anything.

Re: Thoughts on Go vs. Rust vs. Zig

#430

Earlier quoted context omitted.

I don't know Zig. The article says "Many people seem confused about why Zig should exist if Rust does already." But I'd ask instead why does Zig exist when C does already? It's just a "better" C? But has the drawback that makes C problematic for development, manual memory management? I think you are better off using a language with a garbage collector, unless your usage really needs manual management, and then you ca…

yeah, its a better c, but like wouldnt it be nice if c had stadardized fat pointers so that if you move from project to project you don't have to triple check the semantics? for example and like say 50+ "learnings" from 40 years c that are canonized and first class in the language + stdlib

What to say from WG14, when even one of C authors could not make it happen?

Notice how none of them kept involved with WG14, just did their own thing with C in Plan 9, and with Inferno, C was only used for the kernel, with everything else done in Limbo, finalizing by minor contributions to Go's first design.

People that worship UNIX and C, should spend some time learning that the authors moved on, trying to improve the flaws they considered their original work suffered from.

Post reply on HN