HN Theater @HNTheaterMonth

The best talks and videos of Hacker News.

Hacker News Comments on
CppCon 2017: Herb Sutter “Meta: Thoughts on generative C++”

CppCon · Youtube · 55 HN points · 4 HN comments
HN Theater has aggregated all Hacker News stories and comments that mention CppCon's video "CppCon 2017: Herb Sutter “Meta: Thoughts on generative C++”".
Youtube Summary
http://CppCon.org

Presentation Slides, PDFs, Source Code and other presenter materials are available at: https://github.com/CppCon/CppCon2017

Two years ago, I started to focus on exploring ways that we might evolve the C++ language itself to make C++ programming both more powerful and simpler. The only way to accomplish both of those goals at the same time is by adding abstractions that let programmers directly express their intent—to elevate comments and documentation to testable code, and elevate coding patterns and idioms into compiler-checkable declarations. The work came up with several potential candidate features where judiciously adding some power to the language could simplify code dramatically, while staying true to C++'s core values of efficient abstraction, closeness to hardware, and the zero-overhead principle.

The first two potential candidate features from that work to be further developed and proposed for ISO C++ are the <=> unified comparison operator (minor) and what I've provisionally called "metaclasses" as a way to generatively write C++ types (major). This talk is about the latter, and includes design motivation, current progress, and some live online compiler demos using the prototype Clang-based compiler built by Andrew Sutton and hosted at godbolt.org.

Herb Sutter - Software architect, Microsoft

Herb chairs the ISO C++ committee and is the primary author or co-author of a number of Standard C++ features, including nullptr, enum class, parallel algorithms, C++17 structured bindings, and the in-progress unified <=> comparison operator.

Videos Filmed & Edited by Bash Films: http://www.BashFilms.com
HN Theater Rankings

Hacker News Stories and Comments

All the comments and stories posted to Hacker News that reference this video.
To a degree, but templates and constexpr don't support a bunch of features like compile-time field enumeration and introspection + code generation.

For example, let's say I have a bunch of structs:

  struct GeoCoordinate {
    int lat, long;
  };

  struct GeoArea {
    std::vector<GeoCoordinate> perimeter;
  };

  struct Place {
    std::string name;
    std::string contact_number;
    GeoArea area;
  };
Now I need to serialize these structs into a format to be sent over the wire. Currently, I have a few choices:

1. Use an off-the-shelf library like protobuf (disclaimer: I work for Google). Then I have to convert my code to a protobuf definition and rely on its code generator to perform [de]serialization. I also have to hope that my library supports all the field definitions I need.

2. Write macros to define each field in each structure. These macros perform some arcane magicks that somehow create the necessary [de]serialization functions. These macros are difficult to write and maintain (or I find a library).

3. Manually define the methods myself. This is tedious, hard to maintain, and error prone.

What if I could write some code in C++ which could read the structure and generate the appropriate serialization code? Something like (syntax hypothetical):

  Serializable(Class) {
    std::string serialize() {
      std::string output;
      for (auto member : Class.members()) { // loop unrolled at compile time
        if (member.type == int) {
          output.append(std::format("{:10}"), member.get())
        } else if (member.type == std::string) {
          ...
        } else if (member.type == std::vector) {
          ...
        } else if (std::has_metaclass_v<member.type, Serializable>) {
          output.append(member.get().serialize());
        }
      }
    };
  };

Then I could annotate my classes with Serializable instead.

See https://www.youtube.com/watch?v=4AfRAVcThyA.

kthielen
Yeah static structural reflection is an important use-case. The main objection I’ve heard to standardization in C++ has to do with maintaining the mistake of conflating structs and classes and supporting C’s long broken unit type.
A few years ago Herb Sutter proposed Python-like metaclasses in C++ through compile-time code generation. Not sure if anything has been proposed for general use.

https://www.youtube.com/watch?v=4AfRAVcThyA

OneGuy123
Unreal Engine 4 creates C++ reflection classes by parsing the headers and some of their custom macros that you define for member variables & function.

It basicaly allows you full C++ reflection, but only for classes that you mark with the UE4 macros.

The talk about the reflection proposal was amazing. Meta classes are also very cool. We can only hope it comes fast.

https://www.youtube.com/watch?v=4AfRAVcThyA

Herb Sutter's talk about it is by far the best talk I've seen from from CppCon17.

"Meta: Thoughts on generative C++" - https://youtu.be/4AfRAVcThyA

Sep 29, 2017 · 55 points, 22 comments · submitted by vowelless
vowelless
Here is the paper on metaclasses: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p070...
kccqzy
Wow, this looks like a huge change to the language. Reminds me of macros done well though.
pjmlp
Yes, it is quite nice. But how good things go, this might just be standardized post C++20.
snaky
There's no much hope C++ to go away any time soon, so C++20 is fine, there are C++25, C++30 and C++48 for more features to add.
pjmlp
As polyglot dev, I am kind of ok with C++17 and beyond, as ANSI C++ groups at least care about improving the security story, not like ANSI C.
snaky
I know it's unpopular, but I think security is overrated. No, I don't like the way it is, but really - do we know a company that gone bankrupt due the security breach? Do we know a single mobile app that lost it's major audience due the data exposure, or broken crypto implementation? Do we know any business that gone out of business due the security related reasons?

I'm not saying we should not care, but I'm convinced we can't turn the table over by polishing the tools. The user's perception of security is a show stopper as for now.

lomnakkus
> I'm not saying we should not care, but I'm convinced we can't turn the table over by polishing the tools.

Why?

We know for a fact that GC'ed langauges can e.g. prevent double-free for ever and ever. Obviously, this is modulo the language/runtime implementation, but if there are bugs there you fix them once and every single program out there gets the fix instantly.

Similarly for many other types of 'dangerous' bugs.

VHRanger
"3years is not a long time" says the std committee.

If it's in standard in 2023 we can use it at work in 2025-2027 for those of us at particularly fast companies

pjmlp
I only use C++ for native libraries accessed from Java/.NET, so it doesn't hurt me that much, given the average code size.

But things are much nicer nowadays than on the late 90's when I had to use the OS vendor C++ compiler for each system we were targeting, while ANSI was still designing what would become C++98.

Or the C compilers transitioning between some kind of K&R C support and ANSI C89.

hellofunk
I know a lot of companies that immediately adopt the new standards in C++, sometimes as soon as the compiler supports them, even if the standards aren't official yet.

For example, I was working at a company that was using C++14 features in 2013.

zarkov99
Right. We now have two world class compilers, gcc and clang, which both track the standard closely and this has forced Microsoft to improve their compliance as well. It is a golden age for C++ right now.
harry8
The golden age of C++ is that java, python, ruby, clojure javascript and so on all exist so developers who have a dislike and/or perhaps low aptitude for C++ aren't in your codebase because it really isn't the only game in town.

Compiler support, standardisation of things we needed in the late 80s sure. great, yeah, all good and helpful.

Not having a constant standing fight to keep the worst nasty rubbish out of your codebase so you can get on with writing code that achieves something useful in a manner that's not hideous. That's a change that didn't come from within C++.

C++ culture from Bjarne on down is still hideous. Arrogant, aggressive and generally nasty. Fix that and we'd really get the golden age. I stay as far away from C++ "people", committees, conferences etc. as I can. Yeah "No loss" would be the usual response and I'm sure that's true, I'm not such a genius that the loss of me matters at all. There will be plenty more, some of whom have great contributions they will make elsewhere, to think otherwise is just the usual C++ "smart people" nasty, competitive arrogance.

hellofunk
> C++ culture from Bjarne on down is still hideous. Arrogant, aggressive and generally nasty.

This is the complete opposite of my experience. Most are among the most humble people I've met.

harry8
"I understand what you are trying to say and I think that you are wrong." --Bjarne Stroustrup, to a chorus of razzes, jeers and laughter at a question in going native a few years back.

https://www.youtube.com/watch?v=OB-bdWKwXsU about 1:09:30

But hey don't take my word for it, my reputation is nothing and I'm as anonymous as a wrong number whether I like it that way or not. How about Ken Thompson? His doesn't seem to be similar, if you like an argument from authority - and I think such argument has a place if not used exclusively.

"I would try out the [C++] language [at AT&T] as it was being developed and make comments on it. It was part of the work atmosphere there. And you'd write something and then the next day it wouldn't work because the language changed. It was very unstable for a very long period of time. At some point, I said, no, no more. In an interview I said exactly that, that I didn't use it because it wouldn't stay still for two days in a row. When Stroustrup read the interview he came screaming into my room about how I was undermining him and what I said mattered and I said it was a bad language." Ken Thompson; cited in Seibel, Peter (2009). Coders At Work. p. 475.

Alexandrescou openly criticises Alasdair Meredith at cpp con in a way that isn't really friendly or respectful. He also finishes all his talks with "Destroy!" as an open acknowledgement of the defensiveness he feels about the naked hostility that exists in the C++ world. I like his stuff and the bulk of his attitude, I hate the context and that it brings rubbish like this out of him.

newsgroups (remember them?), c++faq - in which the most arrogant and hostile entries seem to correlate pretty closely with all the stuff widely acknowledged to be horrible (eg auto pointer, remember that?). Think about it, remember all the c++ places you've been. Which were really, actually, you know, friendly?

Compare the general tenor of it all to the Python community, the Perl community, the Ruby. Hell even compare it to the way the python community and the Perl community interact with each other and it's vastly more pleasant. C++ is just straight up nasty, competitive, "No you're wrong because I'm smarter than you" "I've been anointed" garbage and it needs to be called as such. It really holds everything back. If I had to pick a word to describe it that word would be "macho."

I think it's reasonable to suggest that if one has a point of view, make the argument, back it with your evidence, acknowledge that those who disagree are neither heretics nor idiots is the right thing on a number of levels.

pjmlp
C++ is pretty much the only game in town for those having those alternative languages running at all.

When LLVM, GCC, JVM and CLR stop being written in C++, then we have sound alternatives.

Java Metropolis or .NET Native with Rosyln are not there yet.

Rust doesn't seem to be taking over systems development at any major commercial OS for the time being. Hopefully it will, if Fuchsia ever becomes a commercial product.

Swift is pretty much an Apple only language and isn't fully stable yet.

So until then, I rather take a polyglot approach C++ and Language X, while helping drive away the C style coding that plagues our stacks.

harry8
If you want to /write/ code there are many options. The most significant of the ones I listed is Java. If you don't like C++, pointers and such Java is actually a nice language and people can and do get jobs programming in that language and do good work there. They don't write code in my C++ code base anymore. The overwhelming majority of people writing C++ nowadays actually want to write code in C++ and have alternatives where they can get paid, well, if they didn't. It really wasn't always that way.
pjmlp
There is more to a project than a programming language used in isolation.

There are many scenarios where C and C++ are the only mature tools available. Unless you want to play the snowflake using unsupported tooling and willing to take full responsibility when things go wrong.

Given that, I will pick C++ over C every single time.

harry8
And anyone who buys this line doesn't work on /those/ projects if they don't like C or C++ and are not in /your/ codebase. They're doing programming something else entirely (maybe in javascript, for example?), hopefully well, not writing C++ code you have to deal with, badly. Do you see the point I'm making?

Given that, this comment and thread was never about C++ vs C but I acknowledge this is the default C++ flame war that has been going on for decades so bringing it up, out of context and with zero supporting reasoning let alone evidence really illustrates the point about the problems of the C++ community nicely, thanks for that. Imagine a golden age of C++, it'd be awesome.

pjmlp
So in what programming language is the compiler, interpreter, VM of yours written in?
harry8
so if you don't want to work in C++ you work on something else But you're still a programmer who likes writing code. You only program in C++ on projects where this makes sense if you like it. Do you not see this point. I'm not sure how to articulate it more clearly?
UnpossibleJim
This might be a sloght departure, sp forgive me, but what exactly is going on with Rust? Their user base is rabid and loyal as any as I've seen, and their evangelists spout out content at a fair pace, but it doesn't seem to be gaining a huge amount of popularity (I may be wrong, but I've seen very little demand/job postings). Has it just not hit critical mass, is there not enough general utility or is the thought of leaving a language with a C in the name just too frightening?
steveklabnik
https://www.rust-lang.org/en-US/friends.html is a non-exhaustive list of companies using Rust in production.

Many don't explicitly hire Rust devs, but hire devs in general, as they won't just be working on Rust projects, but also on others. That's not always the case, but it's common. For example, Amazon recently posted a job listing saying that "Rust knowledge is a plus," that's because a small bit of it is in Rust, but you need to be familiar with other tech too.

pjmlp
The actual Rust developers are not like that, they are quite friendly and help anyone that wanders into their forums.

Google is already using Rust on a few ChromeOS and Fuchsia libraries.

Firefox is getting more components ported from C++ into Rust.

Microsoft adopted a regexp engine, written in Rust, for Visual Studio Code.

So some victories, but the language still needs to mature in a few domains, UI, IDE, DB drivers, graphical debuggers, processors, and these things take time.

It took C++ almost 20 years to steal some industries from C, while others still choose C and Assembly as their daily tools.

It takes years to replace tooling, and many times the sucesses are not only technical, but are heavy influenced by social and political reasoning.

HN Theater is an independent project and is not operated by Y Combinator or any of the video hosting platforms linked to on this site.
~ yaj@
;laksdfhjdhksalkfj more things
yahnd.com ~ Privacy Policy ~
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.