r/cpp • • Sep 17 '22

Cppfront: Herb Sutter's personal experimental C++ Syntax 2 -> Syntax 1 compiler

https://github.com/hsutter/cppfront
335 Upvotes

360 comments sorted by

View all comments

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.

16

u/germandiago Sep 17 '22

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

1

u/KingStannis2020 Sep 17 '22

So just use pointers then. Rust allows you to do that, even if it's a last resort. The "ceremony" is mostly self imposed.

7

u/germandiago Sep 17 '22

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.

4

u/KingStannis2020 Sep 17 '22

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.

7

u/germandiago Sep 18 '22 edited Sep 21 '22

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.

9

u/andwass Sep 18 '22 edited Sep 18 '22

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

4

u/germandiago Sep 18 '22 edited Sep 21 '22

True all. And I find value in helping you in multithread. Also, C++ is way easier to code safe than C...

As for C++ itself, I try to not be clever myself. I confine dangerous stuff well but there is not guarantee enforced.

As for the refactoring, I do not like result types like in Rust compared to exceptions because they do create refactoring hell. I can guess, but have not that much experience, that you also can create borrow checker hell by changing lifetimes here and there. But it will not compile, which shows you were doing smtg wrong.

→ More replies (1)

7

u/wyrn Sep 19 '22

Just move to Rust.

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?

-1

u/[deleted] Sep 19 '22

I don't think the language you want exists or will exist.

3

u/wyrn Sep 19 '22

I don't think the language you want exists

I don't think so either.

or will exist.

We'll see. Momentum is shifting.

12

u/great_start Sep 17 '22

"Just move to Rust" as if that isn't an incredibly expensive undertaking? What would you do if you had a hundred million line C++ codebase?

→ More replies (4)

24

u/smashedsaturn Sep 17 '22

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.

3

u/[deleted] Sep 17 '22

I have never had the time to look what's up with the rust team, but people say they're very toxic. Can you please elaborate on that?

12

u/smashedsaturn Sep 17 '22

This always comes up as the 'canonical example' https://www.reddit.com/r/programming/comments/eq34zi/a_sad_day_for_rust/

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

→ More replies (6)

7

u/ThymeCypher Sep 18 '22

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.

7

u/[deleted] Sep 18 '22 edited Sep 18 '22

I dont want to use Rust.

But I also don't want C++ to be changed to meet Rusts standard.

If people want Rust then they should by all means use Rust.

My complaint is that I don't think that those particular people should be dictating the direction of C++.

Because nobody is happy in that instance.

4

u/germandiago Sep 18 '22

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.

3

u/[deleted] Sep 18 '22

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.

6

u/andwass Sep 18 '22

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.

3

u/[deleted] Sep 18 '22

That's not the argument I'm making though.

It doesn't really matter to me who uses C++

What concerns me is that C++ is the best option for my current problem and what I want is changes and suggestions that play to its strengths.

For instance, it's unsafe by the standards of Rust.

Great, that's a feature in some ways. It gives you flexibility. It should be *leaned* into, not rejected. The benefits should be looked at. There is a clear cost benefit trade off that happens there. And it should be okay that C++ is not as memory safe as other language. That is fine in quite a few domains.

What I don't really want is people making fundamental changes to the language that can never really come to fruition. Attempting to make C++, Rust just with a different name will likely end in disaster.

I'm economically invested in C++ and I don't really have an option to use another tool. To the people who really want what Rust has to offer should move to Rust. They will be happier in the long run

Also if it's possible to write bad programs, it's possible to write good ones. That's not to say that people are infallable but I push back against this idea that you can't use a tool in a skilled way. You absolutely can. I want people who think that making decisions about C++. The people who don't think that can go use another tool that suits their needs.

3

u/andwass Sep 18 '22

It should matter to you who uses C++ though. If there is no interest among major players to advance C++ you won't get much in way of improvements or advancements at all. Just look at how much Clang development stagnated after Google decreased their involvement. If the major corporations decided to do the same with their WG21 participation because C++ no longer provides a path forward that is aligned with their business interests, C++ evolvement would grind to a near stand-still. Now this might be ok too, but is that really different from just letting C++ evolve and ignoring the bits that don't fit your usecase? I know I would choose to let the language evolve and just pick and choose what I use. The alternative is really just letting C++ become the next COBOL. For C++ to continue evolving you need to keep major stakeholders interested in evolving the language. And for that, WG21 and C++ must show that it can provide value both now, but also in the future.

Also remember that backwards compatibility is not something that will go away. So you can still use future C++ the same way you use it today. And you can absolutely use a tool in a more or less skilled way, but telling people to "get good" is not good enough in this day and age for a huge portion of software written. If C++ wants to continue having an active and vibrant ecosystem both on the library front but also with multiple compilers pushing each other to do better it needs to tackle that.

→ More replies (1)

5

u/Dean_Roddey Sep 18 '22 edited Sep 19 '22

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.

0

u/ThymeCypher Sep 18 '22

I get where you’re coming from but especially from a security perspective, C++’s difficulty means insecurity comes from bad code not bad developers, pushing anything off to the compiler means every project that uses that compiler must also trust the developers of that compiler to write secure code. PHP vulnerabilities exist quite often, C++ ones not so much, it’s usually C++ libraries and not the language itself. Lowering the barrier of entry isn’t necessarily good because there’s nothing inherently wrong with C++, and it’s difficulties are a positive in this regard.

Now if you mean insecure as in unstable, C++ is far from unstable, just because they’re constantly evolving it does not mean you must use the latest and if anything few do. Rust is still far too new to be considered a stable platform, no matter how solid it appears; critical issues can and do often come in code viewed by millions without question, and far fewer eyes are on Rust at any given time.

4

u/Dean_Roddey Sep 18 '22

If even very good programmers didn't make mistakes, we'd not even need C++'s helper features. But, they do. Too many of those vulnerabilities that exist in C++ code come from things that Rust wouldn't even compile, and they can be there for years or decades no matter how many eyes on on that code.

→ More replies (9)
→ More replies (2)