Hacker News new | past | comments | ask | show | jobs | submit login

Like Walter Bright, I would love to have some sort of “span” or “slice” primitive. I would love language level tagged unions rather than writing them out each time. Pattern matching isn’t exactly a type system feature, but relies on it to work, and would make those more useful. The lack of destructors means a lot of manual handling of errors. The lack of generics makes it difficult to write generic data structures without losing type safety. There’s no real const.

There are ways to do all of these things, but they’re more manual, more error prone, and get in the way of doing the actual work you’re trying to do.




That describes the basic feature set of C++ very well.

People complain about C++ that it can do much more. Yea. But there is no need to use template meta-programming, multiple inheritance and other special features. Actually I think programmers shouldn’t use them in productive code.

Recently some projects switched the compiler to ‘g++’ and use the basic subset of C++. Makes sense? Maybe Herb Sutters “C++2” will evolve, main features are safety and simplicity.

I’m fine with both C and C++. They do a good job. Address-Sanitizer is a game changer! But I want more.


Yeah, kinda:

> I would love to have some sort of “span” or “slice” primitive.

This was recently added!

> I would love language level tagged unions rather than writing them out each time.

There is std::variant, but it’s not as nice as a language provided solution, both to use and the generated code.

> Pattern matching isn’t exactly a type system feature, but relies on it to work, and would make those more useful.

This is not in C++, and my understanding is that the proposals are nowhere near close.

> The lack of destructors means a lot of manual handling of errors.

The huge C++ feature. Yes, a clear win. I think a version of RAII closer to Rust than to C++ would make more sense for C, though.

> The lack of generics makes it difficult to write generic data structures without losing type safety.

Yep, absolutely.

> There’s no real const.

There isn’t in C++ either.


C++ 20 std::span is an example of how little WG21 actually cares about safety, correctness or other principles of software engineering.

The slice type you actually want has nice safety properties. The slice type proposed to WG21 about five years ago as std::span compromises a little bit, knowing they'd object to good engineering here, and it offers an unsafe way to access the slice as well as safe access. The committee voted to strip out safe access and specifically rejected efforts to ensure there was a sane way to use this type.

I assume Jarrad Waterloo's proposal to fix std::span in C++ 26 will get traction because it's now embarrassing for the project but there's no reason we should pretend this was some mere oversight. C++ is less safe than it should be on purpose.


I get similarly frustrated at the implementation of operator-> and operator* in std::optional. In what world would I want to provide accessors with no more safety than a raw pointer?

Edit: I was looking it up just to make sure I remembered it correctly, and there’s been a recent change that makes it worse. The operator-> and operator* on std::optional are now marked noexcept, so implementations are forbidden from making the accessors safe.

https://cplusplus.github.io/LWG/issue2762


That's what I've heard, but since I'm not that in the weeds with that whole process, I didn't want to comment on it at that level.

It's struck me as being similar to operator* on Optional. I get why they did it. It makes sense. It's also unfortunate. I'm glad I'm not on that committee.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: