top | item 35323942

(no title)

ptato | 2 years ago

Please don't do "const Self = @This();" if the type isn't generic. It is pointless, redundant, ugly.

What issues could public struct fields have caused?

discuss

order

latch|2 years ago

Self is used in the standard library for non generic types every now and again.

As for public fields, the 0.9 change to allocator comes to mind. This was written off as a minor change, because Zig is pre 1.0. But what I haven't heard (and 100% upfront, I haven't looked hard), is how Zig plans on dealing with it post 1.0. Like, where are we in the gradient of: "1.0 will never break the public API (struct fields included)" to "deal with it".

kristoff_it|2 years ago

1.0 for Zig is going to mean not only never break the API, but also that we'll be pretty much done with the language. The current idea is to release v1 only after a few releases that only contain bug fixes.

> As for public fields, the 0.9 change to allocator comes to mind.

That's a good example of why it makes sense for Zig to have all fields be public: the change that we did to allocators has important implications that in Zig we don't want to hide behind a `private` descriptor. This is obviously not a universal truth, but it makes sense for a low-level programming language that cares about the details.

> Self is used in the standard library for non generic types every now and again.

I agree with the parent poster, those should probably be removed, as they don't really help make the code more readable or provide any other advantage. A overhaul of the stdlib is planned, but we're not there yet, as we're still busy working on the package manager and incremental compilation.