Live data from Hacker News

Defining interfaces in C++ with ‘concepts’ (C++20)

lemire.me

11–20 of 77 posts

Re: Defining interfaces in C++ with ‘concepts’ (C++20)

#11
As always, very informative and a perfect "snippet" size to quickly read and learn a new thing or two. Thanks!

Meta: I think the very first sentence is the victim of some drive-by editing, and needs one more pass. I'm not a native speaker, but I still suggest changing

In an earlier blog post, I showed on the Go programming language allow you to write generic functions once you have defined an interface.

Into perhaps

In an earlier blog post, I showed how the Go programming language allows you to write generic functions once you have defined an interface.

Considering the audience and author, I would seriously consider omitting the explanation of what Go is, but that's just polish. :)

Re: Defining interfaces in C++ with ‘concepts’ (C++20)

#12
post #11

As always, very informative and a perfect "snippet" size to quickly read and learn a new thing or two. Thanks! Meta: I think the very first sentence is the victim of some drive-by editing, and needs one more pass. I'm not a native speaker, but I still suggest changing In an earlier blog post, I showed on the Go programming language allow you to write generic functions once you have defined an interface. Into perhaps…

There are quite a few little language mistakes that I couldn't figure out if it was a language thing or just a typo.

> Of course, it also limits to the tools that I use to program: they cannot much about the type I am going to have in practice within the count function.

I think dropping the 'me' is often a feature of those whose native language is eastern European/Russian. The second (possibly) missing 'know' seems to support just editing mistakes. The structure of both makes me think of Portuguese for some reason!

To avoid going off topic on HN, something... something... ChatGPT

Re: Defining interfaces in C++ with ‘concepts’ (C++20)

#14

I would argue Java interfaces are very different from Go interfaces and C++ concepts, because the former is nominally typed and the latter are structural.

That's something I have been pondering for some time.

I believe it's a false dichotomy.

My thought is still that structural supersedes nominal.

A nominal interface is just another constraint added to the list of constraints of an underlying structural interface?

Re: Defining interfaces in C++ with ‘concepts’ (C++20)

#17
post #14

I would argue Java interfaces are very different from Go interfaces and C++ concepts, because the former is nominally typed and the latter are structural.

That's something I have been pondering for some time. I believe it's a false dichotomy. My thought is still that structural supersedes nominal . A nominal interface is just another constraint added to the list of constraints of an underlying structural interface?

Well it depends on a runtime/compile-time distinction. A nominal type is a structural type with a compile-time constraint.

If you have compile-time only constants you can model nominals with structural,

    type Square
        static const IsSquare = true
        
        var length = 10
You can kinda hack-in subtyping,

    type Shape
        static const Shape = true

    type Square
        import static from Shape
        static const IsSquare = true
        
        var length = 10

Re: Defining interfaces in C++ with ‘concepts’ (C++20)

#18
post #14

I would argue Java interfaces are very different from Go interfaces and C++ concepts, because the former is nominally typed and the latter are structural.

That's something I have been pondering for some time. I believe it's a false dichotomy. My thought is still that structural supersedes nominal . A nominal interface is just another constraint added to the list of constraints of an underlying structural interface?

In a nominal type system, a method x() is part of the interface X, while in a structural one it's part of the implementor of said interface. In Go there's a Human.HasOrgan(), not an AbstractBody.HasOrgan().

A consequence of this is that in Rust, which has a nominal system, you can implement two traits that contain a method with the same name and are required to disambiguate at the call site. In Go you can't do that, since the method is part of the concrete type.

Re: Defining interfaces in C++ with ‘concepts’ (C++20)

#19
post #14

I would argue Java interfaces are very different from Go interfaces and C++ concepts, because the former is nominally typed and the latter are structural.

That's something I have been pondering for some time. I believe it's a false dichotomy. My thought is still that structural supersedes nominal . A nominal interface is just another constraint added to the list of constraints of an underlying structural interface?

Nominal interfaces can still be useful though, as they convey a stronger sense of intent than structural. For example, java.io.Serializable is a completely empty interface that classes “implement” to signal that they are safe to serialize. As a structural interface, it’d be useless.
Post reply on HN