The conversation

Lessons learnedExperience excerpt · English

> Variant types where one has to use objects as types don’t come up that often in API design or …

> Variant types where one has to use objects as types don’t come up that often in API design or data structures in my experience with mobile and system programming on e.g. Linux You can't use what you don't have, so you adapt to the tools you do have. In my C++ time, the team would often write types that logically held several variants. However they were expressed as product types, so with space overhead and error-prone, unergonomic use. Sum types are game-changing. Look at any Rust project you'll find enums with data everywhere. They're just a building block to model problems, like product types are. A language that miss them is as strange too me as a language without product types. After 10 years of mostly C++11 and C++14 I would never go back to it for this reason alone (although as outlined in the article there are other reasons too). > Error types are probably the most popular incarnation of that. There’s several libraries available and they will be part of the C++ standard. Again, with what performance and ergonomics?

Original discussionSwitching from C++ to Rust275 source comments · at import
2

What was this responding to?

Parent context · original excerpt

BL

Variant types where one has to use objects as types don’t come up that often in API design or data structures in my experience with mobile and system programming on e.g. Linux. I think I’ve genuinely had to use them only a few times. Error types are probably the most popular incarnation of that. There’s several libraries available and they will be part of the C++ standard. This is a case of the Rust community overselling a minor feature as a game-changing novelty.

Full original

Community replies 0

No community replies yet. Add your perspective.

Replies from the source 2

Direct replies available in this import. Original-language excerpts.

FP

not to diminish value of sum types (those are not specific to Rust of course) but I think that product types belong to a database / config rather than being hardcoded.

Full original
BL

I just checked the old Rust classic “ripgrep” on github. In matcher.rs, the enum is used as poor man’s OOP. I saw several match expressions which then call the same function on each matched type. searcher/mod.rs is an error definition. glob.rs contains a sort of policy enum which can be implemented once again with OOP or as a policy template. json.rs usage can be modeled as a single class. core/app.rs is more involved, but can be modeled as a series of structs with a map from enum -> any. Or as am std::variant. Or using OOP. I looked at all instances and didn’t see anything game-changing. It’s a nice syntax and it should have really good performance, but such idioms are way too low-level to change any game.

Full original
Continue on Hacker News

Respect different perspectives. Share concrete experiences.

Sign in to post, reply, repost, and quote.