Live data from Hacker News

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

hsutter.github.io

51–60 of 174 posts

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

#51

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…

The evolution of C++ has been a multi-decade history of dealing with difficult reality.

I have great hope that Herb can create with his cppfront project “The Very Best of C++” to carry that tremendous legacy forward.

If I was to throw my hat into a “C++ successor”, it would be https://www.hylo-lang.org/ with its “all the safeties” and “tell you when you’re doing it sub-optimal” approach.

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

#52
post #48

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.

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, th…

The problem is reflection, including SFINAE. Code can branch on if a method exists.

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

#53
post #6

Is there any discussion or in-depth explanation of the syntax choices? I understand that a goal was context free unambiguous parsing. But there are some things that surprise me. For example, string interpolation: "Hello, (msg)$!\n" Why “(msg)$” and not “$(msg)”? Surely the latter is easier to parse?

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

What does "for later use" mean?

One thing I've noticed recently is that pretty much no language has a good way to simultaneously define a nested structure and assign that structure a name "for later reuse".

For example -- suppose I'm dealing with some serialized data structure that come from some external system. Very likely the data model behind this value involves "nested values" which have themselves have some type of which might be reused in multiple places by that external system.

When the goal is to just solve problems -- the approach i like to take is to focus on the values i want to consume and produce -- which might themselves contain lots of nested types each with some amount of reuse ...

I'd really like a language feature that supports simultaneously defining a type where it's relevant within some other data structure _and also allows_ giving that embedded thing a name for independent reuse ...

I wonder if this postfix $ syntax is related to that use case at all ...

(... this comment a speculation based on names of things only without even reading the whole article ...)

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

#54
> // 'BufferSize' is an object defined as a synonym for the value 1'000'000

> BufferSize: i32 == 1'000'000;

So "value : i32 = 10" is variable, but "value : i32 == 10" is a constant.

The difference is so subtle I'm not sure I like it.

Later in the documentation you can find "equals: (a, b) a == b;" which is a function but it feels like I need to decipher it because "==" is not for alias in this case.

Retaking the example of "equals: (a, b) a == b;" it feels also odd to omit the braces because they are even enforced for if/else branches.

I have to admit that everything was interesting until the "Summary of function defaults" part.

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

#56
post #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/tru…

Googles habit of dropping support for useful things make me not willing to trust them. I plan for my current code to be in use for at least 20 more years (i plan to retire before then), I don't want to explain to my boss either why we are maintaining a compiler or why we must rewrite working code.

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

#58
post #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 see…

I work on clang and don't know go yet still find the go version easier to read.

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

#59
post #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 see…

> It should be a positive example of how they hope their language is used, right?

should it though? there's a million ways to learn C++. Reading the std code definitely isn't one - technically the std could be entirely compiler builtins. If you want to read positive examples take A Tour of C++ 3rd edition (https://www.amazon.ca/Tour-C-Bjarne-Stroustrup/dp/0136816487)

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

#60
post #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 see…

Part of the distinct "C++ std" style is due to naming rules and textual includes. Every name that's not part of the standardized interface starts with __ because __foo and _Foo are blanket reserved names, so a user can't complain that std:: explodes when he does "#define _Base 0".
Post reply on HN