Live data from Hacker News

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

hsutter.github.io

21–30 of 174 posts

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

#21

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.

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

#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 do "value += 1" and be done with it.

- Less mental overhead.

- Remove an extra way of doing the same thing.

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

#23
post #10

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…

under what circumstances does (2) hold? for vanilla methods it's no problem

Adding private functions or fields requires changing the class declarations, which requires rebuilding any code that includes that class deckaration. It shouldn't be like that, especially for methods which shouldnt change anything about the class ABI.

Even worse, this dependency is transitive. Dependencies to allow defining these private methods an fields are exposed too, forcing inclusion of headers to all members of the class, even if it's only implementation details.

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

#24
post #20

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.

they don't need to be. dependents will continue functioning, because ABI hasn't changed

Now explain that to my build system.

But even if you managed to do that, first compilation is still much slower than it should be, because anlot of headers have to be included (transitively) to allow even declaring these fields and methods.

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

#25
post #10

Earlier quoted context omitted.

under what circumstances does (2) hold? for vanilla methods it's no problem

>>> 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.

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

#26
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...

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

#27

Unfortunately the first example already re-uses one of the less good parts of C++, the "<<" operator for std::cout, which always was a bit of a hack (including strange order of operations since << normally is left shift)

Note that the "<<" operator for std::cout is not related to the language itself but related to the standard library.

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

#28
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…

But you would break the name! C++ would be a syntax error!

I mean, there are people that already think that...

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

#29
It was when debugging a memory leak which occurred because I forgot to declare the base class destructor as virtual that I started to think C++ was a rather unfriendly language and not really designed to be easy to use.

Then a few years later I read the spec for std::launder that I realised C++ was not really designed to be understood.

It's a shame because it's actually a rather nice language in some ways. Here's hoping that this project or something similar takes off and separates the good bits from the bad.

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

#30

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.

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...
Post reply on HN