Hacker News new | ask | show | jobs
by mattnewport 3152 days ago
I think the general consensus of the C++ community is that we need Concepts or something like it. I don't think anyone is really claiming no other language offers something similar. I'd love to learn more Haskell but for my primary domain (games and VR) it's not a terribly practical option. This gets back to my original point - yes Concepts will make C++ more complex (in the sense of adding features) but I think it will make the language better / simpler to use in practice and I look forward to it being standardized and widely available so I can use it.

> The concrete representation of these three types must be hidden from the user by language-enforced mechanisms.

This seems to be more an issue of encapsulation than support for ADTs. There's value in hiding concrete representations (ABI compatibility) but C++ works well for my use cases most of the time with concrete representations visible (and this helps with performance which is important in my domain).

As a language user I don't think it's just compiler writers who care about performance :)

I do see the value in something like Go interfaces although it's not a problem I encounter that frequently in my domain. Type erasure is a handy technique in those situations and I think better language support to eliminate some of the boiler plate is desirable. More complexity :)

1 comments

> I'd love to learn more Haskell but for my primary domain (games and VR) it's not a terribly practical option.

Oh, sure, Haskell has lots of defects. (Chiefly among those, being lazy.) I only said that it has something that's essentially concepts, except it has been designed, implemented and used since ages ago.

> This seems to be more an issue of encapsulation than support for ADTs.

The whole point to ADTs is that clients don't get to manipulate the internal representation! What exactly is that, if not encapsulation?

> most of the time with concrete representations visible (and this helps with performance which is important in my domain).

ADTs are about hiding the representation from abstraction clients (other programmers), not from the compiler, of course! In fact, a compiler writer could use ADTs solely for type-checking purposes, and from then onwards proceed as if ADTs didn't exist. So I don't see how using (proper) ADTs must have any adverse effect on performance.

> I do see the value in something like Go interfaces although it's not a problem I encounter that frequently in my domain.

I have to agree, I don't use objects with dynamically dispatched methods much either. My original point was just that C++ classes are neither good ADTs nor good object builders. They're at an uncomfortable point at the middle, with the disadvantages of both, and the advantages of neither.

> I only said that it has something that's essentially concepts, except it has been designed, implemented and used since ages ago.

I'm not sure why this is relevant to the topic at hand though, other than historical interest. What's relevant is that something like concepts are a useful thing for a language to have and C++ will be a better / more usable language with them, even if it means adding 'complexity'.

> The whole point to ADTs is that clients don't get to manipulate the internal representation! What exactly is that, if not encapsulation?

You said "The concrete representation of these three types must be hidden from the user" and mentioned the pimpl pattern which led me to think you were talking about ABI issues. In C++ generally private members are not accessible but they are visible (in headers) and affect object size and layout. That can be a problem for build times and for versioning / binary compatibility but it also allows for private functions to be inlined and avoids pointer indirections and simplifies certain other optimizations (devirtualization for example).

C++ does not currently have a language level concept of modules (and I'm not sure the modules proposal working its way through standardization addresses your issue here) or anything like the C# internal access level. There are patterns to structure your code to enable implementation hiding for collaborating classes in a 'module' but they don't tend to be very widely used due to lack of first class language support. In my own experience I haven't found this to be a huge issue but maybe I just don't know what I'm missing.