Live data from Hacker News

Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

hsutter.github.io

41–50 of 174 posts

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#41

I wonder how this compares with Carbon -> C++ [0]. Carbon is (was?) a fantastic proposal, but not sure if it has lost steam since it was introduced or how well it is being adopted (be it inside Google or outside)? Being able to incrementally/interchangeably use/call existing C++ code (and vice versa) seems like a great design choice (in Carbon) without having to introspect the actual generated code. Not sure how easy…

Herb Sutter briefly talked about why carbon was not a good contender, and I think remembering it was because of backward compatibility with C++.

At some point, keeping C++ semantics matters, since having different semantics would obviously prevent using previous C++ codebases, or make it more difficult to make those work together, and that may be why Carbon may not be a good choice.

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#42
post #22

> Because ++ and -- always have in-place update semantics, we never need to remember "use prefix ++/-- unless you need a copy of the old value." If you do need a copy of the old value, just take the copy before calling ++/-- I actually wish ++ and -- operators were removed. This would simplify everything, nothing to remember whether it's prefix or postfix operator, whether it copies something or not, you would just d…

That is the direction that Swift went: https://github.com/apple/swift-evolution/blob/main/proposals...

Rust and Go made the same choice. In Go, I think i++ is valid - but only as a statement, not an expression.

https://go.dev/doc/faq#inc_dec

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#44

Most of my personal issues aren't with C++ syntax as such (although it also has many problems). My main gripes are: 1. Very slow compilation. 2. Poor encapsulation, adding private functions requires recompiling all dependents, see (1). 3. Comically huge symbols make debugging much harder than it needs to be -- today gdb OOM'd my 16GB laptop when trying to form a backtrace of a typical QT application coredump. Unfortu…

Adding methods changes the vtable layout so there's no way to not recompile all the dependents. There's no solution to this unless private functions are guaranteed to not be virtual.

Wait, what? Virtual methods in C++ are opt-in. You only need the 'final' keyword when you're overriding a method in a child class.

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#45
post #25

Earlier quoted context omitted.

>>> 2. Poor encapsulation, adding private functions requires recompiling all dependents >> under what circumstances does (2) hold? To add a private member variable or function, you need to put it in the class definition in the header file. Then anything that includes the header needs to be recompiled.

Admittedly, adding a private member variable changes the object size and thus the ABI and thus requires recompilation of dependencies. Thinking about that, is there any case in which private functions can end up in a vtable? In that case, it'd break ABI too.

> is there any case in which private functions can end up in a vtable?

Yes, but it generally isn't something that is done.

https://godbolt.org/z/5oPovKzoT

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#46
post #32

Earlier quoted context omitted.

I don't think of pimpl as a tool for speeding up compilation, but for black box encapsulation. If the compile time (when adding a method) is really an issue you can chop up and reconfigure your include files. A pain, but perhaps saves you time in the long run. Of course ( waves hands ) modules will magically improve things...someday.

I think it can be both things. Haven't you ever seen someone do struct Thing; struct OtherThing; in lieu of just including "thing.h"? I see it frequently in real life code bases and I can't see a reason for it other than compilation time optimisation.

Sure, I do that all the time too. But you can't call a method (or look inside Thing, or pass it as an argument, only a pointer to it) without including the definition.

Hmm, there might be some interesting linker hacks to patch things up post compilation. But then you'd want some way to do the forward declaration for cases where Thing could have been passed in registers...

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#47
post #12
post #6

Earlier quoted context omitted.

https://github.com/hsutter/cppfront/wiki/Design-note:-Captur...

Raises more questions honestly. This looks more different from today’s C++ than Rust.

I feel like consistency goes too for losing the visual parsing benefits of special syntax. Otherwise, we might as well adopt lisp's syntax.

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#48

Most of my personal issues aren't with C++ syntax as such (although it also has many problems). My main gripes are: 1. Very slow compilation. 2. Poor encapsulation, adding private functions requires recompiling all dependents, see (1). 3. Comically huge symbols make debugging much harder than it needs to be -- today gdb OOM'd my 16GB laptop when trying to form a backtrace of a typical QT application coredump. Unfortu…

Adding methods changes the vtable layout so there's no way to not recompile all the dependents. There's no solution to this unless private functions are guaranteed to not be virtual.

There isn't that much work the compiler should need to do. Ideally, a clever compiler could just update the vtables in some intermediate representation of the program and re-emit the binary. The C++ compiler today is so insanely wasteful - edit one header file and the compiler re-parses all the header files N^2 times. It should be possible to make a compiler thats way faster than any C++ compiler today.

Of course, the elephant in the room is the C++ preprocessor. I haven't looked too closely into cppfront, but if I had the chance, I'd give the C macro system a bullet.

My favorite "macro" system by far is zig's comptime, which is beautiful and elegant. Zig code can simply elect to be executed in the compiler instead of at runtime. For example, here's how the print() function compiles in zig. Its a thing of beauty:

https://ziglang.org/documentation/master/#Case-Study-print-i...

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#49

Earlier quoted context omitted.

Adding methods changes the vtable layout so there's no way to not recompile all the dependents. There's no solution to this unless private functions are guaranteed to not be virtual.

Um... isn't that guaranteed? What would it mean for a private function to be virtual? It can't be overridden by a different implementation in a child class...

Yes, you can have a private virtual member function, and it can be overridden in a child class (unless declared final), apparently.

I too thought that sounded insane, so I just looked it up. I've been programming C++ for twenty five years and the thought of wanting to do this have never ever occurred to me...

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#50
Someone on reddit said that the cpp2 repo was a bit old, and that is true, although he may have started this as an experiment influenced by typescript and left it on the side at some times.

Anyway I have no idea if cpp2 would get support from microsoft or other devs, but cpp2 seems like the most humble and "least risky" solution for the future of C++, and I really want it to be.

What I remember the most that Herb Sutter said in his cpp2 talk, is that it aims to avoid 95% of bad coding practices that C++ allows today.

It's safe to say that beyond the valid criticism of C++, that it quite a good goal and it would improve C++, without using a new language, and that's good, because a new language causes problems: new toolchains, new semantics, new specifics, no experience on a new language.

Cpp2 is not a new language, it is the same semantics of C++, except it has a new syntax and enforces good practices.

One very interesting point: in the future, cpp2 allows a cpp2-only compiler to be born, and it would still live next to C++ binaries without problem. That cpp2 compiler might probably be much faster since the cpp2 is a smaller stricter subset.

Post reply on HN