Live data from Hacker News

Type-Safe Unions in C++ and Rust

genbattle.bitbucket.org

51–60 of 140 posts

Re: Type-Safe Unions in C++ and Rust

#51
Is there any demand for a syntactic sugar layer on top of C++? Something to make these new features more ergonomic? Something one could opt-in to for newer code, or code that doesn't need to be backward compatible to 1990? Something that outputs valid C++ and so works with any tool chain?

Re: Type-Safe Unions in C++ and Rust

#52

Is there any demand for a syntactic sugar layer on top of C++? Something to make these new features more ergonomic? Something one could opt-in to for newer code, or code that doesn't need to be backward compatible to 1990? Something that outputs valid C++ and so works with any tool chain?

Well we did get `for (auto x : range)` not long ago!

Re: Type-Safe Unions in C++ and Rust

#53
post #11

Earlier quoted context omitted.

One interesting thing about Rust is that none of the language features are really new . Even the borrow checker is from research papers and languages from quite a while ago. The only thing I can think of that might be truly unique to Rust is the concurrency safety model (Send+Sync), though that might be old too. Rust has just managed to take all these features and put them together well, and strive to be more than a…

Ada and Pascal are not really research languages, though. But still, there are improvements taken from research, see Ada 2012 contracts for example.

sorry if this is a dumb question, but what classifies a language as a research language?

Re: Type-Safe Unions in C++ and Rust

#54

Is there any demand for a syntactic sugar layer on top of C++? Something to make these new features more ergonomic? Something one could opt-in to for newer code, or code that doesn't need to be backward compatible to 1990? Something that outputs valid C++ and so works with any tool chain?

Lot of syntactic sugar recently added to C++ and a lot more in C++17. The structured bindings in particular are really excellent ways for unpacking tuples and structs with type inference into new variables automatically.

Re: Type-Safe Unions in C++ and Rust

#55
post #3

> but it’s the first language I’ve experimented with that has made them a first-class feature It is a feature of ALGOL68, Pascal, Ada and quite some newer languages: https://en.wikipedia.org/wiki/Tagged_union

One interesting thing about Rust is that none of the language features are really new . Even the borrow checker is from research papers and languages from quite a while ago. The only thing I can think of that might be truly unique to Rust is the concurrency safety model (Send+Sync), though that might be old too. Rust has just managed to take all these features and put them together well, and strive to be more than a…

the concurrency safety model (Send+Sync), though that might be old too

Smalltalk has had that since the early 1980s

Re: Type-Safe Unions in C++ and Rust

#56

Earlier quoted context omitted.

One interesting thing about Rust is that none of the language features are really new . Even the borrow checker is from research papers and languages from quite a while ago. The only thing I can think of that might be truly unique to Rust is the concurrency safety model (Send+Sync), though that might be old too. Rust has just managed to take all these features and put them together well, and strive to be more than a…

the concurrency safety model (Send+Sync), though that might be old too Smalltalk has had that since the early 1980s

Interesting, thanks!

Re: Type-Safe Unions in C++ and Rust

#57
post #38

Earlier quoted context omitted.

well, yes. The nice thing is that in C++ can be implemented purely as a library. Sometimes C++ feels like the high level languages assembler.

Unfortunately that means they lack lots of the pattern matching niceties that you get in languages with builtin ADTs. There is an impressive paper about implementing pattern matching on sub-classes, but it's pretty hackily done using the preprocessor, and could definitely do with some language support: http://www.stroustrup.com/OpenPatternMatching.pdf

It is widely speculated that pattern matching and many other syntactic enhancements are coming to C++ because of the big door that std::variant has opened.

Re: Type-Safe Unions in C++ and Rust

#59

Is there any demand for a syntactic sugar layer on top of C++? Something to make these new features more ergonomic? Something one could opt-in to for newer code, or code that doesn't need to be backward compatible to 1990? Something that outputs valid C++ and so works with any tool chain?

Lot of syntactic sugar recently added to C++ and a lot more in C++17. The structured bindings in particular are really excellent ways for unpacking tuples and structs with type inference into new variables automatically.

Yeah but if you read the article and look at the syntax for C++ match-like statements, it leaves a lot to be desired.

Re: Type-Safe Unions in C++ and Rust

#60
post #43

Earlier quoted context omitted.

Erm... I think Dennis Ritchie would have had a few things to say about that.

good point; though, while designed to work well with each other, neither unix nor C require the other.

If you want a portable C, *libc is practically a requirement. Having POSIX is also a huge boon.
Post reply on HN