#capabilities#reflection#comparing#zig#reflection capabilities#comparing reflection#comparing reflection capabilities
7 comments
peesem11 days ago
"not an expert in zig" but you can't even look at the documentation to find the `@tagName` builtin to do exactly the problem posed?: https://ziglang.org/documentation/0.16.0/#tagName
i can literally google "zig enum to string" and the first result is a reddit post where the given solution is `@tagName`. i'm ready to write this post off as a low-effort ad for C3
lerno11 days ago
C3 has an even simpler way than Zig: `Color.RED.description`.
From what I can see the example started from C++, and then comparing how each language would look building it in userland instead.
hiccuphippo11 days ago
If it's for debugging purposes, you can use `{any}` as the format and it will print `.BLUE`
std.debug.print("{any}\n", .{color});jb199111 days ago
Agree, the post was extremely low effort.
RyanVail11 days ago
Zig doesn't have attributes, but you could just create a thin wrapper struct over an inner type and use setter functions that throw errors on invalid values. Personally I prefer this over attributes because it forces you to handle possible error states from the callers of the setters, instead of relying on you remembering to call `validate` on your types.
lerno11 days ago
I believe all examples are derived from C++ examples on its new reflection capabilities.
WalterBright11 days ago
There's a large black zig-zag blocking reading the text.
Read the full thread on Hacker News →
Related stories
- Writing JSON to a custom output in Zigopenmymind.netLobsters · 10 points · over 3 years ago
- A minimal RocksDB example with Zignotes.eatonphil.comLobsters · 19 points · almost 4 years ago
- The Zig Journeykristoff.itLobsters · 49 points · 7 days ago
- Lobsters · 53 points · 8 months ago
- Custom JSON serialization in Zigaolium.comLobsters · 6 points · about 3 years ago
- Hacker News · 4 points · 11 days ago