Live data from Hacker News

Thoughts on Go vs. Rust vs. Zig

sinclairtarget.com

411–420 of 599 posts

Re: Thoughts on Go vs. Rust vs. Zig

#411
post #55

Earlier quoted context omitted.

> For Go, I wouldn't say that the choice to avoid generics was either intentional or minimalist by nature. From what I recall, they were just struggling for a long time with a difficult decision, which trade-offs to make. Indeed, in 2009 Russ Cox laid out clearly the problem they had [1], summed up thus: > The generic dilemma is this: do you want slow programmers, slow compilers and bloated binaries, or slow executio…

Ironically, the latest research by Google has now conclusively shown that Rust programmers aren't really any "slower" or less productive than Go programmers. That's especially true once you account for the entire software lifecycle, including production support and maintenance.

In this context, the the "slow programmer" option was the "no generics" option (i.e., C, and Go before 1.18) -- that is, the programmer has to re-implement code for each separate type, rather than being able to implement generic code once. Rust, as I understand it, followed C++'s path and chose the "slow compile time and bloated binaries" option (in order to achieve an optimized final binary). They call it "zero cost abstractions", but it's really moving the cost from runtime to compile time. (Which, as TFA says, is a tradeoff.)

Re: Thoughts on Go vs. Rust vs. Zig

#412
post #320

Earlier quoted context omitted.

It they had not messed up async it would be much better

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.

Re: Thoughts on Go vs. Rust vs. Zig

#413

Earlier quoted context omitted.

I'm in a similar place, but my stack is Python->Go With Python I can easily iterate on solutions, observe them as they change, use the REPL to debug things and in general just write bad code just to get it working. I do try to add type annotations etc and not go full "yolo Javascript everything is an object" -style :) But in the end running Python code on someone else's computer is a pain in the ass, so when I'm done…

Is there a good resource on how to get better at python prototyping? The typing system makes it somewhat slow for me and I am faster prototyping in Go then in Python, despite that I am writing more Python code. And yes I use type annotations everywhere, ideally even using pydantic. I tend to use it a lot for data analytics and exploration but I do this now in nushell which holds up very well for this kind of tasks.

Just do it I guess? :D

When I'm receiving some random JSON from an API, it's so much easier to drop into a Python REPL and just wander around the structure and figure out what's where. I don't need to have a defined struct with annotations for the data to parse it like in Go.

In the first phase I don't bother with any linters or type annotations, I just need the skeleton of something that works end to end. A proof of concept if you will.

Then it's just iterating with Python, figuring out what comes in and what goes out and finalising the format.

Re: Thoughts on Go vs. Rust vs. Zig

#414
post #2

> Many people seem confused about why Zig should exist if Rust does already. It’s not just that Zig is trying to be simpler. I think this difference is the more important one. Zig wants you to excise even more object-oriented thinking from your code. I feel like Zig is for the C / C++ developers that really dislike Rust. There have been other efforts like Carbon, but this is the first that really modernizes the langu…

One question about your functional point: where can I learn functional programming in terms of organization of large codebases? Perhaps it is because DDD books and the like usually have strong object oriented biases, but whenever I read about functional programming patterns I’m never clear on how to go from exercise stuff to something that can work in a real world monolith for example. And to be clear I’m not saying…

This seems good: https://www.youtube.com/watch?v=WRoYKBXWJes

Re: Thoughts on Go vs. Rust vs. Zig

#415

Earlier quoted context omitted.

To be fair, you can enforce this just by filling all the allocated memory with zero, so it's possible to fail at startup. Or, even simpler, just turn off over-commit. But if swap comes into the mix, or just if the OS decides it needs the memory later for something critical, you can still get killed.

I would be suprised if some os detects the page of zeros and removes that allocation until you need it. this seems like a common enough case as to make it worth it when memory is low. I'm not aware of any that do, but it wouldn't be that hard and so seems like someone would try it.

There's also KSM, kernel same-page merging.

Re: Thoughts on Go vs. Rust vs. Zig

#416
post #334

Earlier quoted context omitted.

If I created a new programming language I would just outright prohibit mutable global variables. They are pure pure pure evil. I can not count how many times I have been pulled in to debug some gnarly crash and the result was, inevitably, a mutable global variable.

Not really possible in a systems level programming language like rust/zig/C. There really is only one address space for the process... and if you have the ability to manipulate it you have global variables. There's lots of interest things you could do with a rust like (in terms of correctness properties) high level language, and getting rid of global variables might be one of them (though I can see arguments in both…

> Not really possible in a systems level programming language like rust/zig/C. There really is only one address space for the process... and if you have the ability to manipulate it you have global variables.

doesn't imply you have to expose it as a global mutable variable

Re: Thoughts on Go vs. Rust vs. Zig

#417
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,…

> it "just requires" you to flawlessly uphold memory access invariants manually across all possible concurrent states of your program. No it doesn't. Zig doesn't require you to think about concurrency at all. You can just not do concurrency. > Stop beating around the bush. Rust is just easier than nearly any other language for writing concurrent programs This is entirely unrelated to the problem of defining shared gl…

> This is entirely unrelated to the problem of defining shared global state

In it's not. The only thing that makes having a shared global state unsafe in Rust is the fact that this “global” state is shared across threads.

If you know you want the exact same guarantees as in Zig (that is code that will work as long as you don't use multiple threads but will be UB if you do) then it's just: static mut x: u64 = 0;

The only difference between Zig and Rust being that you'll need to wrap access to the shared variable in an unsafe block (ideally with a comment explaining that it's safe as long as you do it from only one thread).

See https://doc.rust-lang.org/nightly/reference/items/static-ite...

Re: Thoughts on Go vs. Rust vs. Zig

#418

Earlier quoted context omitted.

If I created a new programming language I would just outright prohibit mutable global variables. They are pure pure pure evil. I can not count how many times I have been pulled in to debug some gnarly crash and the result was, inevitably, a mutable global variable.

> They are pure pure pure evil. They are to be used with caution. If your execution environment is simple enough they can be quite useful and effective. Engineering shouldn't be a religion. > I can not count how many times I have been pulled in to debug some gnarly crash and the result was, inevitably, a mutable global variable. I've never once had that happen. What types of code are you working on that this occurs s…

> If your execution environment is simple enough they can be quite useful and effective

Saud by many an engineer whose code was running in systems that were in fact not that simple!

What is irksome is that globals are actually just kinda straight worse. Like the code that doesn't use a singleton and simply passes a god damn pointer turns out to be the simpler and easier thing to do.

> What types of code are you working on that this occurs so frequently?

Assorted C++ projects.

It is particularly irksome when libraries have globals. No. Just no never. Libraries should always have functions for "CreateContext" and "DestroyContext". And the public API should take a context handle.

Design your library right from the start. Because you don't know what execution environments will run in. And it's a hell of a lot easier to do it right from the start than to try and undo your evilness down the road.

All I want in life is a pure C API. It is simple and elegant and delightful and you can wrap it to run in any programming environment in existence.

Re: Thoughts on Go vs. Rust vs. Zig

#419
post #60

> In Go, a slice is a fat pointer to a contiguous sequence in memory, but a slice can also grow, meaning that it subsumes the functionality of Rust’s Vec type and Zig’s ArrayList. Well, not exactly. This is actually a great example of the Go philosophy of being "simple" while not being "easy". A Vec has identity; the memory underlying a Go slice does not. When you call append(), a new slice is returned that may or ma…

> There's also no way to shrink the memory underlying a slice. Sorry, that is incorrect: https://pkg.go.dev/slices#Clip > It's a common newbie mistake to think they do work like that, and write "append(s, ...)" instead of "s = append(s, ...)". It might even randomly work a lot of the time. "append(s, ...)" without the assignment doesn't even compile. So your entire post seems like a strawman? https://go.dev/play/p/ic…

Does clipping make the rest eligible for GC?

Clipping doesn't seem to automatically move the data, so while it does mean appending will reallocate, it doesn't actually shrink the underlying array, right?

Re: Thoughts on Go vs. Rust vs. Zig

#420
post #49

I could never get into zig purely because of the syntax and I know I am not alone, can someone explain the odd choices that were taken when creating zig? the most odd one probably being 'const expected = [_]u32{ 123, 67, 89, 99 };' and the 2nd most being the word 'try' instead of just ? the 3rd one would be the imports and `try std.fs.File.stdout().writeAll("hello world!\n");` is not really convincing either for a ba…

I will never understand people bashing other languages for their syntax and readability and then saying that they prefer Rust. Async Rust is the ugliest and least readable language I've ever seen and I've done a lot of heavily templated C++

I will never understand people who bash someone's preference of a language after claiming they don't understand people who bash other languages for their syntax. Turns out language syntax preferences are subjective and most likely not black and white.

For example, Pythons syntax is quite nice for the most part, but I hate indentation being syntax. I like braces for scoping, I just do. Rust exists in both camps for me; I love matching with Result and Option, but lifetime syntax confuses me sometimes. Not everyone will agree, they are opinions.

Post reply on HN