Zig's new bitCast semantics and LLVM back end improvements
ziglang.org270 points by kouosi a day ago
270 points by kouosi a day ago
When I first found out about bit fields in C, I was left wondering what the order of bits was in a byte, eventually I convinced myself it doesn't matter, since the byte is the smallest I/O unit, and lived with the fact that casting between bitfields and bytes was UB (or unspecified, I can't remember), and as such, was another thing I wasn't suppossed to do when writing C.
All this to say that Zig just keeps cleaning up and giving well-defined semantics to warts I learned to live with in C.
Writing linkers must be incredibly rewarding - go has its own, there's mold, there's LLD, there's the OG GNU bfd LD and now Zig has one too! I am sure there's a Rust one too - Wild!
Every one of them is faster than the others too lol! Mold for one tries really hard to be GNU ld and to be useful as an independent linker most have to - I guess Zig/Go ones are purpose built so at least those don't duplicate GNU ld compatibility.
Wait till you hear how many programming languages there are
Sure, but one might imagine that linkers are generic and reusable, so you can just pick one off the shelf instead of making a new one 1-1 for each language. Empirically this line of reasoning seems to be incorrect.
Different programming languages are very obviously not the same thing - different cp command implementations are similar conceptually to having different linker implementations that all do the same thing. But you knew that so not sure if there was a point you were trying to make there.
This change + the existing packed struct logic will be great for working with bit packed binary headers w/o having to manually twiddle so much about the bit handling along the way.
It's so interesting to read comments like this and contrast them with the "don't read the code" type of vibes out right now. It feels like half of the developer world is optimizing low-level struct packing and the other half is YOLO'ing 300 KLOC Electron apps. Very confusing.
Same as it ever was.
yeah, remember those newfangled fancy Node.js guys who would just copy/paste from Stackoverflow without any understanding?
Or the Java guys who wrote bloated apps that wasted CPU cycles on garbage collection instead of writing in C++, like God intended?
Or the Fortran / Cobol guys who wrote in those God-damned, wasteful, useless high-level languages, instead of using assembly, like a proper programmer should?
So vibe coding = copy/paste from SO = interpreter with GC = compiler = punch cards. Got it.
Here's a description of a "real programmer" from all the way back in 1983:
i think it's perfect: AI allows you to go incredibly deep (you have unlimited access to context to make incredibly impactful surgical changes), or you can go incredibly broad (you have unlimited access to context to tie a mind numbing amount of components together). what shakes out is the middle layer: "infra" between "algorithms" and "product".
though, to be fair, the middle layer itself is composed of this same work. so it's fractal, or turtles all the way down.
And why do you mention AI here at all? These statements are ridiculous, world didn't start last year.
I think it makes sense, if one sees that LLMs exposed various pre-existing splits in the developer world.
Those who viewed code as a means to build something else, are happy to switch to LLMs if they can build that something faster/cheaper.
Whereas, those who liked coding for its own sake, don't want to use LLMs, and fear for their jobs and their happiness.
Unfortunately for the latter group, we're moving to a world where most development is done by LLMs, and only cutting-edge or hobbyist work is done manually. E.g., Japanese artisanal wood-working and joinery is beautiful and elegant... but modern carpentry doesn't build that way.
I used to be paid to go in and fix messes of code, created by juniors who were forced to build things they didn't understand.
Now I get to fix things created by managers who enjoyed building things they still don't understand.
Zig is already great for this with ‘packed struct’ and arbitrary size ints. Allows for very clean protocol creation between systems with known properties. This is another great step in that direction.
you need different packed structs for little- and big-endian data. and casting with little-endian data is a nightmare - you need to reverse-cascade your struct fields to be in accordance with the little-endian bit-pattern. (or have a comptime function that does it for you, of course. but then you lose all declarations for the struct). what should be a simple writing down of a protocol is now a pedantic and error-prone ordeal.
Or you just go ahead and forget that big endian ever existed. It's not coming back.
it’s little-endian protocols that require that you juggle your struct fields.
plus, there are still big-endian protocols that will stay for a long time. for example, MIDI clip files in MIDI 2.0 are big-endian.
This has been largely solved by everyone agreeing to use little endian. There aren't really use cases for wanting to convert between them.
Does that mean there are no file formats thatbuse big endian? And network byte order isn't a thing?
> there are no file formats thatbuse big endian
if someone chooses to do that they own the problems. > network byte order isn't a thing
if the network serializes/deserializes for you (kernel primitives) then you don't care what it does. if it doesn't and for some reason you choose to use big endian, again, you own the problem.Network byte order has nothing to do with the kernel and you have to care about it
It’s a standard because neither side of the connection knows the endianness of the other side so there must be a standard. That standard is big endian regardless of your architecture or kernel or anything else
So any serialization intended go over the network should be big endian
right, so a zig app will just do little endian. in the very unlikely event you have it running on a big endian machine you have to do extra work.
You may have never done socket programming, or do you use wrapper libs in Zig? Because you have to send the kernel big endian port numbers for example.
What do you do if you program a kernel in Zig, or just generally do low level networking?
My point is to refute the statement that everyone has agreed to little endian, and so there aren't use cases to want to do conversion. Programs do not exist in a vacuum, most programs do not.