Live data from Hacker News

Soursop and Ponies in Kona: A C++ Committee Trip Report

cor3ntin.github.io

51–60 of 69 posts

Re: Soursop and Ponies in Kona: A C++ Committee Trip Report

#51

> One of the concerns is that C and C++ are being discouraged for new projects by several branches of the US government[1], which makes memory safety important to address. The biggest memory safety problem for C is array overflows. I proposed a simple, backwards compatible change to C years ago, and it has received zero traction. Note that we have 20 years of experience in D of how well it works. https://www.digitalm…

C++ already has vector and now has span. Your proposal doesn't add anything over those.

Re: Soursop and Ponies in Kona: A C++ Committee Trip Report

#53
> I spent an ungodly amount of time over the past couple of years exploring ways to get views::enumerate (a view that yields an index + an element for each element of a range) to produce a struct with named members (index & value), as this is more ergonomic and safer than std::get(*it). Alas, despite my best efforts and hundreds of hours invested, this proved almost unworkable.

Isn’t this a damming indictment of the language and everything that is wrong with it? How can something so simple be so hard?

Re: Soursop and Ponies in Kona: A C++ Committee Trip Report

#54

> One of the concerns is that C and C++ are being discouraged for new projects by several branches of the US government[1], which makes memory safety important to address. The biggest memory safety problem for C is array overflows. I proposed a simple, backwards compatible change to C years ago, and it has received zero traction. Note that we have 20 years of experience in D of how well it works. https://www.digitalm…

C++ already has vector and now has span. Your proposal doesn't add anything over those.

Adds:

1. convenience

2. attractive appearance

3. ubiquity

4. better error messages (because compiler knows what they are)

5. one construct instead of two (vector and span)

6. overflow behavior selectable with compiler switch

For example:

    #include 
    std::vector v;
vs:

    int[] v;
Many D users have remarked that it's the single best feature of D.

Re: Soursop and Ponies in Kona: A C++ Committee Trip Report

#55

> One of the concerns is that C and C++ are being discouraged for new projects by several branches of the US government[1], which makes memory safety important to address. The biggest memory safety problem for C is array overflows. I proposed a simple, backwards compatible change to C years ago, and it has received zero traction. Note that we have 20 years of experience in D of how well it works. https://www.digitalm…

C++ already has vector and now has span. Your proposal doesn't add anything over those.

D's slices "T[]" maps to C++'s span -- you're right, though the semantics/APIs of each are slightly different you can treat them as approximate concepts.

C has no such thing that I am aware of

Re: Soursop and Ponies in Kona: A C++ Committee Trip Report

#56
post #5

Herb's CppFront looks like the best hope for a clean C++ future

Herb is one of the best things that ever happened to C++. Not only is he wicked smart, but his ability to persuade is most impressive. As if he needed more, he's also a very nice gentleman.

Re: Soursop and Ponies in Kona: A C++ Committee Trip Report

#57

> One of the concerns is that C and C++ are being discouraged for new projects by several branches of the US government[1], which makes memory safety important to address. The biggest memory safety problem for C is array overflows. I proposed a simple, backwards compatible change to C years ago, and it has received zero traction. Note that we have 20 years of experience in D of how well it works. https://www.digitalm…

But that change is by definition not backwards compatible - neither ABI nor source level.

Using an ifdef to maintain source level compatibility doesn't work as two pieces of code will see the same function using different ABIs.

That said I agree entirely - the conflation of array and pointer is the biggest flaw, it's what "necessitated" the null termination error that people are so fond of calling the biggest mistake.

Re: Soursop and Ponies in Kona: A C++ Committee Trip Report

#58

Earlier quoted context omitted.

C++ already has vector and now has span. Your proposal doesn't add anything over those.

Adds: 1. convenience 2. attractive appearance 3. ubiquity 4. better error messages (because compiler knows what they are) 5. one construct instead of two (vector and span) 6. overflow behavior selectable with compiler switch For example: #include std::vector v; vs: int[] v; Many D users have remarked that it's the single best feature of D.

I think the core issue here is that WG21 seems hell bent on refusing any new syntax if at all possible, and instead requires "generic" solutions that can be used for many problems. The result of which is these unending train wreck solutions for what should be basic, and we end up with enable_if and SFINAE. At least C++ finally has the idea of specifying an interface for a template instantiation, except of course it's absurd in its own way. Rather than specifying an API, you write "code" and a type conforms to that concept if the code "compiles". So you have no way to say "I expect this type to conform to this concept" other than using it.

The primary goal of "concepts" appears to be to mitigate the awful error messages, but even for that it fails.

For example, let's imagine Hashable from any other language, and look at a C++ concept version:

    template 
    concept Equatable = requires (const T& a, const T& b) {
      { a == b } -> std::same_as;
    };
    template 
    concept Hashable = Equatable && requires (const T& a) {
      { a.hashCode() }->std::convertible_to;
    };
and an implementation:

    struct Thing {
      size_t hashCode() const;
    };
    bool operator==(Thing, Thing);
Now how do we make sure Thing is actually going to conform to Hashable? with an assert of course, why would we want anything so gauche as declarative syntax?

    static_assert(Hashable);
You can see the brilliant syntax explicitly disallows us specifying constraints on a concept, and instead we have to use the && expression. My personal belief here is that the banning of constraints in the template name is simply to force people to use logical composition so the people who thought of it can claim people like it.

Re: Soursop and Ponies in Kona: A C++ Committee Trip Report

#59
post #2

Fully agree with #embed. I don't really need the feature often enough to justify it. But it feels fine to use the preprocessor for it. It's annoying enough for the people who need it to have some build-system work-around, so just some simple straight forward implementation seems better than some over-specified solution for every possible use-case (imagine the horror of some template construct with locales/encoding sp…

> having these basic constructs stay compatible is worth quite a lot

Also, I think C++ can still use the same preprocessor as C at this point (it's been a while since I've had to deal with that)? If you're going to diverge the preprocessor you should get more benefit out of doing so than "not having #embed". For that matter, having important features like #embed only available via preprocessor also helps undermine the pointy-haired trolls who (allegedly?) keep trying to deprecate the preprocessor entirely in favor of some proprietary build system.

Re: Soursop and Ponies in Kona: A C++ Committee Trip Report

#60

Earlier quoted context omitted.

C++ already has vector and now has span. Your proposal doesn't add anything over those.

Adds: 1. convenience 2. attractive appearance 3. ubiquity 4. better error messages (because compiler knows what they are) 5. one construct instead of two (vector and span) 6. overflow behavior selectable with compiler switch For example: #include std::vector v; vs: int[] v; Many D users have remarked that it's the single best feature of D.

> 3. ubiquity

Hardly. A std library update is often easier and faster to ship than a new compiler toolchain. Especially in C/C++ world, although it is moderately uniquely terrible in this regard

> 5. one construct instead of two (vector and span)

Incorrect. Vector is an owned type, while both span and your proposal are borrowed types.

> 6. overflow behavior selectable with compiler switch

That sounds an awful lot like a negative to me, not a feature. It's not generally desirable for code behavior to change depending on how it's compiled, makes debugging kinda hard.

Unless you're just referring to things like sanitizers, in which case yeah span & vector both have those same flags.

Post reply on HN