-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Proposal: Concerning Zig Structs #1250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't think methods or
|
Methods lead to this problem. #1170 (comment) |
You are proposing to remove the ability for structs to be namespaces. Rejected. See also #1047 |
@andrewrk I think that was just a suggestion. The idea was to draw a line in the sand as to the definition of a struct. Not sure if this can be 100% resolved before 1.0, but a rule for reference would be nice. |
Uh oh!
There was an error while loading. Please reload this page.
Zig needs to figure out what a struct is, and stick to its guns about it
Is it an encapsulating class? Is it a general namespace? A c-like struct?
It's clear that users of zig all have different answers (and visions) to what they want a struct to look like.
Structs in Zig as they stand right now, do not fit into any of the above categories. They have aspects of being classes, since they can contain functions, and public and private fields (although they don't do anything: #569. They have aspects of being namespaces, as they can contain functions. And they have aspects of being c-structs, since they are concrete, unabstracted, blocks of data. Zig Structs are just an unorganized amalgamation of these concepts.
As a result, Zig structs not only cause complexity elsewhere, they are not able to properly function as any of the abstractions mentioned above: an object, a namespace, or even a c-struct. No matter how the programmer tries to use Zig structs, they will run into problems. Here's a short list of github issues:
This is a question that needs to be answered as soon as possible.
There are many solutions to this problem. We can implement proper OO, or proper Rust-like traits, or namespacing, whatever. We just have to pick one and go with it, or else this unproductive bickering will continue forever.
Now, done summarizing. Here's what I think.
Zig structs should be more or less like c-structs. No functions, no pub/priv, only concrete values. Note that this still allows function pointers to be in a c-struct, since these are concrete values. There will be no more worrying about where functions are defined, or how to do inheritance, or implement Traits. A struct will be a struct, and any futher abstraction will come out of cleverness out of using them.
If anyone thinks C-structs are not good enough abstractions, read through the Plan 9 C library here. It is the most beautiful public interface I have ever seen (much better than OO). If Zig wants to be a C alternative, this is, in my eyes, the only way to do this right.
But of course, I know nothing compared to some of you, and this needs more all-around discussion. But struct should be finalized as something, and that's that.
The text was updated successfully, but these errors were encountered: