r/cpp • u/unaligned_access • Nov 02 '24
Cppfront v0.8.0 · hsutter/cppfront
https://github.com/hsutter/cppfront/releases/tag/v0.8.028
u/matthieum Nov 02 '24
The documentation link in the README is a 404 :'(
One (more) opportunity for CppFront would be adding proper pattern-matching for optional and variant, and perhaps even proper sum types. I couldn't check whether it had them, though, due to aforementioned 404...
16
u/_TheDust_ Nov 02 '24
Adding sum types, tuples, and pattern matching to the language would be a huge step forward!
7
u/RoyKin0929 Nov 02 '24
Pattern matching and sum types are already a part of cpp2, not tuples though.
1
u/tuxwonder Nov 02 '24
Thru std::variant? Or some other mechanism? I forget now...
3
8
u/hpsutter Nov 03 '24
The documentation link in the README is a 404 :'(
Thanks for reporting this. Weird -- I think I found the problem and it seems to be fixed now, please check.
1
6
u/HommeMusical Nov 02 '24
I'm fairly sure the source pages for the documentation are here: https://github.com/hsutter/cppfront/tree/main/docs
12
u/ntrel2 Nov 02 '24
As the docs link is down, you can read the docs here: https://github.com/hsutter/cppfront/blob/main/docs/index.md
10
9
u/DataPastor Nov 02 '24
Wow. With this new license, also heading towards 1.0 this is getting more and more interesting. Thank you!!
51
u/RandomGuy256
Nov 02 '24
•
This really feels like what C++ was for C. Even though it says it is not a new language, it could become a new one. A simpler, safer C++ like alternative. This project has kept my attention since day 1, not only because of the general idea but also because Herb Sutter is behind it, who I admire.
P.S. The documentation page is broken for me.
19
u/matthieum Nov 02 '24
This really feels like what C++ was for C.
It evens borrows the naming convention :)
7
21
u/ronchaine Embedded/Middleware/WG21 Nov 02 '24
Even though it says it is not a new language, it could become a new one
I have never understood with what merits it claims it is not a new language, because it for all intents and purposes is. And any reasoning I've heard doesn't stand up to even slighest scrutiny.
That said, I have little against people working on new programming languages, and I've taken much inspiration from Herb's papers for the one I'm writing for my own enjoyment. I just really don't like when cpp2 is somehow getting preferential treatment from all the other "successor" languages, when it's actually further departure from C++ than some of the others.
24
u/germandiago Nov 02 '24
It is the most compatible one with C++ because it is a transpiler and it allows you to mix and match more easily.
I think that is the reason why some people (including myself) find it appealing.
4
u/JVApen Clever is an insult, not a compliment. - T. Winters Nov 02 '24
Can you elaborate on where you see preferential treatment?
9
u/ronchaine Embedded/Middleware/WG21 Nov 02 '24
Being treated differently in regard to rule 4 than other similar projects.
19
u/BloomAppleOrangeSeat Nov 02 '24
The second sentence of that rule is exactly what this language stands for. Herb has said before(can't look for sources right now, but I could swear it was in a cpp conference) that this language is serving as a "playground" if you will, to get ideas in order to improve C++ itself. Most other languages are instead running away from C++.
0
u/pjmlp Nov 03 '24
Which can hardly be, when it doesn't even use a C++ like syntax as Circle does for example.
So by definition any of these ideas if they ever come to C++ proper won't be using any of Cpp2 syntax changes.
3
4
u/foonathan Nov 03 '24
I don't think this is a conscious decision. We usually only act when someone reports a post, and nobody has reported this submission as being off-topic. But we haven't had an internal discussion about the 'other language' rule for quite some time.
So it's only treated differently because the community treats it differently.
2
u/ronchaine Embedded/Middleware/WG21 Nov 03 '24
Yea, I did not mean to imply that it was intended, just that it seems to happen for one reason or another. Sorry if that made it sound like I did. To be clear, I don't think there's any conspiracy or malice behind that.
4
u/cleroth Game Developer Nov 03 '24
Which other projects?
Posts about Circle that have relevance to C++ are always approved AFAIK. In contrast, languages like Carbon aim to replace C++, in which case they're not that different from Rust, so posts about Carbon will undergo the same scrutiny as with Rust--they can be approved if and only if they're actually of realistic benefit to C++.
2
u/bandzaw Nov 03 '24
Circle posts have definitely not always been approved! Only recently they have, which is good thing IMHO. The same for this post. They really are about C++ and its future so why shouldn’t discussions be allowed here?
1
u/ronchaine Embedded/Middleware/WG21 Nov 04 '24
Circle was the thing first in my mind.
I'm pretty sure (though not absolutely certain) that I've seen Circle posts removed in the past, to the point that I remember seeing Sean himself mentioning it.
How I see it, Circle is (was?) a C++ compiler with a good bunch of extensions. That is far closer to actual C++ than I see any other thing, cpp2 included.
To me cpp2 is a language designed to transpile to C++, much like nim is. So far the points against that are Herb saying it's not so (and people going with it). I do not see the fact that much of the stuff that are prototyped there might end up as committee papers too relevant, as we pretty much take stuff from a lot of other languages.
Carbon is another language entirely, and doesn't even claim anything else.
What I see problematic is that if e.g. a Circle release post (which - and I might be wrong here - I recall being removed) isn't relevant for C++, how is cppfront release any more relevant?
Again I'm not saying this is intentional or some conspiracy to stifle Circle. It might well be community just being more triggerhappy with reports about Circle than cpp2, but it still rubs me the wrong way.
5
u/cleroth Game Developer Nov 04 '24
it still rubs me the wrong way
Funny you mention that, as that's exactly how I felt about Sean's tweet about this post's removal. I explained on twitter the reasoning so I won't repeat myself, but I did even mention there that it wasn't that Circle is offtopic, but that particular post was.
At least authors of other languages/extensions aren't circlejerking on other social media and calling us corrupt while ignoring any attempt at civilized reconciliation.
1
u/ronchaine Embedded/Middleware/WG21 Nov 04 '24
I don't know what goes on in Twitter, because I like to preserve my sanity and Twitter definitely isn't good for that. I do not think whatever drama happens in there should affect what posts are allowed or disallowed in C++ reddit, and I hope that it doesn't.
I see no reason to ask me something just to turn the reply into something about whoever or whatever group might or might not be circlejerking in an unrelated social media platform I haven't even been a part of in ages. I tried to explain why I have the impression I have. I'm sorry if people have been jerks in Twitter, but I don't think I'm the person you should take it out on.
1
Nov 02 '24
It compiles to C++. C++ doesn't compile to C. If at any time you want to abandon cppfront, you just take the compiled C++ code and get on with your life in normal C++ land. You can't do that with C++. Whether or not you think that means it's not a separate language is up to you, but it's not remotely the same thing as C++ vs. C.
27
u/throw_cpp_account Nov 02 '24
C++ doesn't compile to C.
It used to. That's how it started.
16
1
u/F54280 Nov 03 '24
Tell me you weren’t programming in the 90s without telling me that you weren’t programming in the 90s…
0
Nov 03 '24
Breaking news, not everybody was a programmer in the 90s and what was true in the 90s doesn't necessarily have any bearing on what is happening today.
2
u/F54280 Nov 03 '24
“C++ doesn't compile to C” is an hilarious take for anyone that knows a bit about the language history.
But I get it, you’re salty. That’s fine. Have fun with that downvote button.
4
u/c0r3ntin Nov 03 '24
And like C++ was never able to fully outgrow C, this surface-level reskin has the same fundamental limitations as C++
5
u/ntrel2 Nov 03 '24
Can you list those limitations?
3
u/foonathan Nov 03 '24
My far biggest problem with C++ are compile times. Something that transpiles to C++ by definition can't help there.
16
u/hpsutter Nov 03 '24
Something that transpiles to C++ by definition can't help there.
I have super awesome news: It sure can! Please check out the initial results I reported at ACCU here, especially slide 92: 4-minute video clip
We did pretty much exactly the same thing already with
constexpr: It required adding essentially a C++ interpreter (yes, a second C++ compiler!) inside every C++ compiler... and when you change TMP code to equivalentconstexprcode the result is nearly always much faster. Even though you're running a full C++ interpreter first! Why? Because when we directly express intent, the implementation can be more efficient, and compile time goes down.In that clip, I cited that previous experience, and showed how the same thing happened with compile-time regex in Cpp2 using cppfront + reflection + generation, and that the entire added cppfront run time was much less than the reduced time spent in the Cpp1 compiler. When using code generation can generate better C++ code that the C++ compiler can handle much faster, you get a speedup, not a slowdown.
As I mention in the talk, this is the same in principle as we do all the time to add a little work to replace a greater amount of work. For example, anytime we cache a repeatedly-accessed computed result: We do more work (to store the result) but get a speed gain (because we make accesses after the first one run much faster).
3
u/foonathan Nov 03 '24
I'm not talking about small incremental improvements by replacing TMP with constexpr or something.
Compile-times should be measured in seconds, not minutes. You can't achieve that by layering C++ in-between. You can achieve that by designing a language and a compiler in a performance oriented way. For example, Chandler recently demoed a 100x speedup of the carbon compiler over clang. That is what I'm talking about.
8
u/hpsutter Nov 03 '24
Well, you originally said "by definition can't help" compile times. So I gave an example where it does. :)
Compile-times should be measured in seconds, not minutes. You can't achieve that by layering C++ in-between.
OK, so you mean "can't help enough to make them an order of magnitude faster" -- I understand.
FWIW, if you haven't looked at the short video clip, please do... it does show a possible major (not quite 2x) improvement in C++ compile time for approximately equivalent code, compared to today's best-in-class design. Using existing C++ compilers unchanged.
recently demoed a 100x speedup of the carbon compiler over clang.
That's great, and I look forward very much to seeing how much of the speedup can stick as it matures to handle more kinds of code.
That said, let me add a caution about wording: I agree we should focus on "build time" as a pain point for C++. However, "front-end compile time" is a subset of that. A lot of today's slowdowns in C++ builds come in other build stages, such as linking. There is great work currently being done (unrelated to these projects) to dramatically (2x, 4x) speed up C++ linkers that can handle real-world code. In just the past couple of months I've seen these start getting the attention of key folks in WG21 and major vendors, to see what we can incorporate. Disclaimer: As always including in previous "fast linker" efforts, part of the performance gain comes from making simplifying assumptions that don't work on all real-world code, but part of the gain doesn't rely on that.
2
u/ntrel2 Nov 03 '24
Just like with how people use C compilers and not cfront, people could make a pure Cpp2 compiler that isn't a transpiler. A transpiler is good for the transition, and for faster experimenting.
1
u/foonathan Nov 03 '24
It could, but it doesn't. A language that provides 100% seamless interop with C++ without transpiling to C++ is a significantly harder thing to do than for C (what do you do about templates? how do you instantiate templates cross-language?). This is what Carbon is trying to do. And by that point you're no longer layering on top of C++.
1
2
u/These-Maintenance250 Nov 02 '24
because people would come at him with pitchforks if he said its a new language for forking the language and dividing the community. this is clear from his first cppcon presentation on cpp2, he really really emphasized its not a new language. c++ community is allergic to change.
-1
u/pjmlp Nov 03 '24
This is also my point of view, we just need to look at C++, Objective-C, Typescript history to see how that all "it isn't a new language " developed.
10
u/tuxwonder Nov 02 '24
u/hpsutter great update, glad to see the new terse function syntax! I'm curious, has there been thought put into using meta functions/metaclasses in a similar manner to python's decorators? As in, passing parameters into metaclasses? Could be useful for a whole host of things (specifying serialization format, annotating test fixture classes...)
9
u/hpsutter Nov 03 '24
Thanks! Yes, some of the current metafunctions do take parameters, for example
enumandflag_enum(which are compile-time consteval functions in Cpp2, not hardwired language features) take the underlying type as an optional parameter, otherwise computes the smallest possible type.
5
u/germandiago Nov 02 '24
Thank you for this. Next weekend or so I will give a try to my in-progress conversion of a codebase that I had been porting but I got stuck with some bugs I reported.
As for the in_ref forward_ref in min: is this equivalnet to the C++ min function or it is safer to use in any way?
6
u/RoyKin0929 Nov 02 '24
It is not any safer than the cpp equivalent. Currently, cpp2 does nothing towards lifetime safety, but I think there are plans to do something in this area.
1
2
u/Dminik Nov 03 '24
As an outsider I'm genuinely curious.
Are there any people here who dislike rust syntax, prefer c++ syntax and also like the cppfront syntax? If so, what do you prefer about it? I know that rust syntax can be a hot topic so I'm wondering what your thoughts on this are.
For people who dislike the cppfront syntax: How do you feel about this possibly being the future of C++?
5
u/Occase Boost.Redis Nov 02 '24
Where can I find a summary about how Cppfront compares to Rust in terms of memory safety? Will it stop this avalanche of recommendation of different organs to stop using C++?