News for hackers. Stuff that matters.
Re:Modern C++ Won't Save Us by jclay on Monday April 22, 2019 @08:47PM (#19724603)
I really don't get all the hate that C++ gets. The suggested alternatives in the article are Rust and Swift. What if you need to develop a cross platform GUI, that has a backend running a CUDA or OpenCL algorithm? For the former, you can use Qt, which isn't without it's warts, but is pretty tried and true in my experience (see KDE, VTK, etc). For the latter, you'll end up writing your CUDA code in C++ anyways. I guess you could go the route of writing bindings, but that is not without additional effort. Not that it won't happen for Rust, but C++ also has tooling suited for enterprise use that are largely unmatched in other languages (Visual Studio, Qt, etc). Sandboxing, static analysis, and fuzzing tools are also mostly built for C/C++ codebases. It's also an ISO standard language which makes it both a language full of warts due to decision by committee, but also a candidate for a stable, long-lasting language that will outlive many of us. (Try finding an ISO Standard Language you don't hate).

Either way, C++ is certainly not for every project, but the articles scattered around the web claiming it should be superseded by Rust are plentiful. These opinion pieces make no attempt to credit C++ for when it does make sense to use. Despite it's quirks, it is still the most optimal way to program HPC applications or cross platform GUIs that are not Electron based. The security tools around it and the fact that it's an ISO standard language make it a solid choice for many enterprises.

Re:Modern C++ Won't Save Us by mannykannot on Monday April 22, 2019 @09:01PM (#19724686)
I do not think it helps to think in emotional terms such as 'hate'. There is nothing wrong with discussing potential problems, and the current utility of the language should not stop us asking whether we could do better in future.

FWIW, I use C++, not Rust or Swift, and I have a fair amount of knowledge and experience vested in it, but I think these questions are worth asking.

Re:Modern C++ Won't Save Us by Rexxar on Monday April 22, 2019 @09:50PM (#19724959)
> I do not think it helps to think in emotional terms such as 'hate'

I think 'hate' really represent the mind of some people (even if they are a minority) but even if we ignore this extreme, the level of irrationality in technical discussions is generally quite high. You need to have rational people to have a rational discussion. The sad reality is that a lot of technical discussions are only superficially rational and are often a political play to assert superiority on other people (it's true for languages, frameworks, code editors, methodologies, etc ... ).

Re:Modern C++ Won't Save Us by blub on Tuesday April 23, 2019 @02:21AM (#19726074)
The questions are worth asking. But the Rust crowd is not asking questions, they're dictating solutions, or rather that one old solution of rewriting everything to Rust.

Meanwhile the Firefox rewrite, the premium example of what they propose is still plodding along and Mozilla PR blogs aside, Firefox is still plugging vulnerabilities in each release and will be for the foreseeable future.

Now let's look at the Swift community... do we have blog posts from them every week about how awesome Swift is and why one should rewrite their working C and C++ code in Swift? No, they keep doing their thing, Swift is becoming better at cross platform, it's also getting some support for machine learning.

That's how one grows a language, through building successful projects, staying positive (and having an entire platform behind it). Not through doomsday scenarios and a constant barrage of criticism.

Re:Modern C++ Won't Save Us by 0815test on Tuesday April 23, 2019 @05:26AM (#19726831)
> That's how one grows a language, through building successful projects, staying positive (and having an entire platform behind it). Not through doomsday scenarios and a constant barrage of criticism.

This is exactly what the Rust community is doing! RIIR is something that's only really insisted on for relatively small pieces of security-critical code. With huge codebases like Firefox the rewrite is done piecemeal, to put the rewritten code in use as quickly as possible. The "doomsday scenario" talk about memory-unsafe languages does not come from people writing Rust, it mostly comes from the security community, even at places like Microsoft - because guess what, they've literally been running around with their hair on fire for decades, and they're sick of this especially now that something like Rust is available!

Re:Modern C++ Won't Save Us by dejaime on Wednesday April 24, 2019 @01:59PM (#19741111)
Saying that C++ won't "save" us is already pretty emotional and, put simply, wrong. We are not really facing imminent doom or anything that would justify that word, other than an overemotional point of view, biased by personal feelings.
Re:Modern C++ Won't Save Us by badsectoracula on Monday April 22, 2019 @09:28PM (#19724846)
C++ does have its positives, as you mentioned, but those positives do not make its negatives go away, nor having negatives means that there aren't positives. You can dislike some parts of the language while still using it for its positive aspect - that doesn't mean the negative parts do not exist nor mentioning them means that there are no positives.
Re:Modern C++ Won't Save Us by blub on Tuesday April 23, 2019 @02:24AM (#19726085)
Once again, this is not merely mentioning negatives, it's just more submarine advertising for Rust.
Re:Modern C++ Won't Save Us by int_19h on Tuesday April 23, 2019 @03:17PM (#19731894)
Rust is the only serious attempt to fix those negatives while remaining in the same niche, so bringing it up in this context is natural.

And C++ can't really truly fix them without breaking backwards compatibility with all the legacy C++ and C code, which is its main selling point.

Re:Modern C++ Won't Save Us by blub on Tuesday April 23, 2019 @04:35PM (#19732558)
It's the only "serious" attempt as declared by whom exactly, the committee of serious attempts?

There are other serious attempts (D, Swift, Go) which the Rust community likes to dismiss for various reasons, but at least two of them are currently much more successful than Rust. They don't have to be 100% in the same niche to take a bite of marketshare.

Even if C++ breaks backwards compatibility in some ways, it will still have better backwards compatibility to itself and C than Rust or any other language. This break could be something as radical as a C++ "unsafe", or it could be clang's -Wlifetimes, or something else. Credit's due to Rust here for pushing some parts of the C++ community to search for solutions.

Re:Modern C++ Won't Save Us by int_19h on Tuesday April 23, 2019 @07:17PM (#19733974)
I do not dispute that the languages that you've listed are serious attempts. They do not remain in the same niche, however. I would define that niche as "capable of replacing C even in free-standing implementation".

For D and Go, having a GC immediately puts them outside of that niche. For Go, I would also add all the FFI weirdness due to its weird stack discipline, which means that it is non-zero-overhead when interacting with non-Go code - a fatal omission for any contender for a low-level systems language.

Swift is much closer to the metal, and I would consider it a serious contender if it was pushed on all platforms. But it seems that Apple is not interested in its use outside of their ecosystem, which constrains its effective niche to be much narrower than C++ or Rust, ironically.

And yes, of course C++ is always going to have better backwards compatibility. If it didn't, it wouldn't be C++. But its ability to fix issues is directly correlated with that compatibility - it's a dial where you can have more of one and less of the other, as you choose, but you can't have both. Rust (and Swift) can fix more problems, or can fix problems in better ways, because they are not so constrained.

Conversely, if C++ were to introduce safe-by-default, and require explicit opt-in into unsafe - with all present code being considered unsafe - then what you have is a new language that just happens to embed C++ for compatibility reasons. At that point you might as well fix the syntax warts etc as well in that new safe language, since it breaks everything anyway.

Re:Modern C++ Won't Save Us by magila on Monday April 22, 2019 @10:13PM (#19725048)
While there are obviously still cases where C++ makes sense to use today, those case are overwhelmingly based on the age and maturity of the C++ ecosystem. Now that Rust has proven that a language can provide memory safety without compromising (much) on performance, it is clear that the scope of C++'s supremacy is in permanent decline.

As Rust (or another language with similar safety/performance properties) matures and its ecosystem grows, C++ will increasingly become a language of tiny niches and legacy codebases.

In other words: C++ is the new Fortran.

Re:Modern C++ Won't Save Us by ajross on Monday April 22, 2019 @10:23PM (#19725078)
> In other words: C++ is the new Fortran.

Which makes Rust the new... APL?

I think the analogy is pretty apt as far as it goes. Fortran by the 70's was a crufty language with a bunch of legacy mistakes that remained very popular and very useful and would continue to see active use for decades to come.

And everyone knew that. And everyone had their own idea about the great new language that was "clearly" going to replace Fortran. And pretty much everyone was wrong. The language that did (C) was one no one saw coming and frankly one that didn't even try to fix a lot of the stuff that everyone was sure was broken.

For myself, I despair that Rust has already jumped the proverbial shark. It's complexity is just too severe, the only people who really love Rust are the people writing Rust libraries and toolchains, and not the workaday hackers who are needed to turn it into a truly successful platform.

Re:Modern C++ Won't Save Us by arcticbull on Monday April 22, 2019 @10:33PM (#19725118)
It’s definitely easier to reason about than C++ because it errs on the side of safety and explicitness. You can use things you don’t understand without fear which straddles the boundary in a good way IMO. To your point that doesn’t make it simple.

As a work-a-day hacker it’s completely become my go to language when I’m writing tools, libraries or just want to knock out a simple algorithm to prove myself right or wrong.

Re:Modern C++ Won't Save Us by ajross on Monday April 22, 2019 @10:40PM (#19725148)
> It’s definitely easier to reason about than C++

See... I don't think that's true, and argue the huge body of C++ code and talent in the ecosystem is an existence proof to the contrary.

I mean, sure, C++ has its crazy edge cases and its odd notions. But you don't need to understand the vagaries of undefined behavior, or the RVO, or move semantics to write and deploy perfectly sensible code. Literally hundreds of thousands of people are doing this every day.

Now, that may not be a convincing argument about the value of that code. But it's absolutely an argument about the utility of the language in aggregate.

I'll be frank: probably 40% of professional C++ programmers aren't going to be able to pick up Rust and be productive in it, at all. And at the end of the day a language for The Elite isn't really going to mean much. We've had plenty of those. Rust is the new APL, like I said.

Re:Modern C++ Won't Save Us by arcticbull on Monday April 22, 2019 @11:18PM (#19725296)
I'm not really arguing about the value of that code either, just that it's probably wrong, probably trivially breakable due to the sheer mountain of complexity underlying it. The compiler just happened to let it through because it can't help you. The language doesn't give it enough information to do so effectively.

Just off the top of my head, std::move doesn't... move [1]. It just returns an, I kid you not "static_cast<typename remove_reference<T>::type&&>(t)" without doing... anything. You can keep on using the old value probably, silently, until out of the blue, it stops working one day. Then you're super, duper sad. Even modern language features are, I don't want to say lies, but "hopes and dreams" the compiler can't enforce. It's like if you really wished C++ had Rust's features, but you can't without breaking things, so you give it your best shot, which ends up just creating yet more complexity.

Rust's answer is...

  let x = Value::new();
  let y = x;
  let z = x; (COMPILER ERROR: X GOT MOVED INTO Y)
C++'s modern features are to Rust's equivalents what the ruined fresco [2] was to the original. If you stand far enough back, it's basically right. If you get up close it's hilariously and trivially broken.

It takes a lot of gymnastics to call this language approachable or understandable. It's basically a coal powered car made of foot-guns. That doesn't mean it's not a car, or that it won't get you where you're trying to go, I'm just saying it's an open question how many pieces you'll arrive in.

[1] http://yacoder.guru/blog/2015/03/14/cpp-curiosities-std-move...

[2] https://www.npr.org/sections/thetwo-way/2012/09/20/161466361...

Re:Modern C++ Won't Save Us by masklinn on Tuesday April 23, 2019 @02:14AM (#19726031)
> Just off the top of my head, std::move doesn't... move [1].

I mean that makes sense in a (somewhat nonsensical) way, std::move is a marker for "you can move this thing if you want".

The much weirder part is that even if a value is moved it's not moved, it's carved out, you get to keep a shell value in a "valid but unspecified state". Reusing that value (which the compiler won't prevent) may or may not be UB depending on the exact nature of the operation and state.

Oh and of course that a change / override to the caller and recompile can change the behaviour of the callsite entirely (e.g. a previously moved value is not moved anymore, or the other way around) but that's pretty common for C++.

Re:Modern C++ Won't Save Us by estebank on Monday April 22, 2019 @10:52PM (#19725195)
I'm curious, what has given you the impression that Rust is a language "for the elite"? It certainly has some rough edges around learnability, but I don't think anyone is actively trying to discourage people from picking it up. Rust is certainly hard for experienced programmers because some common patterns in other languages are not allowed by Rust's rules, but that's no different than trying to apply OOP in a functional language.
Re:Modern C++ Won't Save Us by leshow on Monday April 22, 2019 @11:32PM (#19725366)
> But you don't need to understand the vagaries of undefined behavior, or the RVO, or move semantics to write and deploy perfectly sensible code.

Don't you kind of have to though? These invariants are in your code no matter what, in the case of Rust they are checked by the compiler (you don't necessarily have to understand every nuance, because it's checked for you), in C++ they aren't checked and are a potential bomb waiting to go off.

Re:Modern C++ Won't Save Us by lpghatguy on Monday April 22, 2019 @11:30PM (#19725358)
Claiming that Rust is a language for 'The Elite' is amusing in light of the recent Rust website redesign, with the following headline[1]:

> Empowering everyone to build reliable and efficient software.

The language is entirely about inclusion, empowerment, and removing the fear of systems development.

[1]: https://www.rust-lang.org/

Re:Modern C++ Won't Save Us by arcticbull on Monday April 22, 2019 @11:33PM (#19725368)
Perception always lags reality, and it definitely was hard to learn when I picked it up 3-4 years ago. Things have improved so much since then, with non-lexical lifetimes in R2018, better compiler errors, stdlib standardization, RLS + VSCode, etc.
Re:Modern C++ Won't Save Us by 4thaccount on Monday April 22, 2019 @11:38PM (#19725394)
"Rust is the new APL,like I said"

I know you're trying to compare it to APL as that language mostly died off and is thus obscure, but I think the analogy is a little off.

While APL is weird, it is actually really easy for me (someone with less than 15 hours playing with the language in total over the past few years) to code up some basic scripts a lot easier than something like C++.

I'm being absolutely serious too. C++ is pretty low level and as a Python coder I feel like I'm sinking in quicksand with everything required to do something simple. APL is basically built around passing arrays of numbers or strings to weird symbols that operate on the whole array. This means I can do text processing with only a few symbols and a library function (and all interactively) where C++ requires lots of boilerplate and debuggers and compilation and pointers. In short, APL seems to be a lot less complicated than both Rust and C++ in my opinion and most using it have very little formal programming experience and have no problem picking it up from what I've read.

I know what you were essentially trying to say though.

Re:Modern C++ Won't Save Us by ajross on Tuesday April 23, 2019 @02:56PM (#19731667)
I picked APL because it matches the "WTF cray cray" aesthetic that Rust's syntax presents to new users. I can see an argument that Ada is the right analogy if you're going for pure complexity.

And yes, Fortran, APL, Ada (also Modula-2 & Oberon, Smalltalk and a bunch of other forgotten languages presented as the Next Big Thing at the time) are all uniformly simpler than either C++ or Rust. The modern world is a more complicated place and programming tools have kept up.

Re:Modern C++ Won't Save Us by Inityx on Monday April 22, 2019 @10:59PM (#19725237)
> the huge body of C++ code and talent in the ecosystem is an existence proof to the contrary

Looks to me more like proof that C++ has been around a long time

Re:Modern C++ Won't Save Us by ncmncm on Tuesday April 23, 2019 @12:56AM (#19725707)
Lots of languages have been around a long time without attracting billions of lines of code. To get that, the language must be unusually useful.
Re:Modern C++ Won't Save Us by dragonwriter on Tuesday April 23, 2019 @04:11AM (#19726523)
That's a powerful endorsement of COBOL, but a lot of language success is “when did it become common”, “who was sponsoring it or what libraries did it come bundled with”, and path dependence that makes momentarily (due to transient conditions) sensible choices into standards that are mandatory for decades.
Re:Modern C++ Won't Save Us by int_19h on Tuesday April 23, 2019 @03:20PM (#19731927)
I don't think anybody is denying that C++ was (and is) unusually useful, simply by virtue of being the only serious game in town when you need that whole "don't pay for what you don't use" thing, and general performance stemming from that. And devising a better replacement that retains that feature is hard, which is why C++ had so much time to entrench.

But it doesn't mean that we can't do it better these days.

Re:Modern C++ Won't Save Us by dragonwriter on Tuesday April 23, 2019 @04:07AM (#19726505)
> I'll be frank: probably 40% of professional C++ programmers aren't going to be able to pick up Rust and be productive in it, at all.

Well, a certain number of professional programmers are past the point of being willing to learn new technologies, so maybe that's true. But close to 100% of the people who might become professional C++ programmers could instead become professional Rust programmers.

Re:Modern C++ Won't Save Us by nunjee on Tuesday April 23, 2019 @05:36AM (#19726880)
happy workaday Rust hacker here. Coming from higher level languages, the semantics make much more sense to me, after a quite harsh learning curve and some un-learning. Non lexical lifetimes is a game changer for rust learnability I think, and I more and more fail to see usecases where I can't just use it.
Re:Modern C++ Won't Save Us by ncmncm on Tuesday April 23, 2019 @01:01AM (#19725726)
If C++ is the new Fortran, Rust might very well be the new Ada. Many of the same relative merits were claimed for Ada as for Rust, and it had the backing of the biggest and best-funded organization in the world, but it faded from view because it did not keep up.

Rust could easily go the same way.

Re:Modern C++ Won't Save Us by pjmlp on Tuesday April 23, 2019 @02:13AM (#19726027)
Given the market size for Fortran and Ada, that doesn't bound well for Rust.
Re:Modern C++ Won't Save Us by 932 on Monday April 22, 2019 @09:01PM (#19724688)
Yeah, agreed. The points in the article are valid, but quirks you learn and get past the first time. I still shoot myself in the foot sometimes even though I don't have a single bare new/malloc without a shared/unique ptr! But that's C++ for you.

But, C/C++ is the best option for us for high-performance network processing. We're dabbling with Rust for small applications where we would use Python previously and it's working pretty well -- but there's no way we could use Rust for the core application yet. Modern C++ has really grown on me and it's sometimes a love/hate relationship but totally a huge improvement over ancient C++ or C.

Re:Modern C++ Won't Save Us by mrbrowning on Monday April 22, 2019 @09:29PM (#19724851)
> The points in the article are valid, but quirks you learn and get past the first time. I still shoot myself in the foot sometimes even though I don't have a single bare new/malloc without a shared/unique ptr! But that's C++ for you.

I think the article maybe doesn't do enough to outline the full extent of the problem by focussing on a few counterintuitive cases that are present in C++17, because you're right, all of those cases in the article are ones that can be learned and remembered without issue. The real problem, as I see it, is actually that the core language semantics mean that there's no foreseeable end to the foot-shooting treadmill. Since the language is fundamentally permissive of such things, it's likely that further spec revisions will introduce abstractions like string_view that are easy to use unsafely, aren't flagged by static analysis tools, and end up in security-critical code.

Because this feels like a necessary disclaimer, I don't think that fact justifies migrating every active C++ codebase out there to Rust or anything, since pragmatically speaking there are a lot more factors beyond just core language semantics that go into evaluating the best choice of implementation language. I guess my takeaway is neatly expressed by the post title: there's a sense that I get from C++ users (granted, maybe only naive ones) that sticking to the features and abstractions introduced in C++11/14/17/etc basically eliminates all of the potholes of old, and it's evident that that's not true and will probably continue to be not true.

Re:Modern C++ Won't Save Us by sanderjd on Monday April 22, 2019 @09:13PM (#19724757)
> but there's no way we could use Rust for the core application yet

I'd love to hear more information on this! In my mental model, you could just use Go to replace your Python utilities, but Rust might be workable for your core (or at least its designers would like it to be and would like to know why it isn't).

Re:Modern C++ Won't Save Us by 932 on Monday April 22, 2019 @09:55PM (#19724982)
We are Rust noobs :-). The Python utilities are random tools and daemons, so it's been a nice experience getting my feet wet in a completely different paradigm with rustc.

So the biggest challenge with moving to another language is reproducing the same low latency and high performance we've carefully designed in C++ to a Rust analogue... which given we haven't really used Rust enough yet to have a total sense of this, is hard.

In the long future, I can see Rust working in gradual stages -- but of course focusing on biz objectives is better first when we know how to write high perf C++, hence spending time to play with Rust on side tooling or other smaller projects.

From what little Rust I've written so far I really do like it, so hoping that I can incorporate it more

Re:Modern C++ Won't Save Us by bobajeff on Monday April 22, 2019 @09:44PM (#19724933)
>Not that it won't happen for Rust, but C++ also has tooling suited for enterprise use that are largely unmatched in other languages

Hopefully that stuff will be helped with things like Language Server Protocol and Debug Adapter Protocol.

Re:Modern C++ Won't Save Us by _bxg1 on Monday April 22, 2019 @11:08PM (#19725262)
But most of the things you just listed are just aspects of the existing ecosystem (libraries, tooling, etc.). There's no doubt C++ has an incredibly large ecosystem and will therefore be around for quite a while to come, but that doesn't make it a good language, it just makes it one that happens to have been very popular for a very long time. Our industry is one that values progress over tradition in the long run. I think C++ has entered its twilight years. That could mean five, ten, or twenty, but I think it's peaked, and I don't think that's a bad thing.
Re:Modern C++ Won't Save Us by jclay on Tuesday April 23, 2019 @01:01AM (#19725723)
The point is that I've noticed a broad "religious" trend where those promoting Rust don't lend any credit to the places where C/C++ has valid strengths, even if due to it's legacy. It doesn't do a great service to either community to constantly pit the two against each other, and to misrepresent the other in a way that's not honest. C++ doesn't exist and continue to evolve just because it's been around forever, there are a number of things leading to it's continued use that should be brought into the discussions.

C++ isn't going anywhere. In 20 years you may not be writing in it, but you'll still be calling into it somewhere in the software stack (especially if things continue moving the WebAssembly direction).

Even if you're using Python's SciPy today, you're calling into LAPACK written into Fortran.

Re:Modern C++ Won't Save Us by pjmlp on Tuesday April 23, 2019 @04:12AM (#19726529)
Case in point, most modern OS GUIs are written in managed languages nowadays, even Qt has JavaScript bindings now.

Yet, C++ is still there as the binding layer between UI and GPGPU.

Re:Modern C++ Won't Save Us by ncmncm on Tuesday April 23, 2019 @12:31AM (#19725632)
That doesn't make C++ a good language. It just is one.

Rust is also a good language. Trash-talking C++ does no one any good.

Overwhelmingly, the substantial gains to be made are moving people off of C. Every other possible benefit is a rounding error. It is still much easier to get people to C++. Once dislodged, they might continue on to Rust, or br seduced by C++'s greater expressive power and more powerful libraries. Either way the world will be better.

C++ today seems weighed down by legacy cruft, compared to Rust, but Rust is rapidly accumulating its own legacy cruft. By the time it is mature it will have easily as much of its own.

Re:Modern C++ Won't Save Us by koffiezet on Tuesday April 23, 2019 @07:06AM (#19727364)
I started came from a C background (mostly for embedded stuff, where on many platforms a C++ compiler wasn't an option) - and eventually moving to C++ for backend and library work was a pain in the ass. I got the hang of it, but never loved it, although for the goals we had to achieve, it was a sensible choice. I however moved into more of an ops/SRE role mainly due to to C++ not entirely being my thing while the dev that was always most in touch with the ops side of thing.

I do see many of the advantages of both Rust and C++, but one of the reasons I like C is its relative simplicity. I only did a single small thing in Rust to try it out, and while still quite complex, at least it felt more manageable than C++ once you understood the borrow checker. The big elephant in the room however is Go. Every time I started something and would consider Rust, it ended up being 'why not just Go?'.

At least for me, it was much better suited language to be moving to coming from a C background. The biggest initial hurdle was setting up the dev environment with the completely backward GOPATH and GODIR environment variables - which just feels absolutely wrong (although this now in the process of being addressed). The language itself however was an absolute breeze, I felt right at home. Simple, quick, straight-forward, with tons of libraries and tools for my current field of work, coupled with performance more than acceptable for 99% of the applications I need and static binaries which are easily deployed anywhere, also eliminating a ton of complexity. Is it perfect? No, but what language is? But if you want to convince C-programmers to ditch C for a memory-safe language - Go is imho in many cases a much better option to move to.

Re:Modern C++ Won't Save Us by _bxg1 on Tuesday April 23, 2019 @01:07AM (#19725743)
"or be seduced by C++'s greater expressive power"

There's a deeper debate lying at the heart of the Rust-vs-C++ conversation (it's the same one at the heart of Haskell-vs-Lisp), which is really about expressive freedom vs. the strategic usage of constraints. That debate will, truly, outlive all of us. You can probably guess which side I'm biased towards; I won't lay it all out here.

Re:Modern C++ Won't Save Us by ncmncm on Tuesday April 23, 2019 @11:56AM (#19729824)
This is not about "expressive freedom" vs "constraints". Rust lacks many of C++'s key core language facilities to capture semantics in a library. As a consequence, you cannot write powerful libraries in Rust that you can in C++, and you cannot use powerful libraries such as are written in C++.

Since you cannot use these powerful libraries, you are (if you like) "constrained" to write fragile code at what would have been the call site.

Each use of a powerful library eliminates all the bugs that would have come from not using one. Those are bugs that Rust designers have elected to keep, in exchange for the memory-use bugs that we largely eliminate, in C++ code, by reliance on powerful libraries.

Powerful libraries eliminate many, many more bugs besides memory misuse.

Re:Modern C++ Won't Save Us by int_19h on Tuesday April 23, 2019 @03:23PM (#19731964)
Can you give an example of said "key core language facilities" that make some library implementable in C++, but not Rust?

I can give an example of the opposite: language-aware macros. No amount of C++ TMP hackery can approach a well-designed Rust DSL.

Re:Modern C++ Won't Save Us by ncmncm on Tuesday April 23, 2019 @11:26PM (#19735303)
Rust macros understand types now? Woohoo!
Re:Modern C++ Won't Save Us by int_19h on Wednesday April 24, 2019 @07:51PM (#19743672)
Can you clarify what you mean by "understand types"? The only thing I can think of in this context is compile-time reflection - but that's not in C++, either (yet).

Ideally, can you give a concrete example of some abstraction that can be implemented in C++ with templates, but not in Rust with generics and/or macros?

Re:Modern C++ Won't Save Us by _bxg1 on Tuesday April 23, 2019 @12:16PM (#19730029)
"Rust lacks many of C++'s key core language facilities to capture semantics in a library."

Can you be more specific? I don't even know what you mean by "powerful library". If you mean a library that's been developed and debugged for a long time, then sure, C++ currently has the advantage there, but that's a transient state and nonspecific to the language itself. If you mean a library that does wild, earth-moving things then I would call that a liability, not an advantage. The language features that allow such things are sources of bugs that Rust designers have elected not to introduce in the first place.

The question of, "In April 2019, which language and ecosystem are more reliable?" is a perfectly valid one. Stronger language semantics vs decades of library refinement. It's not at all obvious. But the answer to "Is Rust or C++ a better language in the long run?" seems clear to me.

Re:Modern C++ Won't Save Us by ncmncm on Tuesday April 23, 2019 @08:15PM (#19734354)
Could you write a Rust equivalent of the STL, or its modern cousin Ranges? That's just one library (as of C++20), but if Rust is not up to that, there's no point in going further.
Re:Modern C++ Won't Save Us by steveklabnik on Tuesday April 23, 2019 @09:21PM (#19734744)
The equivalent of Ranges is already in Rust’s standard library, and has been forever. We call it Iterator. It also provides extra static guarantees against invalidation.
Re:Modern C++ Won't Save Us by ncmncm on Tuesday April 23, 2019 @11:25PM (#19735299)
I see that you did not understand my question.

I see, too, that there are plans for some support for generics in the near future. So the answer might become yes, in time.

Re:Modern C++ Won't Save Us by steveklabnik on Wednesday April 24, 2019 @11:42AM (#19739503)
Rust has also had generics for a very long time.
Re:Modern C++ Won't Save Us by shmerl on Monday April 22, 2019 @09:24PM (#19724824)
Qt has Rust bindings now. I hope CUDA will get replaced with proper cross GPU alternatives anyway. Rust GPU programming should be also possible.
Re:Modern C++ Won't Save Us by jclay on Tuesday April 23, 2019 @12:46AM (#19725678)
The issue with bindings is that you either commit to maintaining them yourself, or you rely on someone else. In this case, the Rust Qt bindings I found [0] were generated for Qt 5.8, which was released nearly 3 years ago. The tests on Github report "failing".

Then, you have the cognitive overhead of translating the documentation, and other sample code. In my experience with bindings, this ends up requiring knowledge of the language you're binding to. It seems easier to just write it in the native language instead and deal with those quirks rather than bindings quirks.

Do the Rust bindings show the Qt docs in the autocomplete? If there's not input validation on the binding side, then you'll end up in C++ again figuring out how to sort things out.

Regarding CUDA, I think we're all hoping for a cross GPU alternative. There's OpenCL, Sycl, ROCm, Kokkos but their API is also written in (you guessed it) C++. Need to render to OpenGL? You'll be writing in C. Unless one of the companies decides to replace driver interfaces with Rust, any application using them will be dependent on N bindings working.

You're ultimately not escaping C/C++ for any systems development. You either deal with the complexity of interfacing between language A and C/C++ or just deal with the quirks of C/C++ themselves. Pick your poison.

0. https://github.com/rust-qt/ritual

Re:Modern C++ Won't Save Us by shmerl on Tuesday April 23, 2019 @12:52AM (#19725694)
There were multiple attempts at such bindings. The most promising is this one:

https://github.com/KDE/rust-qt-binding-generator

> You're ultimately not escaping C/C++ for any systems development.

We eventually should. C/C++ should retire even for drivers and kernels. But for now there is still a lot of baggage to deal with indeed.

Re:Modern C++ Won't Save Us by mokus on Monday April 22, 2019 @10:27PM (#19725092)
Rust gpu programming is very possible already, but as of my most recent foray into the area it was still very much a black art getting your build environment set up for it. It’s probably just a matter of time before it becomes an easy thing to do.

I’ve done a fair bit of mixed Rust + CUDA C++ though, and found it to be a very nice way to build high performance code with safe high-level interfaces that someone can grab and use with little to no understanding of GPU architectures. It’s even pretty straightforward to build wrapper types that leverage Rust’s ownership system to track lifetimes and safe management of device buffers as well (unfortunately I can’t release that code but it really was pretty simple so hopefully someone else will soon do it openly, or by now maybe someone already has)