Live data from Hacker News

Thoughts on Go vs. Rust vs. Zig

sinclairtarget.com

571–580 of 599 posts

Re: Thoughts on Go vs. Rust vs. Zig

#571
post #215

Earlier quoted context omitted.

> How so? Garbage collection has inherent performance overhead wrt. manual memory management, and Rust now addresses this by providing the desired guarantees of managed memory without the overhead of GC. I somewhat disagree, specifically on the implicit claim that all GC has overhead and alternatives do not. Rust does a decent job of giving you some ergonomics to get started, but it is still quite unergonomic to fix…

> I somewhat disagree, specifically on the implicit claim that all GC has overhead and alternatives do not. Not a claim I made. Obviously there are memory management styles (such as stack allocation, pure static memory or pluggable "arenas"/local allocators) that are even lower overhead than a generic heap allocator, and the Rust project does its best to try and support these styles wherever they might be relevant, e…

I agree precise tracing GC's are a huge mess of integration so making them pluggable is likely a pain. I think I'm fairly down on the notion of tracing GC's though and I'd rather have other lifetime tracking mechanisms.

Re: Thoughts on Go vs. Rust vs. Zig

#572
post #554
post #545

Earlier quoted context omitted.

This is completely different from the previous example. It doesn't increment anything for starters. The example would be more convoluted if it did the same thing. And strings in rust always delivers the WTFs I need o na Friday: "hello world".to_string()

use std::sync::Mutex; fn main() -> Result > { static PEDANTRY: Mutex = Mutex::new(0); *PEDANTRY.lock()? += 1; println!("{}", PEDANTRY.lock()?); Ok(()) }

Still different. Yours only increments once. Doesn't pass basic QA.

And declaring a static variable inside a function, even if in main, smells.

Re: Thoughts on Go vs. Rust vs. Zig

#573
post #572
post #554

Earlier quoted context omitted.

use std::sync::Mutex; fn main() -> Result > { static PEDANTRY: Mutex = Mutex::new(0); *PEDANTRY.lock()? += 1; println!("{}", PEDANTRY.lock()?); Ok(()) }

Still different. Yours only increments once. Doesn't pass basic QA. And declaring a static variable inside a function, even if in main, smells.

OP you keep comparing to doesn't even declare the variable. I'm done with you.

Re: Thoughts on Go vs. Rust vs. Zig

#575
post #573
post #572

Earlier quoted context omitted.

Still different. Yours only increments once. Doesn't pass basic QA. And declaring a static variable inside a function, even if in main, smells.

OP you keep comparing to doesn't even declare the variable. I'm done with you.

OP here, not showing how to declare the variable was an oversight on my part.

  static mut COUNTER: u32 = 0;
(at top-level)

If on 2024 edition, you will additionally need

  #![allow(static_mut_refs)]

Re: Thoughts on Go vs. Rust vs. Zig

#576
post #573

Earlier quoted context omitted.

OP you keep comparing to doesn't even declare the variable. I'm done with you.

OP here, not showing how to declare the variable was an oversight on my part. static mut COUNTER: u32 = 0; (at top-level) If on 2024 edition, you will additionally need #![allow(static_mut_refs)]

Yup, your example was fine, as I said I just wanted to show a safe method too :-)

Re: Thoughts on Go vs. Rust vs. Zig

#577
post #485

Earlier quoted context omitted.

Out of all those only Java and Kotlin captured significant market like OP mentioned

Those two aren’t natively compiled. They can be, but it’s not the norm, and it’s hard/time consuming. Java’s type system isn’t as strong as it could be either. It is still lacking proper compile time support for null and there’s been no investment in making error handling better. I’ve written it every day for 10 years and the type system definitely doesn’t help you write correct programs.

> Those two aren’t natively compiled

Idk how up to date ou are in .NET but so you can have an idea how trivial it is in C#:

   echo ‘Console.WriteLine(“hello world”);’ >> app.cs
   dotnet publish app.cs

That’s it. By default C# is natively compiling.

Re: Thoughts on Go vs. Rust vs. Zig

#578

I've been using Zig for few days. And my gotchas so far: - Can't `for (-1..1) {`. Must use `while` instead. - if you allocated something inside of a block and you want it to keep existing outside of a block `defer` won't help you to deallocate it. I didn't find a way to defer something till the end of the function. - adding variable containing -1 to usize variable is cumbersome. You are better of running everything w…

I don't know if that's just aged noob in me speaking but so far, while Rust has "zero cost abstractions", Zig feels like it has "Zero abstractions". Deallocating the wrong thing or the right thing too soon bit me in th ass so much already that I feel craving for destructors.

Rust is not zero cost abstractions, they make decision on case-by-case basis.

Re: Thoughts on Go vs. Rust vs. Zig

#579

Earlier quoted context omitted.

How is that an error if b is properly referenced? It’s perhaps a waste of memory but not wrong

Because `append` works in-place, Go slices are amortised, and the backing buffer is shared between `a` and `b`, so unless you never ever use a again it likely will have strange effects e.g. a := make([]int, 0, 5) a = append(a, 0, 0) b := append(a, 1) a = append(a, 0) fmt.Println(b) prints [0 0 0] because the following happens: a := make([]int, 0, 5) // a = [() _ _ _ _ _] // a has length 0 but the backing buffer has c…

Thanks for the thorough explanation!

Re: Thoughts on Go vs. Rust vs. Zig

#580
post #214

Earlier quoted context omitted.

> [...] 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.

"wrong practice" i always get the impression that rust is an authoratian language that thinks it knows how programming should be done.
Post reply on HN