I've said it in other comments on HN over the years, but yes - I agree.
That `.variant` syntax is annoying as hell to dig through when you don't have an IDE to rely on for jumping around. Rust (or your choice of other more explicit language) is just generally way more clear about what's being used.
The way I usually settle on describing it is that this feature solved for people writing code, but code is read more than it's written, and thus I don't believe this tradeoff was worthwhile.
You will probably be sad to hear that allowing to omit the type in Rust is considered, and has been proposed many times.
I can only hope that it's been proposed many times and not actioned on before means there's been enough pushback, considering one of the entire points of the language is the explicit nature of it.
Do you have a link for an RFC or GitHub issue or anything? Would be curious to see.
Fortunately in Rust you can have it both ways, as in `Type::Variant` most of the time and `use Type::Variant; … Variant …` in cases where the type name just causes noise.
Example in the playground: https://play.rust-lang.org/?version=stable&mode=debug&editio...
Re:Swift is a more convenient Rust
by hardwaresofton on Friday September 06, 2024 @09:08AM
(#41465840)
I’ve never done this but this is a great point. I think I’d avoid doing this though because variants often have really short, reusable/general names (leaning into the overall type name being close)
Re:Swift is a more convenient Rust
by GrantMoyer on Friday September 06, 2024 @10:42AM
(#41466683)
You can put the use statement in the function with the match, or even limit the scope further:
{
use MyEnum::*;
match my_enum {…}
}
Zig and Swift do it and I feel like it makes things harder to read, not easier.
`.variant` vs `Type::Variant`
IIRC the syntax is optional (you can include the type name) but it seems obvious that in any sufficiently long or complex code, not having the type name close would be annoying, especially if you didn’t have IDE like capabilities in your editor.