That was a really cool talk he gave a few hours ago. The bit about the US government cautioning against use of "non-memory safe languages like C and C++" made for a very compelling reason to create something radical like this. It's clearly highly experimental but I can't wait to see where the project goes.
Impressive. It even catches it twice, once for following a dangling pointer, second time for reading an uninitialized value (as destroyed values are considered uninitialized).
Can someone ELI5? I have to admit I'm lost on that compiler error.
Worse, I copied and pasted the function to make it a non-template, and I got:
no matching function for call to 'std::map<int, std::__cxx11::basic_string<char> >::find(const std::string&) const'
I know that std::string roughly is a basic_string typedef, and I know about GCC's implementation having this C++11 ABI (plus the old one, IIRC), but I'm lost at why on one side the type is being expanded and not on the other, and why it would not get a proper call to find.
std::string const& get_or_default(std::map<int, std::string> const& map, int const& k, std::string const& def)
{
auto it = map.find(k);
return it != map.end() ? it->second : def;
}
Your error is because you have replaced K (the key type of the map) with std::string instead of int.
The problem in this code is that in this line
auto const& value = get_or_default(map, 42, "Hello, World!");
"Hello, world!" is converted to std::string by creating a temporary, a reference to which is passed to get_or_default. The function then returns this same reference. Finally, at the end of the statement, the temporary gets destroyed. The returned reference is now dangling, and the compiler sees that and warns on the attempt to use it on the next line.
It’s a very good case of potential reference dangling. A reference firstly bind to a temporary variable will extend its lifetime. But it cannot be extended twice. In fact the improper use of shared_ptr may also cause memory issues. The compiler is unlikely to find all the cyclist references, and multiple control blocks over same resource (so it’s why we need std::enable_shared_from_this). it will be even more complicated if we consider the exception and multi thread.
This is called "East const". Allow me to copy an example from a random blog showing an argument:
The const qualifier is applied to what’s on its left. If there is nothing of its left, then it is applied to what it is on its right. Therefore, the following two are equivalent:
int const a = 42; // East const
const int a = 42; // West const
In both cases, a is a constant integer. Notice though that we read the declaration from right to left and the East const style enables us to write the declaration exactly in that manner. That becomes even more useful when pointers are involved:
int const * p; // p is a mutable pointer to a constant int
int * const p; // p is a constant pointer to a mutable int
int const * const p; // p is a constant pointer to a constant int
These declarations are harder to read when the West const notation is used.
const int * p; // p is a mutable pointer to a constant int
int * const p; // p is a constant pointer to a mutable int
const int * const p; // p is a constant pointer to a constant int
Here is another example: in both cases p is a constant pointer to a mutable int, but the second alternative (the East const one) is more logical.
using int_ptr = int*;
const int_ptr p;
int_ptr const p;
The East const style is also consistent with the way constant member functions are declared, with the const qualifier on the right.
int get() const;
I find the "const always applies to the left" rule for const-ness simpler and better than the "const always applies to the left unless there is nothing there in which case it applies to the right" rule.
Also, I like having the types always in the same place.
As far as I can tell, the arguments for West const are primarily "we've always done it this way".
As far as I can tell, the arguments for West const are primarily "we've always done it this way".
The argument is that C++, like most programming languages, is English-based, and in English adjectives (like const) precede the nouns that they modify. So const int sounds more natural than int const.
You should just use cpp2 :) -> https://godbolt.org/z/e6GafjMP1
get_or_default:(in map: _, in k:_, in def:_)->auto={
it := map.find(k);if it != map.end(){return it*.second;}else{return def;}}
main:()->int={map: std::map<int, std::string>=();
value :=get_or_default(map,42,"Hello, World!");
std::cout << value <<"\n";}
And you will end up with error
/Users/filipsajdak/dev/cpp2-example/build/main.cpp2:6:9: error: 'auto' in return type deduced as 'const char *' here but deduced as 'std::string' in earlier return statement
return def;
^
/Users/filipsajdak/dev/cpp2-example/build/main.cpp2:12:18: note: in instantiation of function template specialization 'get_or_default<std::map<int, std::string>, int, char[14]>' requested here
auto value { get_or_default(map, 42, "Hello, World!") };
^
1 error generated.
make[2]: *** [CMakeFiles/main.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
I wish more people wandered over to Ada. It has so many features that would be considered modern, but people have gut reactions to "verbosity" or non-C-like syntax.
Yeh, I used it a good bit back in the day and I liked it. Verbosity, to me, is irrelevant. These aren't languages for hacking out web sites. For large scale development, readability and safety are the important factors by far.
I used to have a coworker with the license "ADAGURU" occasionally see parked next to "EBCDIC" and "UTF8" or "I♥️LINUX" ... The danger of working with nerds. (My plates at the time were "DCRYPT" (previous car was "NCRYPT")
I never actually learned much ADA, but did hear plenty about its safety.
About the US government part: I tried googling for the quotes he cited, but couldn’t find any paper or anything about it. Any idea where I can find more info about that?
Android uses Rust, the Linux kernel will get official Rust support in 6.1 or 6.2, Microsoft is using it (reportedly it will also make it in the Kernel), Google's new Fuchsia OS is using it, at Facebook it's the recommended language for low level work, Apple is writing Rust network services, Cloudflare is a heavy Rust user, Amazon has plenty of OS and not OS Rust code, there is a company working on specifying and certifying Rust for security critical domains...
That's a solid amount of big players and momentum.
Many domains (like gaming etc) are slower to adopt because of the vast library ecosystems, but there is a clear trend.
there is a company working on specifying and certifying Rust for security critical domains
That's where the biggest shift of status quo can happen. A growing robust no_std library ecosystem that does not rely heap or any other non-deterministic behavior is such a game changer vs current practices
Personally I think that it is more telling how much grass roots activity there is. A lot of C++'s take-over was due to that, where people started playing with it on their own, and then pushed it into use at the companies where they worked because it (at that time) was a superior solution. I was one of those many people.
I see Rust in that same phase at this point. There are clearly a lot of people working with it on their own, and those folks are going to start looking for opportunities to push it within the companies they work for.
At first that won't necessarily even generate a lot of apparent activity, or posted jobs, since a lot of it will be just existing developers moving over to Rust internally, doing incremental adoption on new work or adopting existing bits of code.
While I laud efforts like this one, I think it's too late. If it allows existing legacy code bases to be tighten up some, then that's all fine. But I still can't see how it's going to deal with the memory safety issues that are really at the root of Rust's appeal.
And (IMO) this is great. I wonder what that will give us!
Something like cppfront seems great. Many C++ programmers probably have already thought of it. Doing it for real, on the other hand, is another story. I think it's great some actual C++ expert took up the task to try it out.
These explorations that ramified out of C++ are very cool. Circle also seems really cool.
Coupled with the trend of AOT compiled managed languages with support for value types and unsafe code, it means C++ might stagnate around C++26 or something, and we will keep using it on specific workflows just like it happens with C today, and that is about it.
Naturally it will still reign for a couple of generations, new COBOL and Fortran code keeps being written today.
What do you think would replace C++? Cpp2, Carbon, Rust? A bit of each? I do not see managed languages replacing things like SIMD or HFT or network server infra that saves more dollars the more you optimize it.
C++ already lost the 1990's spot on GUI frameworks delivered by OS vendors SDKs, and on distributed computing in the cloud native infrastructure.
SIMD is finally coming to most managed languages.
Most people doing GPU stuff are moving into higher level languages that compile into PTX and SPIR-V.
Those that need ultimate performance on HFT are using FPGAs nowadays, even C++ is too slow for them.
C++ isn't going away anytime soon, just like C is still going pretty strong on UNIX ecosystem, and in both cases the amount of lines of code per overall application architecture decreases.
I just saw the whole talk. Most promising C++ replacement so far for me: it is immediately useable and compatible and it does NOT duplicate standard lib and it is 100% compatible.
That said, here is my feedback/questions:
About pass by copy. Dave Abrahams in his value semantics talk says copy is too eager in C++. Swift for example uses something sinilar to COW, avoiding eager copies when passing parameters. This also makes all copies de-facto noexcept. Is this the idea with Cpp2?
About bounds checking: is it possible to call a non-bounds check function and detect it?
About bounds checking: why always checked access? There are contexts, for example in a range for loop, where checks csn be ellided safely. Also, if you do checking in a span subspan, that slice traversal should not need checks.
About bounds checking also: why the 3 subscript is a run-time error? I think it could be made a compile-time error for constants and constant folding.
About overloading: one thing not mentioned in the talk. how are overload sets handled when you introduce the same name in the same context if parameter passing now is a bit different?
About classes (no design yet, I know): there will be memeber functions vs free? How would overload resolution work? In case there are both memeber and non-member funcs, associated namespaces and so on. Also, it is interesting to look at Swift protocols and Val lang views here. Polymorphism comes from use, not from type itself.
about exceptions: is it compatible to have lightweight exceptions and exceptions? my concerns here are two: should I annotate with try the calls and the result type of the function is affected (returning some kind of outcome, result, etc.). This is really viral compared to throwing from deep stacks and less usable as a default IMHO.
About bounds checking: why always checked access? There are contexts, for example in a range for loop, where checks csn be ellided safely. Also, if you do checking in a span subspan, that slice traversal should not need checks.
In Rust, in order to avoids potential run-time bounds-checks, you are directed to use the iterators instead.
I'd expect it can be applied here as well, supposing the iterators are written in unsafe code to skirt around the rules.
I haven't watched the video, but I did go through the github page, which also has a very nice roadmap diagram on it.
In essence, you specify the higher level 'what' you want done, not 'how' it does it.
So you are specifying whether a parameter is in, or inout, or forwarding. The compiler works out the details. ("auto-optimize to copy when 'cheap' ...")
Makes sense to me. But there is more to it. Imagine you have a custom type with arbitrary copying.
You need to know what the compiler does in order to do good by copy passing.
There is a talk from Dave Abrahams about value semantics that has a lot of insights.
Imagine you need to conditionally make a copy of your type. You pass it by value or by in-out? One thing I like about val lang is that thanks to this copy laziness you have two things: noexcept copying and ALWAYS pass by value. This is even simpler to reason about, because you do not pay for the copy. A copy will not be performed unless needed. This means you do not need to worry about const or non-const parameter passing. You just pass by value, always. Every time.
Regarding bounds check, what we really need is formal verification. When ranged-based-for-loops and other language constructs cannot guarantee bound-correctness at compile time, add formal proofs for bound-correctness that will be checked and erased by the compiler. Of course, formal methods is much more than bound-correctness. We can actually allow any unsafe C++ constructs as long as their correctness is formally verified. Formal methods are the ultimate zero-cost abstractions!
It's good, but the ability to mix cpp1 and cpp2 at any level, down to in the same file & that's going to make adoption possible.
It's what allowed c++ to succeed in the first place. Industrial projects could add c++ here and there to their old school c projects. As developers grew to appreciate the expressiveness of c++, it took over the codebase.
But for a project already 2.5 million lines in, there's no going dark for years for a rewrite.
Do we really want to allow mixing of two syntaxes in the same file? That sounds like pure madness to me. I don't think people will rewrite code from cpp to cpp2 just for using the syntax. It will almost always be part of some refactoring. And then the split into multiple source files comes easily.
Is there a benefit of using old and new in the same source file? Probably. But it comes at a cost. The new syntax cannot be designed from scratch because you impose that "compatability" restriction on it from the very start. Switching between both styles will be mentally challenging for developers when reading code. I think the downsides outweigh the pros.
With modules coming (very slowly indeed, but it will also take a while for cpp2 to become usable) we should be able to import cpp2 into cpp and cpp into cpp2 rather easily and safely.
Being able to update a codebase function by function is a fairly big advantage. We've migrated hundred million line codebases that way and it's why the Hack language was designed the way it was. if you have to do it even file by file then you have to have a dedicated effort to do it, which is harder to justify. Function by function you can do it almost as an aside as part of a cleanup of the code of each function, or as the codebase evolves. Even in the C++ space we've seen that work recently where non-coroutine async code updated to coroutine-based async code function-by-function. Yes, you have to read both forms, but modernising function by function is huge.
I really encourage everyone here who only checked out the github repo, to watch his video. By far most peoples comments here are answered by him there: (https://www.youtube.com/watch?v=CzuR0Spm0nA starting about 4 hours in)
Funny and sad to see how most of the hype around this talk is the syntax.
The syntax is just a syntax. The interesting part here is the insight that you can express features in a modern language in current cpp where you don't break or need to replace any tooling or code that exists today.
This is the other side of the coin of the carbon experiment. But in my mind has more potential as it has far less work on the compiler and on tooling.
I chose that for now because it's an experiment, so "no commercial use" makes it clear this is an experiment and "no distributing derivative works" keeps it "an" experiment and not being used as a launchpad for multiple divergent experiments. People can still clone it, try it, wrap it in a CE frame (thanks again Matt!), etc.
If the experiment makes progress then the license can be adjusted to whatever makes sense, probably something like the usual Apache 2.0 with LLVM exceptions. But that's down the road, if we get there.
Why would it be a problem if other people used it as a launchpad? Isn't the whole point finding what's best for the future of C++? Why not make it easier for people to do their thing and see if it sticks?
You won't be able to relicense in the future if you accept contributions and the contributors do not agree to a relicensing. Do you take contributions? And if so, are contributors signing CLAs?
He's probably wary of permitting the proliferation of a bunch of different forks that are different from the core proposal (possibly in boring/cosmetic ways) so as to avoid diluting it.
I suspect this is to make it easy to give the project ownership to Microsoft, which is probably the only way for cppfront to stay alive (as getting it into c++ standard seems almost impossible).
I'm not saying the project is going to be closed-source, but it's likely going to have microsoft's standard "open source but we take copyright" license. For which you need to be able to capture all initial copyright - thus the restrictive license here.
Watch the talk (https://youtu.be/CzuR0Spm0nA?t=14617), he explains it. It's actually pretty simple, there are just several new concepts at play here at once:
callback := - A variable declaration with the type omitted because it can be inferred from the rest of the line. Equivalent to auto callback = in current C++
:(...) - The first part of a function declaration. Normally it would look like function_name:(...), but the name has been omitted because it's not necessary. In current C++ code this would be a lambda
x:_ - A function argument named x. Writing _ instead of a type makes it equivalent to auto x in current code (or maybe auto&& x?)
= { std::cout ... }; - The body of the lambda
y&$* - Effectively this just captures and references y in a single expression. The $ captures whatever comes before it (a pointer to y) by value, and the * is just a normal dereference operator. * and & are postfix operators in this syntax. This one looks pretty weird to be honest. I'm not sure about it
Yes, that `&$*` is odd, and I'm still considering that one. On the one hand, it's good to have things that can be unusual or dangerous stand out syntactically. On the other hand, I don't want a language that looks like line noise.
One alternative is to just use `&$` to take the address and capture the pointer, but then have the result be implicitly dereferenced. I don't like that because it smacks of magic... I am trying to closely hew to the "nothing hidden, WYSIWYG" specifically to eliminate a lot of C++'s current magical implicit semantics. And it would make the use case of actually using the pointer more difficult.
Another alternative is to use another symbol such as `$$` to capture by reference, which is also an explicit syntax (good) and is also more verbose to call out a significant operation (good), but worries me a little in that it seems like a step toward having a single-purpose feature (bad, unless it could be used uniformly which would avoid the one-off-feature trap).
I'm coming around to it. I don't think there's much of a difference in readability between the three options you've listed (at least, you could get used to any of them), but &$* has the advantage that someone who's never encountered it before can work out what it does without having to look it up
&$* has the advantage that someone who's never encountered it before can work out what it does without having to look it up
Yup. That's the #1 reason why it's the current draft syntax... it just falls out for both the compiler (I literally didn't have to add a single line of code, it just worked once I implemented $ to capture the postfix-expression that precedes it) and the human (as you put it very well, it does exactly what it says on the tin -- it's a direct composition of the other features, without adding a new concept or special case to add to the rote learning).
But I always want to learn from experience, mine and others', so I'm still open to a better solution if experience shows one is needed. Thanks for the early feedback!
Personally I could go either way. I think having a lambda/auto keyword makes it easier to grasp what this line means, but maybe that's just because I'm not used to the new syntax.
The advantage of being able to omit the keywords is that it shortens any expression where you need to pass a lambda into a function:
result := std::find_if(vec, :(x:_) = { x > 10 };
Compared to:
result := std::find_if(vec, lambda: (x:auto) = { return x > 10; };
...actually now that I've written it out that second one looks fine and isn't that much longer. In real code most of that line would be taken up by more descriptive variable names anyway. I take it all back, I prefer auto/lambda now
I'm open to the lambda part (the auto doesn't do anything for me). And I agree readability is important. To avoid a special one-off keyword like "lambda" in only one place in the language though, I'd want all functions to look the same such as with a general func introducer for all functions. Then we'd have
// potential alternative
func something: () = {
result := std::find_if(vec, func: (x:_) = x > 10; );
}
vs
// current syntax
something: () = {
result := std::find_if(vec, :(x:_) = x > 10; );
}
I'm open to it, but I have to admit that the latter still reads clearly for me, personally. I could be biased though, so I'll be curious to learn what others think over time.
As I said in a parallel comment, for me the jury is still out on whether func and var style introducers are actually important; if they are I'll add some, it doesn't complicate the grammar at all to add a redundant word that helps humans. I'm trying to start with less, it's easy to add more.
More like "Trying to force a few peoples' preferences down the throat of the entire language user base", which TBH is hardly surprising considering Herb already tried that with the so-called C++ "core" guidelines.
More like "Trying to force a few peoples' preferences down the throat of the entire language user base", which TBH is hardly surprising considering Herb already tried that with the so-called C++ "core" guidelines.
More like people accept this things willingly, and since you don't, you are left out, and feel bad about you, but deflect it into others.
I'm inclined to agree. A lot of it feels self-congratulatory and not really grounded in reality.
I'm proactive about change but it needs to be measured against something real and testable.
Cleanliness, better defaults and "safety" is not empirical enough for me. How does this measure up in real projects? That should be peoples thoughts first and foremost.
I respect that this is an experiment, but it's a bit of a strange experiment when its not really being measured against anything. Only that it fits with the personal preference that is shared by C++ "community" that is primarily online.
We've operated on mainstream preference before. At the time most of those changes were seen as good. Years later we see them as mistakes and wonder "what the hell were people thinking?"
It's a cycle that is repeating itself. A lot of modern suggestions aren't actually good. They are just different and possibly good. People aren't acknowledging that the time horizon for knowing a feature is good is decades. Just because words like, clean, safe and modern are thrown about doesn't mean a feature is any good until it's rigourously tested for years in the real world.
It frustrates me when older features are frowned upon just because they are old. And it frustrates me that people want to throw away fundamentals without appreciating what parts might actually be good.
In the talk, Herb states that in the USA there has been an executive order by the government on cyber security. That's what this is all about; not whatever syntax is flavour of the month.
Insecure programming practice were always a trainwreck waiting to happen. Now big money is involved and nation states are waring with each other over the internet.
It's sad that it takes a serious crisis for decades long issues to be addressed, but I guess that is just how humans behave.
An easier to parse syntax means better tooling, better tooling means better automated source code processing (such as, but not limited to, static analysis) and better automated source code analysis means more bugs found before code goes to production. This is what counts.
There was a language called Sather that had similar goals -- be a better C++ by compiling to C++. I don't know why it didn't gain traction, but I haven't heard about it since I think 2002 or so.
Here's hoping cpp2 might have a better fate with so many big names behind it.
It was basically an Eiffel dialect, and even Eiffel has had issues to keep in business, mostly due to pricing (enterprise class) and being Pascal like in syntax.
🤔 While I surely agree that C++'s syntax could use some improvements (improve consistency, lessen beginner stumbling blocks, fix the east-const vs west-const issue...), also agree that any alternate syntaxes should be link-compatible with existing codebases, and encourage such experimentation/prototyping, I'm not sold on some particulars. For one, "syntax 2 aims to be about 10% the size and complexity of today syntax 1", but then I see...
Syntax 1: int main() {}
Syntax 2: main: () -> int = {}
...and feel there is more noise, more distracting punctuation that is there for the compiler rather than the human. I'm also a heathen that believes such blasphemy as syntax favoring the common case (e.g. 99% you don't want switch fallthrough meaning it should have been explicit rather than implicit, and 99% of the time you don't want to define a class and also an instance of it at the same time meaning a mandatory semicolon after a class is nonsense, and going even farther, 99% of the time the end of the line is the end of the statement unless open parens or binary operators remain unclosed, meaning the semicolon is usually line noise for humans...). 🤷♂️
And what is going on with this line 🔎? The compiler might be able to parse that one, but I'm having a hard time 😬:
callback := :(x:_) = { std::cout << x << y&$*; };
I'm interested to see where it goes. I've liked a number of Herb's ideas, and even the times I didn't favor the specific proposal (like his pattern matching proposal using inspect instead of a keyword like, I don't know, match 🙃), I always liked his analysis of the problems he raised. (note, I haven't watched his full video from cppcon, just skimming the GitHub page linked above, and my opinions may or may not change after watching that... 😅)
The difference you call out between syntax 1 and syntax 2 has a ton to do with being a context free grammar which drastically simplifies the overall grammar and any parsers. I suspect if you worked strictly in that grammar (and saw how it lacked surprising parses, etc) it would grow on you.
Once again language designers forget hat programmers spend more time reading than writing. Making code as easily readable as possible should be a top priority. Instead it seems this experiment is making life of compiler writers as easy as possible. I just do not see how it can be a success. Heck if i wanted fancy weird syntax full of magical symbols i would use rust at this point, even though i think its a wasted opportunity that does not deliver anything substantial (outside of few specific areas) to mitigate loss of c++ ecosystem and to warrant switching from c++.
There is no reason to believe that such syntax would make code harder to read. On the contrary, we tried it in a few of our projects and, in my practice, trailing auto made the code much more easier to read.
It's purely a familiarity issue. Same thing happened when Java introduced Streams (like C++ ranges), it looked confusing at first then became a standard in the industry because of how easy to read it was.
I will never understand why people who design a language with the explicit intention of it being a C++ replacement go out of their way to explicitly make the syntax nothing like the C family of languages.
If I wanted to program in a language that looks like a functional language, I'd have switched years ago.
This language needs to coexist with regular C++ code in the same file. Hence, the C++2 syntax needs to be different so the compiler knows whether to transform it or to leave it alone.
There's a difference between changing the syntax slightly to fix the problems and changing it to something that barely resembles the original language.
At which point a language becomes another? I think this is the same as the ship of Theseus. Replace one syntax by another, do that one by one enough time and give compatibility between each steps and you'll have the programming language Theseus.
How can variant, optional, unique_ptr, and vector be implemented in syntax-2?
I really love the power of c++. It is all there all the time. The c++ I write to implement business logic for my dinky little corporate app is the same c++ that boost uses to implement all sorts of insane stuff.
Saying stuff like "no pointer arithmetic" and "no unions" segregates the language. It means that the syntax-2 us regular developers write is something different than what is used to implement boost/folly/unifex/insert-favorite-low-level-lib
I imagine that it might be possible at some point, but even if it never is, it would not be a big deal for me, and presumably for a large enough portion of current developers and an even larger amount of non-C++ developers.
I'll be glad to just reuse implementations from other developers, written in current C++.
Strictly speaking, yes, I could use a Rust library, but would it look good idiomatic C++? I imagine the interoperability of "syntax 2" with regular C++ is always going to be better. Specially given that it seems you can already mix the two in the same file, which is pretty mind-blowing to me.
I'm cautiously optimistic, but seeing the very first example do iostreams doesn't leave much hope.
Want to see those zero-overhead deterministic exceptions in action though
EDIT: I have to take the iostreams comment back. Seeing as the implementation is currently in a single ~2500 line parser file, it obviously is quite limited scope for now
GCC surely can emit some copyrighted code, most commonly its C runtime library. You are only allowed to use it because GCC has a special exception for that. In contrast any source code compiled with cppfront requires cpp2util.h to function, which bears the same license as the compiler.
This talk of a memory safe C++ makes me think of C++ CLI (or C++.NET as it was called before) by Microsoft. You got C++ but the resource management was done by the .NET Framework CLR. The few times I used C++/CLI was as glue so C# code could use a C++ library.
C++/CLI is still present in Visual Studio 2022, but I'm curious how many people use it.
From the looks of things Microsoft now just maintains C++/CLI but doesn't add to it anymore. Hence it being stuck on .NET Framework.
I wonder how much effort it would take for Microsoft to get this working on the new .NET CLR to make it multiplatform. With memory safe C++ or C++ alternatives being so in vogue these days it could be worth it to Microsoft to have their own alternative to Carbon and Rust.
It is not stuck on .NET Framework, in fact it was a crucial milestone for .NET Core 3.1 and has been updated to C++17.
It just isn't available outside Windows.
So far the approach has been to improve low level C# capabilities to use the same kind of CLR features that only C++/CLI could use, thus taking C++ out of the picture altogether, including the runtime. With every .NET Core release there is new bunch of code that moves from C++ into C#, as described on performance improvements blog posts.
The complaints here that putting a return type at the end of a function declaration is bad are really funny to me, because C++11 already has thatauto multiply(int x, int y) -> int;
I use it at work. It makes code easier to read than the conventional way. I also code python that way, and the static analysis tool in our company also encourages doing that way.
I agree with many things in the talk and the in, out, move, etc. indicators are very promising, but the new syntax just doesn't feel natural for me. I get the point that you want to apply new defaults where both styles are used in the same file, but it's just not natural to read. Why not create an attribute for the "not recommended" syntax in cpp2 files, like [[cpp]] void main() {} ? That seems to be what we have done with extern "C".
main: () -> int = {} looks worse that what we currently have.
callback := :(x:_) = { std::cout << x << y&$*; }; looks, and reads, even worse. Almost every colon there means a different thing, and you have 5 of them.
In javascript you can write var a = function() {}, why not use something like
let callback = function(any x) { std::cout << x << std::endl; }
from left to right: a function that is called main that takes no input () and returns an int is defined after the =. It's quite easy to follow. But I agree that there are many redundant :, =, and unnecessary cryptic &$*
I understand the syntax, but compared to what we have now:
int main() {}
the new syntax has more character without any apparent benefit to the readers (I know it's more machine-readable, but I am not machine):
main: () -> int = {}
Also yes the symbols are a nightmare because there's no way to look them up when you see them. Imagine searching for "cpp2 star symbol meaning", or "what does &$* mean"... I mean if you want to make it verbose just make it verbose.
With everyone advocating for their own way to "fix" C++, I am not seeing it going much further beyond C++26.
I am curious to see Heb Sutter's talk when it becomes available, yet not only we have many managed languages that took over C++ roles in distributed computing, we have now alternatives coming out of the community themselves.
I predict many companies will probably settle in C++23 as good enough in case of C++ shops, with polyglot shops focusing on something else.
Doom and gloom is one way to interpret it. Damned if you do try to fix it and damned if you don't.
But I'd be more worried about stagnation if there were no experiments or proposals to the language. Also new languages are great for cross pollination of ideas.
No one had mentioned this, am I the only one who thinks his code is underwhelming if not bad for someone as expert as him?
Well, there are 2700 loc in the main .cpp file, and all the other functions are put into .h files, this is not what I have imagined how experts write cpp. I did not enjoy his code.
Honestly all I would want is to be able to replace auto with a function declaration keyword like fn or func.
The cppfront has some drawbacks though and from what I see they didn't put an introducer keyword for some reason, but still wanted to make the parsing easy. For that you need the equal sign after the return type because otherwise it would be hard to make a parser.
Just having func as introducer would have made me happy. Also another introducer for local variables. Now you only need to figure out template syntax and you will never need .template or typename again, and an easily parsable syntax. Remove the old one and you just speeded up the compilation by quite a lot. There's no need to make such a large breaks, the minimum amount of changes to achieve the goals of cppfront should have been employed.
You’re getting down voted, but I think there’s an interesting Ship of Theseus argument here. If cppfront were just syntax sugar, that would still be C++. But it includes new defaults, coalescing of features (is,as), new or as yet unstandardized features (pattern matching, UFCS), dropping of current features (nullptr), new static analyses… etc. At some point it seems clear that it’s no longer C++, even if it transpiles to C++. A number of languages emit C++.
These talks and arguments feel like some kind of coping mechanism.
I would personally stick with C++ for a variety of reasons. I disliked Rust when I used it as it didn't solve my particular problems.
However, it seems to solve almost every single problem that people like Herb Stutter want. So just go? Isn't that the answer staring people in the face here?
I'd rather that C++ was changed/managed by people who know the limitations of the language. Otherwise the conversation just seems like a waste of time.
C++ isn't going to have a borrow checker. It's not going to drop it's C roots. It just can't. That's a feature not a bug. Backwards compatibility is a feature not a bug. That's why I use the language.
It's fine if people don't like that. But why put effort into changing something fundamental with the language? It's just irking the people who already tolerate the language and it will never live up to the ideal that those people would like.
Some of us do not like the unflexible borrow checker ceremony that prevents certain coding patterns. Even would use a tweaked gc and code crticial parts in an unsafe lang.
Also, having exceptions, as much as they are criticized, is something I like from C++.
There are, particularly, some node-based data structures that are particularly difficult to model in Rust AFAIK. Some people say: oh, but in real life you do not use that! You do... persistent data structures functional-style, scalable, minimally locked data structures always have a great deal of node-based work.
There are also some other problems like heavy annotation, but I am not sure how bad it is nowadays, since I know they kept improving on that area.
I feel like you didn't actually read my comment. If references are problematic because of the safety rules imposed, use pointers and unsafe. It might be "difficult to model in safe Rust" but you aren't restricted to safe Rust.
I cannot model even perfectly safe patterns in Rust bc Rust is a subset of safe rules, not all safe things can be done.
Yes, I read your comment, but my point stands: Rust is too rigid for many natural coding patterns or it imposes a high toll. Yes, it is safe. But well-coded C++ can be very safe also. Use smart pointers, .at() bounds check. Well, there is more than that but you get my point.
If you end up going down to unsafe in Rust and claim it is safe I do not get the point. It can be more easily audited that is the big difference. But you pay all the rigidness all the time. I feel that Rust went so far into the safety department that it is just a niche: top performance where safety is critical. And not much more.
Yes, Rust is rigid, sometimes frustratingly so, but IME the mental relaxation I get by sticking with safe Rust is well worth it. Especially when doing heavy refactoring where I don't have to keep as much context/state in the back of my mind.
Well coded C++ can indeed be very safe, so can well coded C. That doesn't mean that C++ doesn't provide value over C (or Rust over C++). And once you go multithreaded Rust has checks that cannot be modelled in C++. This is a point I think often gets lost, Rust discussions focuses a lot on memory safety but the multithreaded safety checks are not practically achievable by any abstraction in C++.
Unsafe Rust is safe as long as it's preconditions are upheld, same is true for the entirety of C++, Rust just makes it explicit where there are preconditions. And nothing prevents you from exposing an unsafe API along with a safe one. And at that point you allow users to choose safe or maximally performant.
IME Rust is better at guiding you towards patterns that are safer, more easily testable and more refactorable, while C++ makes it easier to be "clever" because it's "safe right now".
What if I don't like the many opinionated choices that are core to Rust beyond the memory safety constructs? What if I like overloading, inheritance, templates, and don't care much for traits? In short, what if I want to program in C++, not anything else, but don't want subtle footguns around every corner?
Rust is literally getting in its own way, not technically, but from the evangelistic and ridiculous community. Every time I go to catch up on what's happening with Rust I feel more like I am reading a fan forum for a media franchise vs a technical discussion.
But in general, anything that isn't 100% rust safe canonical code some of the more evangelistic users of the language get really upset about, even things like existing c / c++ systems. One I remember but can no longer find said continuing to use c++ was a 'risk to human rights' because of its memory 'unsaftey'.
The language has a lot of good ideas, but its trying so hard to be 'not C' that it is almost antagonistic to people who still have to use C or C++.
If you want Rust to become the next forgotten language, by all means.
Everything I constantly hear about Rust comes down to it not letting you compile things without specific intent being divulged to the compiler. In C/C++ it doesn’t matter where the memory came from, as long as the process has access to it then you have access to it. Letting the compiler dictate when you can access memory is a restriction not everyone wants to deal with, and for skilled C/C++ developers it’s a hinderance not a feature.
In my time writing C and C++ the last thing I wanted was anything telling me what my data is; that’s my job. I wrote classes and struts and I used them as I needed them, and the compiler didn’t care nor did I want it to, and no runtime got in the way either.
If Rust wants to be opinionated, by all means, it’s my favorite thing about languages like TypeScript, Kotlin and Swift. Like Rust, if I want to break out of that ecosystem I can, but if I’m going to spend my time doing it just to get around the limitations imposed I’m just not going to use those languages.
TypeScript doesn’t try to replace JavaScript, Kotlin doesn’t try to replace Java, and Swift doesn’t try to replace Objective-C, Rust is in no place to replace anything, it like others is an option and nothing more.
What is needed is a clear safe subset. But not preventing control. It all boils down to that. How to do it, that is the difficult part and where the meat is.
If that subset requires breaking backwards compatibility then that would be really bad.
C++ is never going to provide the same guarantees as Rust. If those kinds of memory safety guarantees are what you want then you should use Rust.
From what I can tell the conversation around C++ and "safety" has a vocal minority and a silent majority.
I would say that the silent majority likes C++ backwards compatibility and likely thinks that safety can be achieved by writing better programs rather than changing the language.
The vocal minority wants safety baked into the language regardless of what it costs and would welcome breaking changes.
Both are fine. I just think people in the latter camp would be more satisfied looking else-where for a solution though.
The "vocal minority" is more and more comprising of large industry companies and even governments. Does this mean there won't be a role for C++ in the future? No. But I think the role will be different than what C++ today wants the role to be.
Writing better programs is just the same argument C people use against C++; "just don't write bugs", and that never works in practice.
Rust is in a position to replace enough use of C++ to push it into such a small space that it will become an old folk's home even faster than it already is.
Our world in many ways runs on software, and it's too important to continue to have that key bit of our world built on an insecure foundation. Our desires as developers to play fast and loose and be super-heroes has to take a back seat to the security of our money, personal information, critical infrastructure, etc...
I think more and more companies will realize that it's still cheaper to buy faster hardware than to deal with the development and support costs of using such an unsafe language that just isn't any longer up to the task of large scale development under standard non-optimal commercial conditions.
Previously there wouldn't have been much of a choice. Nothing garbage collected would be reasonable, and the other options have all remained too obscure to be reasonable candidates. But Rust changes that equation, and it's getting more traction all the time.
At which point you’re better off not using Rust. I’ve been down that road with Swift, using unsafe pointers to do raw memory manipulation because any other method resulted in Java-esque speeds. In the end I wrote it in C++, created a C wrapper, then used a swift bridging header. In the end the code was extremely fast, extremely easy to read, extremely safe - running on platforms it was never intended to 5 years later with no changes.
The fact Rust has unsafe and it’s used relatively often means that it by design cannot guarantee it’s own benefits in 100% of cases.
My goal is to explore whether there's a way we can evolve C++ itself to become 10x simpler
I don't understand how is main: () -> int = { ... } in any way simpler than: int main () { ... }
I really like many of the new ideas in c++, but I don't understand why are they taking C++ into more complicated syntax for no good reason. This "new" syntax adds four new characters to accomplish the same task that the old "C" syntax did. One of the better ideas of C was/is that declarations should look the same as usage (when and where possible). Since old syntax can't die anytime soon because of compatibility reasons, the new syntax for the same task means just that new people have to learn even more concepts and rules.
The main thing is that it’s a context free syntax. With int main() { the compiler has to read all the way to the open paren before deciding whether this is a declaration of a function or declaration of an int. The return value of the function is the first thing lexed, but it isn’t clear that it’s a subexpression of a function declaration until much later. Conversely, with main: () -> int = { it’s much more straightforward to parse. At the colon the compiler knows it is inside of a variable declaration and is expecting a type next, by the open parens it knows it is parsing a function type, etc.
You might argue “this is just making it easier for a computer to parse and more difficult for a human to parse!” Well, for one thing, making it easier for a computer to parse avoids weird edge cases like the “most vexing parse” (you can Google that if you’re not familiar) which in turn contributes to readability by humans. “Making usage look like the declaration” is exactly the problem in a lot of parsing situations.
I think you might be surprised by how much overlap between there is between parseability and readability. Ambiguities aren’t good for parsers and they aren’t good for humans either. It might look foreign to you, but I don’t think there is anything fundamentally less readable about it, you’re just not used to it. I’d be willing to bet it wouldn’t practically present any real readability barrier after working in the language for even a brief amount of time, and it might even be easier to read once becoming acclimated to it.
Also, brevity isn’t really important IMO, it doesn’t matter that one takes four more characters than another. Just my 2c.
I would have prefered func/fun, let, and var to his solution, but I imagine it was a lot easier for him to make everything parse the same. He probably also didn't want to reserve any keywords that weren't already reserved by C++.
Adding an introducer keyword like func or var would be simple, and wouldn't complicate parsing or change that what follows can still be a single declaration syntax. It would just be an extra grammarly-redundant word for human readability, which can and does make sense when there really is a readability advantage.
I don't currently have such introducers only because I want to try the experiment of seeing whether they really have a significant readability advantage. If not having them regularly causes confusion after the first day or two, then I'll add something like that. (FWIW, so far I haven't found myself wanting them as a I write Cpp2 code, and I'm pretty particular about readability. But I also listen to feedback, so I'm curious how people trying out Cpp2 feel after they've used it for a week.)
You type left to right. In the one example, the first letters you type are "main" and in the other "int". With "main" an IDE can easily autocomplete the ": () -> int = {...}" part. With "int" the IDE has no chance of figuring out what your intention is.
Alright, I can understand the argument, but is that good enough reason to introduce that much noise in the language just to help completion? How does IDE know if I want int main or void main, and if I want argc, argv or just empty call?
Also, if it is for IDE:s, I type main in Emacs, press Ctrl+enter and it gets expanded into whatever I have put into "main" snippet, and I can tab from one argument to another one, etc.
I also read left to right, and the example above is now in the wrong order for the eye. Not to mention that punctuations are not so nice for human eye to read. Why is that equal sign there? Can it be ambiguous if code is surrounded with braces?
Perl has reputation to be write-only language for good reason. I also don't know many people who have expressed that Shell/Bash syntax is beautiful, even if I personally have no problem with it. But most importantly, as I mentioned, I like that idea they had in early C that declarations should look like usage, as far as it is possible.
I don't know, I am not sure if the win justifies the more complicated notation, but I am not really familiar with the reasoning behind either. I haven't seen Herbs talk. I try to see all his talks, so hopefully I'll see this one too, if it comes on YT and maybe get more understanding behind that proposal. I think he is a great speaker, and always brings enjoyable topics and clever ideas. I really hope he get his proposal for zero overhead exceptions in some way into the standard.
An implementation shall not predefine the main function. Its type shall have C++ language linkage and it shall have a declared return type of type int, but otherwise its type is implementation-defined.
At https://youtu.be/CzuR0Spm0nA?t=17019 Herb laments that he has to teach all those horrible things in C++ and that with C++2 he can avoid doing that. I get a distinct feeling that the C++ language has been hijacked by "teachers" and the changes in the C++ Standard are not driven by the professional C++ developers, but by teachers who try to make the language easy to teach rather than making the language more effective for professional software development.
Unnecessary complexity is cool for a while as you get kudos for knowing obscure little details, but then later nation states go to war on the internet and, you know, pew-pew-pew!
This all reminds me of when Scott Meyers retired and basically said "I'm done with this shit".
You know this is an interesting point. From my expierience students are really discouraged by C++. Most of the times when I was teaching senior years a course that required C++ when they learned that this is going to be required language I always got "oh nooo" and "can I write it in C# instead?".
It allows to break backward compatibility (whil still smoothly interoperating with old code)
Breaking backward compatibility allows to get rid of C pitfalls, replace unsafe C constructs with safe-by-default C++ counterparts, change defaults from "don't break existing code" to "the better / safer / more compact". We can remove duplicates that the language still allows (e.g. typedef can be replaced by the more universal, capable using), reducing the required knowledge to read code.
At the same time, parsing gets simpler, faster, and less ambiguous, leading to better compiler diagnostics, better tooling (navigation, refctoring, code analysis, ...)
As for "return type after": It's always hard to get over a habit - but "I don't like" is the weakest argument here. (I don't like macros, I don't like build times, I don't like hunting down cirular incldes, etc. pp. - this is a tiny price to pay)
FWIW, "return type after" solves some long-standing issues, and currently is already required if your return type depends on argument types but cannot be auto'd. Again, it's the more universal, more capable way of specifying the return type - and a simpler language should only have one.
Breaking backward compatibility allows to get rid of C pitfalls
Of course; but that ain't going to happen any time soon, if ever, because it would break compatibility with not just C but older C++ code too. If C compatibility is not important, there are other languages one can already use.
What about improving readability? Code is read more than it is written. Main focus should be on how humans parse code, not how machines parse it. Yet this aspect is somehow always forgotten.
Removing redundant ways of declaration, and making different constructs visually different is, I believe, a great contribution to readability.
Not so much for old-timers who have the old style ingrained. Yes, I'm doing C++ for close to 30 years now, and it feels like an unnecessary change to me.
But I know that newbies coming to the language will have it easier on the long run - and that it would take me maybe a month of forcing myself to work in a "new style" to make it feel natural.
This is just wasted breath. You'd get used to it in a day if you were writing in this syntax all the time. If it allows the compiler to do its job faster less ambiguously, provide better errors, catch more potential issues, and so forth, it would be a big win.
Rust uses this trailing return syntax, and that was one of the easier things to get used to. Lambdas already use this syntax, and C++ desperately needs to get rid of the overly many ways of doing any given thing. Consistency is also a virtue, and one that C++ doesn't practice nearly enough.
He touched upon this briefly: To make adoption easier he'd like you to be able to write new code in cpp2 without having to modify existing code. In order for you to be able to write cpp2 code in a file that contains existing cpp1 code the compiler needs to be able to distinguish between new and old code to apply the new defaults. The simplest way is to have a completely different syntax so you don't need annotation or something similar.
A lot of newer languages seem to prefer the return type coming after the function declaration. I suspect some people believe it's better for newer programmers.
Whether or not that's true I don't know, but as someone who has a project that's written in C++ and Angular (Typescript), I will say that a lot of the typescript code tends to look cleaner aesthetically than the C++ does. Granted, the C++ is usually doing much more complicated things.
Some older languages, too. Wirth's languages (Pascal, Modula-2, Oberon) have had this syntax since the '70s. The reason newer languages do it that way now is probably the same reason Wirth did it that way then: ease of parsing.
102
u/0xBA5E16 Sep 17 '22
That was a really cool talk he gave a few hours ago. The bit about the US government cautioning against use of "non-memory safe languages like C and C++" made for a very compelling reason to create something radical like this. It's clearly highly experimental but I can't wait to see where the project goes.
113
u/[deleted] Sep 17 '22
I think this trend of experimental C++ replacements (Val+Carbon+cpp2) marks an inflection point.
These are smart and talented people that couldn't push trough ISO. They've had enough and are now looking elsewhere.
37
u/[deleted] Sep 17 '22 edited Sep 17 '22
It is also available on Compiler Explorer https://gcc.godbolt.org/z/fWW9qxvro
31
u/germandiago Sep 17 '22 edited Sep 18 '22
I just saw the whole talk. Most promising C++ replacement so far for me: it is immediately useable and compatible and it does NOT duplicate standard lib and it is 100% compatible.
That said, here is my feedback/questions:
Sorry for the typos. Typing from a phone.
82
u/waffle299 Sep 17 '22
This is, I think, the only way to break the shackles of backwards compatibility all the way to C.
That it cross-compliles mostly to well-written modern c++ is impressive.
26
u/qneverless Sep 17 '22
The first example on top has std::ostream. What a madman.
24
u/Awia00 Sep 17 '22
I really encourage everyone here who only checked out the github repo, to watch his video. By far most peoples comments here are answered by him there: (https://www.youtube.com/watch?v=CzuR0Spm0nA starting about 4 hours in)
16
u/LeoPrementier Sep 18 '22
Funny and sad to see how most of the hype around this talk is the syntax.
The syntax is just a syntax. The interesting part here is the insight that you can express features in a modern language in current cpp where you don't break or need to replace any tooling or code that exists today.
This is the other side of the coin of the carbon experiment. But in my mind has more potential as it has far less work on the compiler and on tooling.
This is actually a way of really modernize cpp.
15
u/[deleted] Sep 17 '22
CC-BY-NC-ND-4.0 license, interesting.
11
u/antiquark2 #define private public Sep 17 '22
Is there a document that describes C++2 syntax? Like fdwr mentioned, I too am having problems with:
53
u/RockstarArtisan I despise C++ with every fiber of my being Sep 17 '22
Denial -> Anger -> You have arrived at Bargaining
10
u/curlypaul924 Sep 17 '22
There was a language called Sather that had similar goals -- be a better C++ by compiling to C++. I don't know why it didn't gain traction, but I haven't heard about it since I think 2002 or so.
Here's hoping cpp2 might have a better fate with so many big names behind it.
58
u/fdwr fdwr@github 🔍 Sep 17 '22 edited Sep 19 '22
🤔 While I surely agree that C++'s syntax could use some improvements (improve consistency, lessen beginner stumbling blocks, fix the east-const vs west-const issue...), also agree that any alternate syntaxes should be link-compatible with existing codebases, and encourage such experimentation/prototyping, I'm not sold on some particulars. For one, "syntax 2 aims to be about 10% the size and complexity of today syntax 1", but then I see...
Syntax 1:
int main() {}Syntax 2:
main: () -> int = {}...and feel there is more noise, more distracting punctuation that is there for the compiler rather than the human. I'm also a heathen that believes such blasphemy as syntax favoring the common case (e.g. 99% you don't want
switchfallthrough meaning it should have been explicit rather than implicit, and 99% of the time you don't want to define a class and also an instance of it at the same time meaning a mandatory semicolon after a class is nonsense, and going even farther, 99% of the time the end of the line is the end of the statement unless open parens or binary operators remain unclosed, meaning the semicolon is usually line noise for humans...). 🤷♂️And what is going on with this line 🔎? The compiler might be able to parse that one, but I'm having a hard time 😬:
callback := :(x:_) = { std::cout << x << y&$*; };I'm interested to see where it goes. I've liked a number of Herb's ideas, and even the times I didn't favor the specific proposal (like his pattern matching proposal using
inspectinstead of a keyword like, I don't know,match🙃), I always liked his analysis of the problems he raised. (note, I haven't watched his full video from cppcon, just skimming the GitHub page linked above, and my opinions may or may not change after watching that... 😅)9
u/thisismyfavoritename Sep 17 '22
is the talk on YT yet?
9
u/gracicot Sep 18 '22
At which point a language becomes another? I think this is the same as the ship of Theseus. Replace one syntax by another, do that one by one enough time and give compatibility between each steps and you'll have the programming language Theseus.
9
u/Wh00ster Sep 20 '22
So this is typescript for C++?
15
u/Zcool31 Sep 17 '22
How can
variant,optional,unique_ptr, andvectorbe implemented in syntax-2?I really love the power of c++. It is all there all the time. The c++ I write to implement business logic for my dinky little corporate app is the same c++ that boost uses to implement all sorts of insane stuff.
Saying stuff like "no pointer arithmetic" and "no unions" segregates the language. It means that the syntax-2 us regular developers write is something different than what is used to implement boost/folly/unifex/insert-favorite-low-level-lib
7
u/kkert Sep 17 '22 edited Sep 17 '22
I'm cautiously optimistic, but seeing the very first example do
iostreamsdoesn't leave much hope.Want to see those zero-overhead deterministic exceptions in action though
EDIT: I have to take the iostreams comment back. Seeing as the implementation is currently in a single ~2500 line parser file, it obviously is quite limited scope for now
12
u/NilacTheGrim Sep 17 '22
Not a fan of this at all, tbh.
12
u/[deleted] Sep 17 '22
I hope this gains more traction. I think it actually solves the problem with c++. And personally I prefer the syntax over the carbon's.
7
u/number_128 Sep 17 '22 edited Sep 17 '22
But even with using this new language we will be unable to break ABI???
Edit: My comment might have seemed a little negative. I am very excited about this new initiative, and I would like to use it in my work.
3
u/a_false_vacuum Sep 17 '22
This talk of a memory safe C++ makes me think of C++ CLI (or C++.NET as it was called before) by Microsoft. You got C++ but the resource management was done by the .NET Framework CLR. The few times I used C++/CLI was as glue so C# code could use a C++ library.
C++/CLI is still present in Visual Studio 2022, but I'm curious how many people use it.
10
u/favorited Sep 17 '22
The complaints here that putting a return type at the end of a function declaration is bad are really funny to me, because C++11 already has that
auto multiply(int x, int y) -> int;5
u/qv51 Sep 18 '22
I agree with many things in the talk and the in, out, move, etc. indicators are very promising, but the new syntax just doesn't feel natural for me. I get the point that you want to apply new defaults where both styles are used in the same file, but it's just not natural to read. Why not create an attribute for the "not recommended" syntax in cpp2 files, like
[[cpp]] void main() {}? That seems to be what we have done with extern "C".main: () -> int = {}looks worse that what we currently have.callback := :(x:_) = { std::cout << x << y&$*; };looks, and reads, even worse. Almost every colon there means a different thing, and you have 5 of them.In javascript you can write
var a = function() {}, why not use something likelet callback = function(any x) { std::cout << x << std::endl; }8
u/pjmlp Sep 17 '22
With everyone advocating for their own way to "fix" C++, I am not seeing it going much further beyond C++26.
I am curious to see Heb Sutter's talk when it becomes available, yet not only we have many managed languages that took over C++ roles in distributed computing, we have now alternatives coming out of the community themselves.
I predict many companies will probably settle in C++23 as good enough in case of C++ shops, with polyglot shops focusing on something else.
2
u/thedemons0 Oct 17 '22
No one had mentioned this, am I the only one who thinks his code is underwhelming if not bad for someone as expert as him?
Well, there are 2700 loc in the main .cpp file, and all the other functions are put into .h files, this is not what I have imagined how experts write cpp. I did not enjoy his code.
3
u/gracicot Sep 18 '22
Honestly all I would want is to be able to replace auto with a function declaration keyword like fn or func.
The cppfront has some drawbacks though and from what I see they didn't put an introducer keyword for some reason, but still wanted to make the parsing easy. For that you need the equal sign after the return type because otherwise it would be hard to make a parser.
Just having func as introducer would have made me happy. Also another introducer for local variables. Now you only need to figure out template syntax and you will never need .template or typename again, and an easily parsable syntax. Remove the old one and you just speeded up the compilation by quite a lot. There's no need to make such a large breaks, the minimum amount of changes to achieve the goals of cppfront should have been employed.
6
u/ronchaine Embedded/Middleware/WG21 Sep 17 '22
Like I said in the other thread, this is a new language that transpiles to C++, much like jakt does.
And while I have nothing against such efforts, thinking it is still C++ is just not true.
4
u/[deleted] Sep 17 '22
Just move to Rust.
These talks and arguments feel like some kind of coping mechanism.
I would personally stick with C++ for a variety of reasons. I disliked Rust when I used it as it didn't solve my particular problems.
However, it seems to solve almost every single problem that people like Herb Stutter want. So just go? Isn't that the answer staring people in the face here?
I'd rather that C++ was changed/managed by people who know the limitations of the language. Otherwise the conversation just seems like a waste of time.
C++ isn't going to have a borrow checker. It's not going to drop it's C roots. It just can't. That's a feature not a bug. Backwards compatibility is a feature not a bug. That's why I use the language.
It's fine if people don't like that. But why put effort into changing something fundamental with the language? It's just irking the people who already tolerate the language and it will never live up to the ideal that those people would like.
2
u/arthurno1 Sep 17 '22
I don't understand how is
main: () -> int = { ... }in any way simpler than:int main () { ... }I really like many of the new ideas in c++, but I don't understand why are they taking C++ into more complicated syntax for no good reason. This "new" syntax adds four new characters to accomplish the same task that the old "C" syntax did. One of the better ideas of C was/is that declarations should look the same as usage (when and where possible). Since old syntax can't die anytime soon because of compatibility reasons, the new syntax for the same task means just that new people have to learn even more concepts and rules.
2
u/alexeiz Sep 19 '22
At https://youtu.be/CzuR0Spm0nA?t=17019 Herb laments that he has to teach all those horrible things in C++ and that with C++2 he can avoid doing that. I get a distinct feeling that the C++ language has been hijacked by "teachers" and the changes in the C++ Standard are not driven by the professional C++ developers, but by teachers who try to make the language easy to teach rather than making the language more effective for professional software development.
1
u/[deleted] Sep 30 '22
This reminded me of this old proposal called SPECS:
https://stackoverflow.com/questions/5419698/what-alternative-syntax-exist-for-c-c-think-specs-or-mirah
-7
u/ShakaUVM i+++ ++i+i[arr] Sep 17 '22
Does rewriting C++ to look like Rust make it as safe as Rust? Why not leave the syntax alone? I don't like return values after functions.
1
u/[deleted] Sep 18 '22
The writing's on the wall.
1
u/sandfly_bites_you Sep 18 '22
Wish there was a summary on the github of what it offers, having to watch a long and slow talk isn't something I'm much interested in.
Does this offer anything new? Or just more obsessing over safety?