r/programming 8d ago

What Zig felt like, coming from Rust

https://besok.github.io/posts/what-zig-felt-like-coming-from-rust/
263 Upvotes

173 comments sorted by

186

u/ParadiZe 8d ago

Im a Rust guy and i really enjoy zig, but the subpar tooling and lack of documentation ultimately prevented it from being my "main" language. But im rooting for it and im excited to see where its going!

123

u/VictoryMotel 8d ago

I'm sure the super toxic community that has "get good" as an answer to every problem will get right on that tooling problem.

49

u/solidiquis1 8d ago

Is is really that bad over there?

134

u/VictoryMotel 8d ago edited 8d ago

They intentionally made a windows version then had it error out on windows newlines. Then zig users' answer was "don't use windows, use a preprocessor, too complicated to parse newlines". It was bizarre.

It seems to have attracted people who are upset at programming and want some sort of culture war stuff instead of just trying to solve problems.

I like small binaries and fast compilation as much as anyone, but I think when C gets defer zig won't have much of a technical advantage.

I would still use rust or C++, despite the compile times and unnecessary complexity, there is too much being left behind.

79

u/veverkap 8d ago

The creator of the language has willed the toxicity into existence

43

u/butt_fun 8d ago

Which is honestly really sad. I've been following the Zig development since almost the beginning, and seeing the bright-eyed-and-bushy-tailed optimism erode into how things are today is a little depressing

9

u/The_Shryk 8d ago

Odin it is…

3

u/MediocreAnalyst2121 7d ago

Unfortunately I can’t get over the syntax of Odin

3

u/HolySpirit 7d ago

Really? What about it?

I don't use Odin, but from skimming it's overview/reference, the syntax looked fairly minimal and pleasant to me.

7

u/renatoathaydes 6d ago

It’s Go inspired, not C, which for some people is an insurmountable barrier.

7

u/cdb_11 8d ago

I tried looking it up, and CRLF is supported, but just plain CR is not? I believe the problem is multi-line strings, where it's not obvious if CRLF should be kept or converted to LF or what

11

u/Dragdu 7d ago

It was changed after much drama.

5

u/VictoryMotel 8d ago

I think it was changed but I think the issue was just erroring on carriage return. It could have just been ignored.

-2

u/cdb_11 8d ago

It can be ignored for normal code, and it is ignored AFAIK. But you can't just ignore it inside strings. The compiler has to either keep the line endings as is (and you can't tell just by reading the source code), or convert all of them to LF.

7

u/VictoryMotel 7d ago

But you can't just ignore it inside strings.

No one is ever saying anything different.

1

u/loup-vaillant 7d ago

Then you understand the dilemma caused by multiline strings:

  1. Allow any line ending, carry them into the string. Problem: visually identical source code has different semantics.
  2. Allow any line ending, convert to a specific line ending. Problem: which one? Presumably \n, but some Windows users may still expect \r\n on Windows systems. And I'm pretty sure we don't want to even consider having the blessed line ending be system dependent.
  3. Only allow one line ending. Problem: it's annoying on some systems (some editors, really). But at least it's clear what's happening.

It could have just been ignored.

Option (1), then. You sure about that?

7

u/Dragdu 5d ago

This is complete non-issue. Do what other languages do; fold newlines in source files into \n, fold into platform's newline on output. Multiline strings get \n, only raw strings keep specific encoding.

→ More replies (0)

4

u/VictoryMotel 7d ago

You're talking about specifics of what happens inside quotes. Different languages handle these situations differently and you can pick and choose your favorite if you want to proclaim something to be superior.

What no language does is error out in general parsing on default windows text, which is what this thread is about.

You sure about that?

You sure you've followed this conversation properly?

→ More replies (0)

1

u/Ravek 7d ago

Who cares about following the Unicode standard, right?

-14

u/phylk 8d ago edited 8d ago

Any text editor supports unix line endings, even notepad since windows 10. It is to ensure one canonical style for zig source files, not to troll windows users. Same reason it must be indented with spaces not tabs (though I disagree with that choice).

22

u/QuaternionsRoll 8d ago

Are you sure you know what canonical means?

27

u/VictoryMotel 8d ago

Here we go again with someone trying to justify this nonsense.

Any text editor supports unix line endings, even notepad since windows 10.

And every language ever made parses windows newlines just fine.

It is to ensure one canonical style for zig source files,

Absolute bullshit. There is no reason not to do it and the response of making users jump through hoops is always telling.

Same reason it must be indented with spaces not tabs

And you agree with not parsing windows newlines? Treating tabs as whitespace is trivial, it's another dig at people doing something different. Why not make it an option instead of a default?

-17

u/phylk 8d ago

Every decision has tradeoffs. You may not agree with this one, but the only one being toxic here is you for assuming malice when there is none.

14

u/VictoryMotel 8d ago

There are no tradeoffs here or you would have been able to explain at least one. I didn't assume malice, I saw that it was malice when people responded with bizarre rationalizations and liked that it was broken.

7

u/Ameisen 8d ago

It's either malice or incompetence, and they're asserting that it's actually sound design, which suggests more malice or incompetence.

By requiring Unix newlines, they're violating decades of conventions and standards.

1

u/VictoryMotel 8d ago

That's exactly it, when people start lying about their defense of something and making ridiculous claims it ends up being like someone desperately trying to defend their team, religion etc and technical arguments not only go out the window, people won't agree on reality.

16

u/shadowndacorner 8d ago

"I'm not toxic you're toxic" ass response lmao

9

u/HungYurn 8d ago

what is the benefit that comes with those tradeoffs?

9

u/spicy_indian 8d ago

I've had pretty good luck getting reasonable answers to questions in their Discord.

-16

u/nnomae 8d ago

If you're working off of the development builds, which almost everyone does the expectation is that stuff breaks and you'll need to fig sure it out yourself. They're quite up front about that. It seems weird that people using systems programming languages would find that a problem to be honest. That's the job of a system programmer. Once they hit 1.0 I'm sure that'll change but that's the expectation of pre-release software.

-3

u/OSS-Corpo-Shit 7d ago

No. The community is extremely welcoming and helpful. No idea what that dude is on about. 

3

u/renatoathaydes 6d ago

Everyone has different experiences. I had some good ones but also got someone telling me it’s on me that I was using a function wrong and I should have read the source code. All I wanted was to list a directory’s children, and IIRC you needed to pass an option like .for iteration=true when opening a directory and I was trying to say this should be the default as it’s the most likely thing to do when you open a dir. But they got upset at me. I think they eventually did change that.

6

u/CT4nk3r 8d ago

they really feel like what stackoverflow became in its last years

-12

u/jan-pona-sina 8d ago

That's not true at all. The Zig language and the community demand some degree of competence from programmers. Zig also doesn't cater to every workflow. That doesn't make it toxic, it's just not a one-size-fits-all philosophy

24

u/VictoryMotel 8d ago

That's a very generous reframing of reality, but making a windows version then intentionally making it error on windows newlines to troll your own users is the definition of toxicity.

-1

u/jan-pona-sina 8d ago

I've used Zig on windows and I simply didn't have any issue with unix newlines? I did the same in C and python, the main programming languages I use otherwise. I don't understand what is toxic about this decision.

7

u/VictoryMotel 8d ago

Here it comes, we'll get to see all the same nonsense play out in real time.

I've used Zig on windows and I simply didn't have any issue with unix newlines?

Are you asking? You might have missed the point, it only works with unix newlines, unlike every other language ever made.

I don't understand what is toxic about this decision.

You don't understand what is toxic about making a windows version, making it error on default text, then telling people not to use windows or to reconfigure their text editor? What other language has ever done this? Why would this be good for users?

0

u/jan-pona-sina 8d ago

I configured my editor(s) to save files with unix newlines. I used a question mark because I am confused about the problem.

It's not for users directly, it's to aid in collaboration with version control. When collaborating on code, someone saving a file on one operating system can trigger a diff for an entire file. This is a pain for code review, one I encountered before I used Zig. Many a style guide expects this.

Clearly, you don't want to use unix newlines. Again, Zig isn't catering to everyone. I think it's bad faith to treat the language's opinionated nature as toxicity. If you really can't stomach unix newlines, you probably have other opinions that will conflict with Zig.

14

u/VictoryMotel 8d ago edited 8d ago

I configured my editor(s) to save files with unix newlines

The problem is that you would have to

It's not for users directly,

It hurts them directly

it's to aid in collaboration with version control.

No it wasn't, because when it happened, no one, including the creator gave this as a reason, then eventually it was changed. This is something you are making up now as a rationalization. If that were true it would be optional and wouldn't have eventually been fixed.

This is a pain for code review,

It's nonsense to enforce this by erroring out your language.

No other language has ever done this.

"Maybe you should use a preprocessor", "maybe you should configure your text editor" were what people told me, and both those things could apply.

Clearly, you don't want to use unix newlines

It has nothing to do with that. "Bad faith" is purposely misrepresenting what's being said. The problem is creating road blocks then self righteously acting like users are in the wrong for running into them. It's an insane and toxic way to make a tool.

I think it's bad faith to treat the language's opinionated nature as toxicity

I think it's bad faith to act like it's not the backwards rationalizations and toxic responses that are the problem.

If you really can't stomach unix newlines,

Bad faith toxicity, not what anyone is saying.

you probably have other opinions that will conflict with Zig.

My issues are with the people surrounding it. Any other language would acknowledge that intentionally tripping people up with newlines and tabs is corrosive to anyone trying to get things done.

-5

u/dronmore 7d ago

The little princess cannot configure her text editor? Is that all the yapping about?

jan-pona-sina is right. In mixed environments, where people use different operating systems, you still have to agree on common line endings, and most of the time it will be LF. Line endings is the least of the issues with Zig, and in my opinion it's a non-issue. Your entitlement to CRLF newlines is more alarming then the lack of support for CRLF in Zig. If I were to choose, to work with you, or to work with Zig, I would choose neither. Get your self an .editorconfig, and give me a break.

5

u/Ameisen 8d ago

Clearly, you don't want to use unix newlines. Again, Zig isn't catering to everyone. I think it's bad faith to treat the language's opinionated nature as toxicity. If you really can't stomach unix newlines, you probably have other opinions that will conflict with Zig.

It literally takes extra work to not properly support new-lines.

I don't make a habit of performing extra work just to fuck over people. If you do, you're a dick.

4

u/jan-pona-sina 8d ago

What part of not supporting windows newlines "fucks people over," in your words? I'm really just trying to understand, I don't get the vitriol over this

4

u/MEaster 7d ago

Claiming you support a platform then going out of your way to not work with that platform's standards is a dick move. How is that hard to understand?

→ More replies (0)

2

u/ComprehensiveWord201 8d ago

Ah so it sucks for all the same reasons that C and C++ do

45

u/teerre 8d ago

C and C++ have the most documentation of any language? Whole libraries are written about them. It's not even remotely close

8

u/ComprehensiveWord201 8d ago

I have been writing C++ professionally for 8 years. The language docs and the entire ecosystem sucks dick. Build tooling is the worst by far.

17

u/teerre 8d ago

Of course you're free to think you want. But that are a couple things in C++ that are universally considered excellent. cppreference is certainly one of them

1

u/QuarkCreator2610 8d ago

You cant look at a page of C++ documentation and understand what they are trying to convey so it kinda beats the purpose

20

u/teerre 8d ago

What? cppreference is literally the gold standard for references

33

u/XtremeGoose 8d ago edited 8d ago

cppreference is incomprehensible gibberish to anyone who isn't already a seasoned cpp developer.

Compare the c++ vector docs to the rust ones.

It's night and day. Rust actually explains up front what it is, how to use it, gives examples. C++ does kind of do that, but not in a way that's helpful to someone just starting, and there's so much superfluous crap I shouldn't have to think about (though maybe that's just because the language is a bloated mess). The rust docs read like they are trying to help you rather than trying to be pedantically correct.

Rust docs are the gold standard. I've never seen any other language come close.

10

u/torsten_dev 8d ago

C++ deprecates features a lot more than rust all of the version differences need to be on there, though you can hide some of that if you're logged in.

Also note that Rust can move a lot of the pedantry to functions marked unsafe. Cppreference is both the rust std docs but also by necessity the C++o'nomicon.

These docs are skewed towards more experienced developers, that's true, but that's also what makes them an invaluable resource even after 10+ years of experience.

15

u/Daedalus1907 8d ago

I wouldn't consider myself a seasoned c++ developer and find the cppreference perfectly comprehensible. Maybe if you're fundamentally new to programming, it's hard but I wouldn't expect that to be the expected audience for language docs.

3

u/XtremeGoose 7d ago

I'm definitely not new to programming and I understand it. I think all good developers should be able to have empathy for their audience, and that is true for good documentation. That is why I dislike them.

6

u/Daedalus1907 7d ago

I just don't understand the problem with the documentation; it seems perfectly easy to read for me. Maybe it's an age thing? I grew up with C so a lot of the memory allocation/pointer stuff is ingrained even if I don't use it anymore. Could you explain why you find it difficult to read?

6

u/XtremeGoose 7d ago
  • The actual definition of the type is confusingly put in a numbered list, with reference to advanced topics such as "sequence container", encapsulation, polymorphic allocator, etc
  • It immediately jumps in to talking about iteration, rather than how to build one or how to access elements in it
  • It's never suggested why I might want to use on, just what it is
  • Only 3 methods are linked in the main prose, and not even close to the most important 3
  • A massive section is given up to iterator invalidation, before even discussing how I use it as an iterator
  • Let's say I want to read how to construct one, I click on the constructor docs and get this horror. Up front I have 11 overload definitions, completely separate from their documentation (which again doesn't tell me why I might use it)
  • The example is near the bottom, and is extremely lazy. It shows the absolute minimum of functionality.

They seem to be both way too thin and also way too deep. It reads like it was written by committee (which it was).

→ More replies (0)

5

u/teerre 8d ago

Uh, I cannot tell what you think it's so different between those two. They are the same. Are you talking about the differences in CSS? That's mostly irrelevant

Besides, you seen to be confusing a reference with a learning book or something. A reference is for seasoned developers. There are countless beginners books for C++

1

u/loup-vaillant 7d ago

cppreference is incomprehensible gibberish to anyone who isn't already a seasoned cpp developer.

That's why it is called a reference, instead of a manual or a tutorial. All are valuable, they're just not optimised for the same audiences.

4

u/XtremeGoose 7d ago

This is the rust standard library reference. They fit the same purpose.

There is also the rust language reference, that is different.

1

u/loup-vaillant 7d ago

OK you didn't get my point, so I'll spell it out: references are for seasoned users first and foremost. Getting you to git gud, that a tutorial's job, or a course, or a manual (and that last one often assumes you got the general basics down).

I wouldn't like wasting my time on noob hand holding.

3

u/XtremeGoose 6d ago

Which is why people like the rust community and don't like the c++ community.

The rust std libs show how it's perfectly possible to be both beginner friendly and useful for seasoned developers. You don't need to prioritise experts and tell beginners "git gud".

→ More replies (0)

2

u/QuarkCreator2610 6d ago

Most of my criticism was directed to the code examples though. I think that more than feature documentation itself, the code examples given are exceptionally bad. A lot of them are overly clever and are very misleading as to how to use the feature it showcases or why it exists. Every piece of those code examples is also too tightly coupled to other parts of the standard library. To fully understand an example you often have to look up other a lot other features you don't really want/need to use and those features you look up have other features you don't know so you have to look them up as well.

11

u/torsten_dev 8d ago edited 7d ago

ninja, meson and clang are good tooling. And atleast for C the documentation is good, if you learn a little standardese.

Dependency managers are nice but there's value in keeping transitive dependencies low. So there is some reason in having those be a painful experience.

2

u/Lisoph 8d ago

My thoughts exactly.

51

u/Blashtik 8d ago

The language isn't young at all. It's gotten plenty of breaking changes over the years, but the general design of the language isn't changing.

Also, why did this person entirely skip over error handling beyond the issue with not calling free? Results are a very clean way to deal with errors. The Zig system is basically just a slight improvement over error codes in C. I didn't think this was the biggest deal until I was working with JSON parsing and realized that since the error can't carry any extra info, getting the position of a parse failure requires either storing the error state in the parser and having the caller read it out on an error, or by using an output parameter to hold that info.

After that case I noticed that I was over-simplifying my errors to fit Zig. I was missing useful information that would help understand the reason for errors. If any did arise, it would be as annoying as calling a Windows API and getting ERROR_INVALID_PARAMETER (which parameter is invalid?!)

3

u/hxtk3 8d ago edited 8d ago

I kind of like the Zig error handling. For me the coolest thing about Zig is how easy it is to control allocations. If I don't care about error details and just want to know that something failed, I pass nil to an output parameter and only get a status code back and I'm guaranteed non-allocating error path. I can also pre-allocate space for the errors I care about.

I do think that I would hate to write a large program in Zig, though. I really only like it for small things that are performance-sensitive enough that I want to be able to avoid any post-startup allocations.

I made a utility for relaying a UDP multicast stream into a TCP server that forwards the UDP datagrams as TCP packets to all connected clients with io_uring and zero runtime allocations. It's extremely performant in terms of the memory and CPU utilization per concurrent client and it's relatively easy to beat a Rust Tokio/async version of the same utility in performance because it's easier to look at the code and know when you're writing a performance hotspot. I'd call Zig a good fit for about that size and complexity of program, at least for my personal usage.

(Of course, Rust is fully capable of hitting the exact same performance, but the program would look radically different and you'd end up abandoning async entirely to write roughly the same code as the zig version. If you tried to write idiomatic IO-bound rust, you'd run into a local minimum while optimizing where you had to dramatically restructure the program to optimize more, but it would certainly be doable.)

1

u/skyfex 1d ago

I didn't think this was the biggest deal until I was working with JSON parsing and realized that since the error can't carry any extra info, getting the position of a parse failure requires either storing the error state in the parser and having the caller read it out on an error, or by using an output parameter to hold that info.

The idiomatic way to pass error information like that is through an optional pointer to a struct where you want that information stored. There are many legitimate use-cases where you don't want all that information, in which case you can pass null and all the code related to tracking that should get optimized away.

It's really not a great idea to try to shoe-horn all kinds of error meta-data into a result type or exceptions. Zig errors do one job, and they do it well: force you to consider error conditions for functions that can error. What you do from there is up to you and completely explicit.

I understand the feeling that Zig is too explicit and leave too many things to be done manually. But that's the whole point of the language: to be a fully explicit systems programming language.

157

u/esiy0676 8d ago

Rust has been designed to be error-resistant (junior developers welcome), which a hiring manager likes as they could form quite an unbalanced (cost effective) team and have their team lead do all the hard work without (as many catastrophic) bugs slipping though.

This can't be said as much about other languages. As a side effect, we are seeing Rust becoming a good combination with what AI spews out for the same reason. And junior developers might as well go extinct as a result, we will find out some generation later.

42

u/DigThatData 8d ago

I think we're ultimately going to see an evolution towards something like an apprenticeship system. We were already sort of headed in that direction with the seeming expectation that part of the CS undergrad experience is landing internships.

18

u/pjmlp 8d ago

We have had apprenticeship system in Europe for decades in computing, I did professional IT on the high school back in Portugal, with on the job learning in the early 1990's, just in case I would not manage getting into a Software Engineering degree at first attempt.

Same to several team members on my German agency.

8

u/TheBananaKart 8d ago

Yeah both Germany and the Uk have always been big on apprenticeships for engineering, they nearly died off in the UK at one point due to a push for university by previous governments.

6

u/Cremdian 8d ago

Apprenticeships seems like such a superior model for most careers.

3

u/2hands10fingers 8d ago

Bad for unchecked capitalism

8

u/gimpwiz 8d ago

I distinctly hope that adequate numbers of employers stay committed to hiring interns to continue making this possible. We try to have an intern every year. Part of that though is making sure we have a req to hire an intern to fulltime after graduation of course.

5

u/veverkap 8d ago

As long as they pay the interns I agree

11

u/gimpwiz 8d ago

Had to check the sub to make sure I was commenting in the right place. I do firmware these days so we mostly hire EE/CE kids. Regardless of EE, CE, or CS, there is absolutely no such thing as un unpaid internship in any of these fields anywhere in the US that I know of, except for random individual yahoos trying to get kids to make their facebook killer for them or something. No legitimate company even thinks they can get away with not paying.

I don't remember exactly what we pay our interns but I think it's in the 40s or 50s per hour. I know it was high 30s and low 40s like a decade ago. For undegrad interns, not grad.

We expect usable results (even if very modest) from an intern. You do work, you get paid... simple stuff

3

u/veverkap 8d ago

That's great but too simple for most shops I know of.

4

u/gimpwiz 8d ago

Yeah you're right, everyone seems to be trying to game that. Wage theft is rampant. I am lucky enough to work somewhere that time cards are taken seriously enough and nobody tries to get clever. Hell, I've multiple times had to remind interns that all intern events and all team events are paid time, so if they're going to get beers and listen to music at 2pm at an official company event, do not even think of not putting those hours down as worked hours; you absolutely get paid for that too. Not only is that federal and state law, but it's also explicitly something we remind them of - it's a work event at work hours, it's time on the timecard. If any of them get a little shy about it I remind them that part of their job as an intern is to network, and talk to people, and learn things, and if you happen to do it over a beer that the company is paying you for, so much the better.

I always say... you do work, you get paid. You don't get paid, you don't do work. Basis of our economic system, really. Anyone cheating that deserves trouble coming their way.

2

u/veverkap 8d ago

Amen.

2

u/blind_ninja_guy 8d ago

You sound like a great mentor.

18

u/CherryLongjump1989 8d ago edited 8d ago

This can't be said as much about other languages

You mean like Go, which is the canonical example of a language designed to make hiring managers happy above all else? Or Java, which as far as anyone can tell, has avoided the fate of COBOL solely because of armies of offshored contractors willing to do the needful?

1

u/germandiago 5d ago

It has also been developed to be productivity-resistant from the point of view of prototyping and initial learning curve.

It is a double edged sword: what is great for rock solid security and/or safety (as long as you do not spam unsafe around) is the same thing that makes other kind of software more difficult to write.

18

u/CherryLongjump1989 8d ago

It turns out I’d simply forgotten how straightforward it can be to rely on bare CLI tooling.

I had this same exact experience with Zig. Switching back to the CLI for Zig, ended up switching back to the CLI for most languages I use. Zig debugger still works fine for stepping through code and I don't feel like I am missing anything else.

18

u/pm_plz_im_lonely 8d ago

Coming from Java: The linter bugged out and the compiler errored on unused variables. See ya.

3

u/neutronbob 7d ago

You won't like golang either. It would be nice to have this be a compiler switch, so that you could make it a warning, rather than always be a stop-the-compile error.

5

u/ManufacturedCakeDay 7d ago

as a rust enjoyer, OP should just use Odin. many of the points just straight up disappear.
i really don’t get why people prefer Zig to Odin. truly.

11

u/otherwiseguy 8d ago

As someone who was a C developer and has written primarily Python for the last 14 years or so, any language that is duck-typed is just inherently not something I am interested in. Never again.

7

u/unski_ukuli 8d ago

Confusing comment. Never again Python while you are a python developer?

11

u/somebodddy 8d ago

One can swear to never again buy another phone from <brand> while still using his <brand> phone. Switching away from an option is not a free action - it's much more costly than picking a different option to begin with.

7

u/314kabinet 8d ago

Sick of it, clearly

5

u/otherwiseguy 8d ago

You can be good at using tools that have features you don't like. I'd argue that increased familiarity really highlights the features you don't like.And duck typing is my least favorite part of Python, especially when working on very large projects.

2

u/unski_ukuli 8d ago

Right. I actually agree but somehow I didn’t get that from the original comment.

1

u/renatoathaydes 6d ago

Zig duck typing is different than Python’s. Zig will check the function types when the compiler finds a function is actually calling it with a concrete type. It just can’t check that until then because the function is more of a template. Python only checks types at runtime unless, though they do have a type system now.

0

u/KaMaFour 7d ago

"Yet you participate in society"

13

u/Awesan 8d ago

It's kind of subtle but I really felt that zig encourages you to fix your shit, so to speak. While rust seems designed to say "don't worry about it, i got you", zig is like "yeah that's your problem to solve, so solve it".

Basically you need to design your stuff correctly so that memory management is easy and you can lean into zig's features. If you try to go against the happy path in the language, you end up with a lot of crap code that is very hard to read and probably full of bugs. Whenever I see people hating on zig this is often what I think they ran into. It's very opinionated, in a subtle way that allows you to do what you want, but it just kind of sucks if you try to do lots of small allocations.

In any case I feel like I learned a lot from trying zig and probably will be able to write better C and even rust now that I've used it.

56

u/Antroz22 8d ago

"don't worry about it, i got you"

You mean the "I won't compile this"?

18

u/-Redstoneboi- 8d ago

yeah, basically.

it won't compile anything that has even the slightest hint of being unintentionally* unsafe. well, besides cve-rs. but we're also getting a new borrow checker now, so i wonder how that one's doing.

it's very restrictive, but we also regularly have people in rust subreddits asking why a certain operation is forbidden in rust before someone in the comments explains exactly why it's forbidden.

you can afford to be less careful/anxious about the code because there are practically no false negatives. false positives be damned.

-11

u/Awesan 8d ago

No, sorry it was unclear. I mean, provided your code compiles, you do not need to worry about where the memory comes from or when it is freed. Same for concurrency: provided your code compiles, you will not have memory related race conditions. If you're really into rust you can understand what the compiler does exactly, but you don't have to in order to be an effective programmer with rust.

7

u/gmes78 8d ago

If you're really into rust you can understand what the compiler does exactly

Local variables are always on the stack, some types allocate on the heap.

Does reading documentation for the types you use make you "really into Rust"? None of that stuff is hidden. Box, Rc, Arc, Vec, String, PathBuf, etc. all allocate.

Memory gets freed on Drop, which happens at the end of the scope. It's true that you don't have to worry about that (except for reference count loops), but why is that a bad thing?

1

u/Awesan 8d ago edited 8d ago
  1. I didn't say it was a bad thing, just a different philosophy
  2. I didn't say you cannot know how it works, just that for the most part you don't need to in order to be productive/get started (as opposed to zig, where you absolutely do)

I don't know why you're so combative with your reply when I was just trying to clarify what I meant, not trying to judge anything.

edit: I just read the comment again, this whole idea of having 2 places for allocations, "stack" and "heap", is an invented concept that does not accurately map to the underlying mechanics. There are also fundamental differences between how zig and rust handle this concept.

8

u/read_volatile 8d ago

I just read the comment again, this whole idea of having 2 places for allocations, “stack” and “heap”, is an invented concept that does not accurately map to the underlying mechanics.

This whole idea of having 2 ways to organize storage, “files” and “directories”, is an invented concept that does not accurately map to the underlying mechanics of blocks on a drive.

Hell, you could say the same thing about actual blocks themselves thanks to wear leveling. Or virtual memory, or processes and threads, or even the notion of a “register” given the existence of ROBs, etc etc.

I would recommend getting familiar with the concept of “abstraction”; it’s something that comes up a lot in this field.

0

u/Awesan 8d ago

Of course most of the time the differences between these things are minor and only relevant in certain edge cases (also for all the examples you provided). But when we're specifically comparing two things and the difference cannot be properly explained while maintaining that level of abstraction you cannot just pretend anymore.

Zig specifically is designed to ensure the compiler always knows how much stack space your program will ever need. This means you cannot run out of stack space in a Zig program unless you do recursion (which I understood will be disallowed directly at some point, forcing you to allocate your own stack space for that call stack, either on your own stack or somewhere else). Rust does not have this assurance and cannot due to its compilation model.

6

u/gmes78 8d ago

Your comments imply that Rust doesn't force you to get memory management correctly, while that couldn't be further from the truth. You need to design your data structures in a way that'll work with the borrow checker. Saying "provided your code compiles" dismisses all the work and knowledge required to write a program that does compile.

It's a bit confusing to see someone describe Rust as letting you not care about the details, when, to me, "doing things correctly" is the central theme of Rust.

edit: I just read the comment again, this whole idea of having 2 places for allocations, "stack" and "heap", is an invented concept that does not accurately map to the underlying mechanics.

Not really. The stack is part of both CPU architecture and ABI.

2

u/EntroperZero 8d ago

this whole idea of having 2 places for allocations, "stack" and "heap", is an invented concept that does not accurately map to the underlying mechanics. There are also fundamental differences between how zig and rust handle this concept.

Can you elaborate on this? I don't know that much about Zig.

1

u/Awesan 8d ago

The hardware does not have the concept of a stack or a heap. I also am not an expert but my understanding is that CPUs can only really operate on registers, so to use anything from memory they have to do load instructions first. Because loads from actual RAM sticks are slow, they have layered caches (L1, L2, maybe more depending on the model). The idea of "stack memory" vs "heap memory" is a language construct/abstraction that is very common but not a hardware-level thing.

What happens when your program starts is that the OS allocates some block of memory to be used by your functions known as "the stack". Each function can just use what it needs, and the memory is again available when the function ends (hence the name).

If your program then needs any compile time known size memory, it can allocate this on the stack. This is very cheap as it's just a bump allocator (pointer is moved back when the function returns). It's also nice because this memory is basically always going to be in L1 and compilers can often trivially assign it to a register, bypassing loads altogether in some cases. If you do not know the size of what you want to allocate at compile time you need to heap allocate it, basically ask the OS for more memory and storing a pointer to that (usually 8 bytes nowadays) on the stack instead.

Your program says how much it will need (deduced by the compiler). This is where Zig meaningfully differs from Rust -- Zig has gone to great lengths in its language and compiler design to ensure it actually knows how much stack space your program will ever need. Recursion is still allowed for now (so that's a current caveat) but this will be changed in future versions (see below). Rust does not do this and therefore stack overflows can occur (if you try to allocate more on the stack than was reserved).

I believe there's a language proposal for Zig to only allow recursion if the caller provides the stack memory, so basically you would not use the OS-provided stack memory for recursion but instead you have to make your own best guess of how much you need. Of course you can still allocate this guess on the OS-provided stack memory if it's compile-time known (this kind of thing is really easy in Zig).

6

u/EntroperZero 8d ago

Mmm, the heap isn't a hardware thing, but the stack definitely is. The CPU does use registers, one of which is called the stack pointer, and it has push and pop instructions that write to and read from the address pointed to, and increment or decrement the pointer. The OS does manage virtual memory, but the CPU "knows" where the stack is in its current virtual memory space. And referencing stack-allocated variables and blocks is done using stack-relative addressing modes supported by the CPU instruction set.

But anyway, that's interesting that Zig is doing static analysis to determine how big the stack can possibly get. I would have thought that impossible in all kinds of programs, but I guess it's kinda similar to declaring an "unsafe" block where you opt out of compiler protections.

2

u/ConspicuousPineapple 8d ago

I mean, if you disallow recursion it's kind of trivial to compute, isn't it?

1

u/EntroperZero 7d ago

Well that's what I mean, they give you the escape hatch, so they can do the analysis even if you want to use recursion.

53

u/dan00 8d ago

It's kind of subtle but I really felt that zig encourages you to fix your shit, so to speak. While rust seems designed to say "don't worry about it, i got you", zig is like "yeah that's your problem to solve, so solve it".

Actually Rust does the same to you regarding program architecture. If you've a messy, intertwined architecture, than you're gonna fight the borrow checker a lot.

But you're right about Zig and memory management. If you organize your code, that certain blocks of code share the same memory arena - perhaps even use a bump allocator - than memory managment gets a lot easier and it's as performant as it can get.

57

u/max123246 8d ago

Yeah idk, rust simply won't let you compile. I prefer that over zig's potentially buggy code

Plus personally after seeing how the zig creator dealt with the bun guy, I doubt I'd ever use zig as a result. And I agree with their anti ai stance too

4

u/0x564A00 7d ago

Well, Zig might not stop you from writing a use after free, but it successfully save you from trying to run your code that has an unused variable because you haven't finished writing it yet.

3

u/OSS-Corpo-Shit 7d ago

Bro, what do you mean?

The bun guy tried to get zig team to implement pull requests that causes non-determinant outputs from the zig compiler. IE: you would have to keep compiling your exact same correct zig code multiple times till tests passed and then keep that executable, then bun guys threw a massive hissy fit over zig rejecting said pull requests. 

If anyone was the absolute child in this situation, I was absolutely bun. 

2

u/max123246 7d ago

The zig creator then put out a hit piece on the bun creator. They're both children.

Edit: Well the zig creator has edited the blog post and it's far more civil. But y'know, damage already done and all.

2

u/OSS-Corpo-Shit 6d ago edited 6d ago

The hit piece following the multiple hit pieces that the bun team threw up all over GitHub, twitter, and other spots?

If anything, Andrew’s blog on it was overtly civil considering the bullshit bun was authoring.

Bun team deserved a mid-2000s Linus post and got a late-2010s Linus post.

Spinning this as AK being the jerk is utter fanboy nonsense. 

2

u/max123246 6d ago

Did you read the first draft of that blog post? It was not civil. Yes, bun's attacks were slathered in corpo PR speak so it wasn't as inflammatory but still just as damaging. But none of it was civil.

I don't get why you feel the need to defend this. Even the zig creator has apologized and edited his initial blog post to be far more civil.

1

u/OSS-Corpo-Shit 6d ago

I have only read the original post. I did not know it was revised. Good on Andrew. 

You know who hasn’t come out and admitted they were incendiary and wrong and that their pull requests were justifiably rejected? Bun team. That’s who.

It is funny that you are mad at myself for pointing out that you’re blatantly lying about what actually happened because writing what actually happened doesn’t align with your hit piece commentary. 

2

u/max123246 6d ago

I edited my original comment once I found out he revised the blog post. I don't have an agenda i read the zig blog post but have not actually read any of the bun correspondence other than them crying about not getting to submit vibe coded slop

Sorry if it seemed otherwise. Have a good one

1

u/spinwizard69 7d ago

I wouldn't trust a guy with a bun either.  ;)

1

u/skyfex 1d ago

Yeah idk, rust simply won't let you compile. I prefer that over zig's potentially buggy code

FYI, there is a project to add on static analysis to Zig: https://github.com/ityonemo/clr

From discussions I've read this seems to be a path Andrew is very interested in: add a system to plug in any kind of static checking tools into the compiler. The current version of clr relies on a fork of Zig with this plug-in feature added. This is a path to check for a lot more issues than just memory bugs.

I think it's wise to have some patience with Zig. It's a language that seems very focused on not locking into a bad solution prematurely. See the async I/O development for instance.

Zig is not going to make its syntax unwieldy or compromise its crazy fast compilation speed to force expensive static memory analysis onto everyone in all compilation modes. I have a suspicion that Rust's borrow checker approach will be seen as the same kind of "mistake" as its choice to go for colored async functions. Sure, it was the best approach at the time. And Rust is great in its own right for it. But Zig is playing a longer game, for better or worse.

23

u/Lisoph 8d ago

My experience is this: Rust tells you to fix your shit. Zig expects you to write tests which tell you to fix your shit.

29

u/flying-sheep 8d ago

That's just stepping out of your comfort zone in general.

I learned Java, then Python, then SML (a functional language similar to Haskell), JavaScript, R, Typescript, and finally Rust, and each step made me better in general.

I think apart from learning to code in the first place, SML was the biggest step up.

17

u/-Redstoneboi- 8d ago

"if a language doesn't change the way you think, is it even worth learning?" or however that quote went

11

u/jl2352 8d ago

If you try to go against the happy path in the language, you end up with a lot of crap code that is very hard to read and probably full of bugs. Whenever I see people hating on zig this is often what I think they ran into.

Honestly I've seen the same with Rust. Everyone I've known who hated Rust basically had the same experience, where they didn't know the Rust patterns and found the language painful.

They will have millions of match blocks everywhere because they don't know the patterns to remove them, or their iteration logic is painful because they know only the basics of iterators. One time I had a team member write about 500 lines implementing logic that was simply `std::iter::Iterator::map` + `std::iter::Iterator::fold`. As a result their code is bloated, brittle, and everything takes 10 times longer, because there is a lot of stuff to learn on the happy path.

When you have `Into` vs `From` and `AsRef` vs `Borrow`, but strings also have `FromStr`, `ToString`, and `Display` (which when you implement you get `ToString` for free so why are there both). Then you have `Iterator` vs `Iter` vs `IntoIterator`, and `to_iter()` vs `into_iter()` ... and then `Send`, `Sync`, and `'static` all come up too (and `'static' is usually `&'static` but sometimes you need `+ 'static` so what's that about). ... all of this actually makes sense once you learn it. They've done a really good job of organising it well. But it's a lot of stuff. This is core stuff too. We ain't even onto common libraries yet, where you get questions like why do I need `serde` and `serde_json`? That's not how it goes in most langauges.

You can see why people find this agonising when they start out.

11

u/xFallow 8d ago

Is it wrong that I'd rather focus on the problem I'm solving than how to best write in the programming language?

13

u/Awesan 8d ago

No, but if that is your preference you probably have more success with e.g. Python or Java or something. Neither rust nor zig seems to match that idea very well.

2

u/xFallow 8d ago

Happy with Go at the moment I don’t like dependency management in python and Java and I especially hate how Java devs write programs 

11

u/EntroperZero 8d ago

It depends how much of the problem you're solving is making your program highly performant and memory safe.

7

u/flying-sheep 8d ago

Not if you're writing a one-off script that you delete immediately after running it successfully.

Yes if you write code that ever has to be read.

1

u/xFallow 8d ago

I’m using Golang at the moment it’s a breath of fresh air being able to look at stuff I wrote 5 years ago and still perfectly understand it 

Can’t say the same for the RXJS stuff I wrote 

1

u/flying-sheep 4d ago

There's a balance and for me, Go ain't hitting it.

It's a language designed to keep junior devs humble. I'm senior enough to know when to use e.g. operator overloading and when not to, and my code is more readable as a result.

1

u/xFallow 4d ago

Fair enough I personally never find I needed operator overloading although it was fun to play around with in Clojure.

I've been working with nats a fair bit recently and I really enjoy reading their code when I have to https://github.com/nats-io/nats-server/blob/main/server/server.go

1

u/Ravek 7d ago

There should be some balance. Dedicating some part of your focus to learning, trying different things and checking out new developments leads to better results in the future.

-15

u/coolmintchocolate 8d ago

"One caveat worth stating up front..." is such an obvious AI-ism

29

u/elperroborrachotoo 8d ago

People read more AI texts, AI-isms will enter human language.

Especially if it's a sub group where the median of creative writing is fixes some minor bugs.

12

u/atrocia6 8d ago

People read more AI texts, AI-isms will enter human language.

AI models train on human writing, human brains train on AI writing?

8

u/CherryLongjump1989 8d ago

Welcome to life in the Marine Corps. Where people are still pretending to be John Wayne, who was pretending to be a Marine.

1

u/disperso 8d ago

I'm not a native speaker. I've learnt what "load bearing" is very recently. Guess why... Also, lots of people are learning what em dashes are at a very fast pace.

I was saying "delve" quite lot, though. Thankfully people don't know about this that much.

1

u/elperroborrachotoo 8d ago

🤷🏻‍♂️

15

u/xFallow 8d ago

Yeah the word choice is very AI like, nothing against people who use it to write but I find it grating after reading claude outputs all day at work

5

u/Blashtik 8d ago

The more I use LLMs the more I hate reading their output. It always felt off to me but now it's getting so tiring to see. I want to see their writing as little as possible.

3

u/max123246 8d ago

Yeah I agree. Way too many people putting a filter over their voice by "editing with an LLM".

1

u/AlSweigart 8d ago edited 8d ago

So, many "AI-detectors" are junk products that are just a front-end to ChatGPT, but I've found Pangram has held up pretty well to my own testing. If anything, it tends to have false negatives (it thinks AI-generated text is written by humans).

I fed the first 700 words into Pangram, and it gave me a 50ish% score for being AI. Don't think that it can zoom in on any given sentence as AI or not, but this is the kind of score I see from Pangram on stuff that has been edited by AI, though not written. So it's not like the author told ChatGPT, "Write a blog post about..."

The Pangram team developed their own ML classifier model for AI text. They don't just copy-paste it to ChatGPT and ask it for an answer.

Sorry that this sounds like an ad, but the "I saw Goody Proctor generating with the AI" accusations started to miff me a bit. People point to an em-dash and declare it as definitive proof of AI writing.

-27

u/BrewedDoritos 8d ago

AI bitching is getting really tiresome

26

u/vips7L 8d ago

Stop using it then. 

18

u/cairnival 8d ago

“The first thing that caught me off guard — and honestly, who would’ve expected this to be the memorable part — was IDE support” reading stuff like this is tiresome

12

u/Keganator 8d ago

Don’t post your sloppy AI slop then and write your own article. 

8

u/TankorSmash 8d ago

Did your use LLMs to help write this article at all?

10

u/disperso 8d ago

The bottom of the post says:

Disclaimer: styling and error handling throughout this article were cleaned up with the help of AI.

-3

u/BrewedDoritos 8d ago

I haven't written it

1

u/TankorSmash 8d ago

Ah okay, thanks

1

u/QuarkCreator2610 8d ago

I think zig could really use a dependency manager and the little tooling that they do have feels clunky/hacky to use since its a bit too connected to your own source. If zig gets a good dependency system I think i would definitely seriously consider phasing out C for it(Im a C guy and i like what zig is doing, but i think Rust takes it to a level thats a bit too extreme for my liking where the features and standard library are starting to look like C++)

1

u/unski_ukuli 8d ago

I think the std is pretty far from C++, though I think thats sort of a problem. Rust doesn’t even have a bundled date library. A simple project can easily have hundreds of dependencies because 1) too small std together with 2) very easy to add dependency with cargo.

1

u/OSS-Corpo-Shit 7d ago

What is missing out of zig build and zig fetch that you need for dependencies?

2

u/QuarkCreator2610 6d ago

I’m not saying zig build and zig fetchare incapable of handling dependencies. They provide the basic mechanism, but to me the experience still feels more like “fetch this source and wire it into build.zig” than a complete dependency-management workflow. Its way too integrated into your source.

What I’d like to see is a more standardized, ergonomic system for declaring dependencies, resolving compatible versions and transitive dependencies, updating them, inspecting the dependency graph, and applying overrides or patches - ideally with reproducible lockfiles and clearer conventions across projects. I also think the tooling is fairly coupled to the project’s build.zig, which makes simple dependency management feel more manual than it needs to be.

So the gap is less “Zig cannot use dependencies” and more “the workflow and ecosystem don’t yet feel as polished and predictable as I’d want before replacing C in larger projects.”

-1

u/MrFranzose 7d ago

May I ask an unconventional side question: how did someone come up with a programming language name which sounds quite similar to a motto of an Austrian painter?