4 ms·
Have you ever used other (modern) programming languages ? In a lot of languages, you achieve the same with 1 line of code. It's not about familiarity, it's abo
by delegate 5mo ago
Have you ever used other (modern) programming languages ?
In a lot of languages, you achieve the same with 1 line of code. It's not about familiarity, it's about the fact that it's a long and convoluted incantation to get the name of an enum.
Why do I have to be familiar with all those weird symbols just to do a trivial thing ?
Update:
Zig:
const Color = enum { red, green, blue };
const name = @tagName(Color.red); // "red"
Rust:
#[derive(Display)]
enum Color { Red, Green, Blue }
let name = Color::Red.to_string(); // "Red"
Clojure:
(name :red) => "red"
- SuperV1234 5mo agoC++: enum Color { red, green, blue }; auto name = to_enum_string(Color::Red); // "Red"
- shooly 5mo ago... and where does that `to_enum_string` come from exactly? It doesn't seem to be built-in, which is the point of the parent comment.
- SuperV1234 5mo agoIt's a fair comparison. The parent comment isn't showing the compiler source code for the built-in reflection mechanisms. You won't have to care about ^^ and [:X:] if you just want to consume reflection-based utils, which was the whole point of my comment.
- shooly 5mo agoWhat? No. Parent comment is comparing C++ to modern programming languages, showcasing how they provide commonly used utilities out-of-the-box instead of making every programmer re-implement them again and again and again and again and again.
- SuperV1234 5mo agoThe parent comment is quite clear: > Why do I have to be familiar with all those weird symbols just to do a trivial thing ? And my answer demonstrates that you do not have to.
- shooly 5mo ago> And my answer demonstrates that you do not have to Then again - "where does that `to_enum_string` come from exactly?".
- pjmlp 5mo agoA library that you install via vcpkg or conan. How many libraries do you read the source code after installing them with the package manager?
- wiseowise 5mo agoTypical C++ dev schizophrenia. In one thread complain about Node and its death-by-a-thousand-packages, then suggest the same in another.
- pjmlp 5mo agoDon't put assumptions in others heads. First of all, the only correct way to use package managers is with validated internal repos, don't vibe install, that goes for node, and goes for C++ as well. Second this thread was all about how code lands in one's computer.
- SuperV1234 5mo agoPackage? We're suggesting to copy paste 5 lines and stick them into a header.
- wiseowise 5mo agoYou can press 'parent' button my comment.
- gpderetta 5mo agoThe whole point of reflection is that it doesn't have to be builtin.
- throwaway7356 5mo agoAnd what if you want to implement something like Rust's "derive"? That is what the article shows. As far as I understand you would have to mess with individual parser tokens in Rust instead of high-level structures like "enum" (C++ reflection). It would be much, much uglier to implement anything like "to_enum_string" in Rust as you would have to re-implement parts of the compiler to get the "enum" concept out of a list of tokens.