Live data from Hacker News

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

hsutter.github.io

31–40 of 174 posts

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

#31
post #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.

But in a "C++ 2" helloworld one would really expect to see std::println used instead [1].

[1] https://en.cppreference.com/w/cpp/io/println

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

#32
post #10

Earlier quoted context omitted.

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

C++ build systems are typically based on file timestamps. Modifying a header file triggers recompilation of all translation units including that header. There are workarounds like pimpl (aka. C style encapsulation). But this requires extra boilerplate and indirection. C++ modules might fix it at some point, but after 35 years of not having them in C++ most real life codebases aren't set up that way and may never be.

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.

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

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

We could allow overloading operator++ while not defining it on anything built-in....

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

#35

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…

The roadmap for Carbon [0] mentions wanting to have basic, non-trivial programs written in Carbon by the end of 2024. They're aiming for a v0.1 release in 2025. If it gains traction, they're aiming for a v1.0 beyond 2027.

I don't think anyone outside Google will seriously adopt this before it reaches v1.0. Even within Google, they may choose other options.

[0] - https://github.com/carbon-language/carbon-lang/blob/trunk/do...

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

#36

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…

I laughed at (3)

Although QT is not a tiny framework, and I don't really know if modern C++ tools are really good enough for this sort of problem, since C++11 to 20 probably caused those tools to explode in memory consumption

But I am not surprised at all. I remember around 2013, I would use bullet physics and the Ogre3D engine, and I had to tell visual C++ to increase its memory capacity because the compiler would refuse to continue.

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

#37
post #7
post #4

Like Kotlin to Java Or ReScript to OCaml Or Gleam to Erlang

Kotlin is a distinct language with new features that (I'm fairly sure) make it non-isomorphic to Java code though. But I can't speak on the others.

not sure what "(non)-isomorphic" but Kotlin code is interoperable with Java code in both directions. You can easily call Java-code from Kotlin (but I guess that's the easy direction) but you can also call Kotlin code from Java. There exist specific annotations to control how Kotlin code will be converted to bytecode and therefore be invoked from Java, e.g. a function in a Kotlin companion object would normally concerted into a function of a Singleton property called INSTANCE on the base class, but if you annotate it with @JvmStatic it will become a static method of that class in bytecode instead. This means you can write a Kotlin lib that feels very normal to call from Java. here's the relevant part of the documentation: https://kotlinlang.org/docs/java-to-kotlin-interop.html So yes, Kotlin is considered to be a successor language, not just another language (also) compiling to the JVM.

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

#38

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

`final` prevents a child class from overriding a method. `private` does not.

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

#39
post #32

Earlier quoted context omitted.

C++ build systems are typically based on file timestamps. Modifying a header file triggers recompilation of all translation units including that header. There are workarounds like pimpl (aka. C style encapsulation). But this requires extra boilerplate and indirection. C++ modules might fix it at some point, but after 35 years of not having them in C++ most real life codebases aren't set up that way and may never be.

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.

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

#40

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 hop…

Yeah... its shocking to me how difficult it is to read the C++ standard library. Surely, the standard library is written by the authors of the language. It should be a positive example of how they hope their language is used, right?

Here's the source of C++'s vector class:

https://gcc.gnu.org/onlinedocs/gcc-4.6.2/libstdc++/api/a0111...

In comparison, vec in rust. (Note you need to scroll down a few pages to start seeing non-trivial functions. There's a lot of block comments.):

https://doc.rust-lang.org/src/alloc/vec/mod.rs.html#398

Or list in Go:

https://cs.opensource.google/go/go/+/master:src/container/li...

To my eye, that C++ code is by far the hardest code to read.

Post reply on HN