Live data from Hacker News

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

hsutter.github.io

111–120 of 174 posts

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

#111
post #96

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.

In typical c++ manner, we can’t have nice things because {obscure internal technicality that don’t impact the user in any way whatsoever}$. As a user I don’t care what a vtable is. Just make it work. Other languages don’t have this problem. During release builds sure, optimize away with LTO and whatever is needed to make it vroom. During development, waiting several minutes for a minor private function update is just…

C++ is designed for good performance. Solving ABI problems permanently usually means an extra layer of indirection, which hurts performance.

There are also concerns about what you can link against or not once you modify the ABI of widely used types. This is of real concern at least for closed-source software or software that just cannot be recompiled.

I am not saying it should be the right choice, some of that software is legacy. I just say this is a real concern.

As for the private function. You can use a pimpl and use a private (on the cop file instead of header) and use that, for example, in many cases. This keeps compile time down.

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

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

Pimpl is both. I use it as black box also, but it does both things.

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

#113
post #98

Earlier quoted context omitted.

> 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. That ship has sailed. They already have C#.

C# is so old by now, if it would be a good replacement for C++ at MS, it would already have replaced it.

Java and C# are in their "let's get functional" phase.

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

#114

Earlier quoted context omitted.

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.

Hylo is interesting in principle for exploring this particular notion (mutable value semantics) as a way to potentially write software without the lifetime annotations Rust needs. But I don't find it promising that after apologising in 2023 for missing their self-imposed 2022 deadline to ship something that works and other people can use, in Q2 2024 it doesn't look like their new 2023 roadmap got done either. Maybe t…

For me Hylo is the most elegant object model I have seen so far in the sense that it achieves dafety without all the anniyations and borrow checks that Rust performs. It just fits well the model for thinking yet it enables lots of optimizations. Of particular mention is that copies are lazy and can be passed freely and will only be done transparently on demand. That is what keeps the model simple.

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

#115

Earlier quoted context omitted.

C# is so old by now, if it would be a good replacement for C++ at MS, it would already have replaced it.

Java and C# are in their "let's get functional" phase.

:(

C# has been at that for more than a decade and a half already. Java's arrival to the party is extremely late and still lacking in many areas.

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

#116

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)

I've always thought that using "<<" in that manner was more of a way to show off the operator overloading feature than anything else.

I think the original point was to make a typesafe printf that's still reasonably efficient without creating a bunch of small temporary strings. Like, if you printf like this:

    printf("Number %d, String %s", n, s);
but the types of n and s aren't int and char*, all hell breaks loose and you have the origin of a million CVEs. But how do you make that function signature typesafe, without the tools of modern templates? You sort of can't. One thing you can do is do string append stuff, but the syntax then is annoying:

    print("Number " + to_string(n) + ", String " + s);
This also creates a bunch of temporary strings, which is not ideal (and still relies on operator overloading, btw). In this world, using operators for this does make some sense:

    std::cout 
Like, seen from this perspective, it's not the worst idea in the world, it does work nicely. The syntax really isn't too bad, IMHO (the statefulness part, though, really sucks). It also allows you to add formatting for your own types: just overload operatorClearly, properly type-safe std::format is vastly superior, but the C++ of the 90s simply didn't have the template machinery to make that part of the standard library.

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

#117

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)

Don't you think it just serves to highlight that Cpp2 is just C++? That it's explicitly not some new language with C++ FFI like Carbon.

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

#118
post #6

Earlier quoted context omitted.

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

I think $() makes much more sense than ()$ in terms of parsing, when you see $ you're looking for a single word token, and $( you're parsing up to the matching ) Maybe it's not much extra workload, but ()$ requires you to pattern-match all bracketed content in a string as a possible capture, and the parser can't determine whether it's a capture or not until the $ or a matching close bracket. Consider parsing "((x)$)"…

> Maybe it's not much extra workload, but ()$ requires you to pattern-match all bracketed content in a string as a possible capture, and the parser can't determine whether it's a capture or not until the $ or a matching close bracket.

You don't have to: you can also just parse the string backwards.

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

#119

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

Child classes can override private member functions in their parent class.

Making all virtual functions private is the better way to implement inheritance: it separates implementation from interface, allows for common functionality to be moved to the base class without requiring gymnastics in each and every derived class, and even lets you simplify the public interface to reduce compile times.

Try it, you'll like it. You may never go back to writing Java in C++.

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

#120
post #40

Earlier quoted context omitted.

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 think the c++ version could be more understandable but it’s as if the authors intentionally made it as obtuse as possible.

The authors are required to make it obtuse. They're required to use warts on all of the names because most of the code is in the head files and is generative code compiled by users of the library rather than the vendor. In order to avoid naming conflicts they can only use obscured names in their implementation of any but the defined API (eg. naming any internal functions, macros, or variables with leading underscores).

So, the authors did intentionally make it as obtuse as possible for your benefit. It's written to be used, not studied, by all kinds of developers in all kinds of circumstances.

Post reply on HN