Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Does the case for C++ in 2020 still exist? Rust and Go are much simpler to learn, can do everything that C++ can and have sane, simple and clean build systems/package managers, not to mention async/await concurrency in the former and channels in the latter.


> can do everything that C++ can

There are still areas where C++ is more expressive than both rust and go. AFAIK rust just recently got the capability to work with const generics and compile time evaluation.

Lack of overloading (besides operators) in Rust is a double edged sword. Overloading allows for very expressive C++ code in the expense of awful error messages when it doesn't work out.

C++'s concurrency story is continuously improving, but I'm not qualified to compare here. C++20's coroutines will be quite powerful.

And there is one area where Rust and go can't compete: interacting with existing C++ code, including templates. There is a lot of that already.

Having said that I keep a close eye on rust, it can certainly replace C++ in certain areas, possibly all areas in the future. But it can't replace it overnight, considering that there are millions of lines of _maintained_ C++ code out there.

Not go though, that's like comparing apples to oranges.


I think this is probably the most important reason you list: interacting with existing C++ code, including templates.

I wonder if we could ever get direct Rust to C++ FFI. There are ways around it of course, by dropping down to C FFI in both languages.


> I wonder if we could ever get direct Rust to C++ FFI

https://github.com/dtolnay/cxx/ exists and works well AFAIK. That's what Chromium (https://chromium-review.googlesource.com/q/project:experimen...) and others use.


It's important to remember that C++ doesn't define an ABI, so you'd have to focus on specific compilers' ABIs.


For some reason I thought C++ had gotten a stable ABI? Not sure why (I’ve been out of C++ dev for years).


There isn't any standard C++ ABI but there is a de-facto standard ABI that many compiler writers have agreed upon (icc, clang, gcc), funny enough it was developed for Itanium originally: https://itanium-cxx-abi.github.io/cxx-abi/abi.html


C++ has a policy of not making changes that would break anyone's ABI, but still doesn't have an official one.

https://cor3ntin.github.io/posts/abi/


> Does the case for C++ in 2020 still exist?

The question is the opposite: you have to prove to managers the benefit overcomes the risk of using a new language. Rust is still not nearly stable nor popular enough for many fields.

Go is a very different language with different goals and constraints, so the question does not really fit.

> Rust and Go are much simpler to learn

Go is a simple language, yes. Rust is a different beast with the same intrinsic complexity as C++.

> can do everything that C++

Not exactly true (for the moment). Rust is lacking on const generics, HKTs and other details.

> sane, simple and clean build systems/package managers

That is not a big argument for the kind of projects is used for.

And it is not true either, since nowadays there are several competing, modern package managers for C++ too (build2, Meson, Conan, modern CMake...).

> not to mention async/await concurrency

The async IO model has been available in many languages for many years, including C++. In the recent years several languages (including Rust and C++) are bringing syntax sugar to let the compiler create the state machines. But it is not the only way of doing async.


> The question is the opposite: you have to prove to managers the benefit overcomes the risk of using a new language. Rust is still not nearly stable nor popular enough for many fields.

I'm not sure what you're saying. Rust 1.0 code compiles just fine in the most recent rust compiler. It's been stable since that 1.0 point and promises to continue being stable. C++ doesn't have a a stable ABI either.


This from yesterday:

https://news.ycombinator.com/item?id=24032305

Tl;dr: C++ is now and will remain the near-exclusive choice for essentially all of the highest-paid, most demanding work in medtech, fintech, CAE, HPC, telecom, and aerospace, for decades to come. Rust code will never be able to call into the very powerful libraries these applications depend on, because they are based on language features Rust will never have. No language other than C++ and Rust targets these applications.

Very noisy Rust advocates here are inaudible elsewhere; many more people start using C++ in every week than the total who touch Rust in that week. That will not change soon.

Rust is a much better language than C, Go, Java, C#, Visual Basic, Delphi, COBOL, Nim, and Dart, and much faster than Python, Ruby, and Perl. Advocates would better focus recruiting there than tilting at C++.


We mostly use C rather than C++, but the same two big reasons get in the way of using Rust for everything:

* Compiler support

* Availability of suitable engineers

Context - I work for the Wireless Division of Cambridge Consultants (Cambridge, UK). We build comms technology for our clients for basically anything you can think of - satphone, telecomms infrastructure, bluetooth headphones etc. This means that a lot of the software we right runs on an embedded target - that might be a microcontroller or it might be Linux. And importantly - often when we've designed something, our clients will carry on the maintenance and ongoing development.

We have to take the long view - if we choose C/C++ we can guarantee that a compiler will exist for whatever hardware target they choose for the next generation of the product (or even the current generation - architecture swaps often happen at the cost reduction stage). Rust support is improving but can I guarantee that there will be a compiler available for some niche processor, or even the Xilinx Zynq target I'm using at the moment?

And then when we hand over the code, we have to explain to the client that it's written in a language that none of their existing software engineers know, and if they advertise for people they may or may not be able to find them.

All that said, we are pushing to use more suitable languages for our work. Using C/C++ for anything where security is important is beginning to look irresponsible, the above issues don't always apply and that combined with improved embedded support, more name recognition for Rust and ever more enlightened clients means that it's going to be an easier sell for more and more projects. But not all of them, not now.

Actually it turns out that it's easier to sell Elixir as an alternative to some of our C development. My current project is a Linux target, microprocessor support is not important and the challenges it has are exactly what Erlang is designed to solve. I'd also suggest it's easier to incrementally teach the client Elixir than Rust. We'll keep pushing Rust though, and we'll get there eventually.


I have experienced this horrible chicken-and-egg problem firsthand. I worked at Zipcar building the control boxes used for rentals and the fit for Rust was obvious and compelling, but was squashed by management because it was "too hard to hire" and "the language is underdeveloped". While those things are true, to fix them someone has to just do it. Instead, they fired me and now I make twice the money doing SRE work again at a FAANG.


The problem doesn't exist for in house software. Any good programmer can learn whatever language in a week. They can become good over the next few years. Coworkers to help teach help a lot.

When you turn code over to someone else it matters because who you turn it over to needs to learn the language fast and they won't have a few weeks or someone else to teach them.


Plenty, let me see.

Although it is a polyglot target environment, CUDA hardware is designed for optimal support of C++ semantics.

C++ is used for device drivers on Apple and Google's OSes.

Swift and Rust depend on LLVM, written in C++.

Unreal, Unity, CryEngine, Godot have C++ at their core.

AUTOSAR safety standard for cars is based on C++14.

UWP and DirectX are heavily based in C++.

Tensorflow and PyTorch depend on C++.

And plenty of other endless examples.

Sure you can try to make do with Rust or Go, but be prepared to code like we used to program in C++ 30 years ago in regards of eco-system, IDE support and wealth of existing libraries.


Yep, and consider the chromium code base, or at least V8 which is embedded in all sorts of projects. C++. Yes, you could use a Rust wrapper, but it would not be pleasant. There's a bunch of other examples of this kind of thing.

Additionally, if you work at one of the FAANGs (or many other large established companies) there's good chance you are working on an existing C++ base, with existing C++ build tools, with a good C++ style guide, and with plenty of other competent C++ engineers. Rust is not of the endorsed/established languages at Google. (And no, Go isn't frankly used as much at Google as people seem to think it is, though its use is increasing).


> be prepared to code like we used to program in C++ 30 years ago in regards of eco-system, IDE support and wealth of existing libraries.

That's a bit of an extreme statement that needs some significant qualifications. This might be true if you are pushing for Rust or Go in one of the domains you mentioned, like professional game development. It would be fairly absurd for a studio to seriously try to switch to Rust in some of these areas.

That said, if you're largely working on greenfield projects that don't rely on an existing C++ ecosystem, the situation almost gets inverted. For instance, C++ still doesn't have any kind of standardized package manager in 2020. There are a thousand little paper cuts in C++ that are hard to justify if you don't have to interface with an existing ecosystem or target a specialized environment that only it is well-suited for.


C++ has a large ecosystem in certain domains that Rust and Go can't match (and may never be able to). Graphics and game development are examples. So I don't think C++ is just going to die out and be replaced entirely by Rust and Go. Also, in some of these domains, Go fundamentally isn't a good fit, though Rust theoretically could be if not for the ecosystem problem.

That said, I do think that for a certain category of greenfield projects that can avoid needing certain types of dependencies on and interactions with other existing software or codebases, Rust and Go will completely dominate C++ going forward. For new work that doesn't need the C++ ecosystem and doesn't rely on dependencies not available for Go/Rust, it really is hard to imagine how one of Go/Rust would not be a significantly better choice in 2020 and beyond.

Some companies will be entirely based on such greenfield projects. Others will be entirely based on problems that rely on some of that existing C++ ecosystem. Yet others will be mixed and may be able to use C++, Go, and Rust as it makes sense. So I think it's going to be a complicated situation where some folks will be able to completely move ahead of C++ and others will be tied to it for a long time yet.


>Does the case for C++ in 2020 still exist? Rust and Go are much simpler to learn, can do everything that C++ can

There are 2 levels of comparisons:

- (1) language syntax : the "they're both Turing Complete" so whatever one can do, the other can do and because Rust is newer, it has nicer syntax. E.g. plain Rust syntax already has "ownership pointers" by default so doesn't require typing ugly verbose syntax such as "unique_ptr<T>".

- (2) ecosystem and dependencies : In 2020, C++ and not Rust is still the primary API for things like NVIDIA CUDA, Unreal game engine, Qt GUI, and the ARM Allinea developer tools[1] for compiling code for the new Neoverse chips (e.g. latest AWS Graviton2 ARM servers). Sure, one could write wrappers in Rust for all those things but doing so will be going against the grain and now you're yak shaving your tools instead of building business value.

If I had a brand new startup today, I'd use Rust as much as I could but there'd still be 25% to 50% new C++ code because deep learning (e.g. CUDA) is C++ not Rust.

[1] https://www.arm.com/products/development-tools/server-and-hp...


> Rust and Go are much simpler to learn

I don't think this is true. I say that even though I would be deliriously happy if Rust replaced C++ in most situations it's currently used.

Yes, learning the whole of Rust, including any/all dark corners (no doubt it has a few) is easier than learning the whole of C++ including all its dark corners (it certainly has many!). But getting a basic working knowledge of both is not too different... except for Rust's ownership system. I realise that the ownership system is one of Rust's main benefits, but that doesn't change the reality that it's a significant obstacle for many decent developers.

I actually wish it were possible to use Rust in an "unsafe everywhere" mode where you could ignore the ownership stuff. (Maybe this is already possible with liberal use of the "unsafe" keyword, but it is at least socially unacceptable.) Of course it wouldn't be right for every project but it would still be a huge improvement over C++ while being much more accessible than fully safe Rust.


As someone who had a go at both languages Rust has some hard topics, but the time needed to know enough Rust to be able to not shoot yourself in the foot while getting things done is lower than in C++. Of course this has to do with Rusts philosophy of not letting you shoot yourself into the foot, while in C++ you'd have to get much more experience to achieve the same robustness.


Yea I don’t think it’s even comparable, and with c++ it’s still a nightmare to import anything not to mention having to deal with the horribly awkward syntax they have accumulated over the years


Just wait until Rust gets 50 years old.

As for the rest, there is vcpkg and conan nowadays.


Used both vcpkg and conan, not comparable to the ease of use of cargo.

Needed some high performance code last year, wrote it all in c++. This year migrated to Rust, will never look back.

C++ is going to need to break things if they want to fit into the modern landscape.


Cargo is only simple if one is doing FOSS with Rust only code.

Speaking of modern landscape where is a Rust IDE comparable with VS, C++ Builder, QtCreator?


Cargo works fine with private repositories, and I use it wrapping C++ code and that works fine as well.

I use VScode with rust-analyzer and its been a great experience, had an easier time with it than the c++ vscode extension.


> Cargo works fine with private repositories

So does any of the main package managers for C++.

> had an easier time with it

That is an empty argument. Not to mention Rust is only now in 2020 starting to get actual IDE support.

For C++ there are at least 8 major production GUI IDEs available, plus a few TUI ones too, plus dozens and dozens of specialized tools around it.


> So does any of the main package managers for C++. Never said they didn't...

> That is an empty argument. Not to mention Rust is only now in 2020 starting to get actual IDE support.

Actually thats an empty argument, I'm responding to someone saying rust doesn't have IDE support.

It does, I use it every day and it works great. Not saying c++ doesn't just saying it worked better for me than the MS c++ vscode extension.


The person you are responding to is talking about an actual IDE, not an extension to VS Code.

rust-analyzer is great and we have waiting for it a long, long time. But it is not an IDE. Neither is the MS C++ extension.


what? Yes it is, vscode was built to be powered by extensions and they work great.

I've been using vscode for the last 5 years for all kinds of languages and have never though to myself "I wish I had an IDE"


You can also do all your work in a raw text editor, yet you prefer VS Code. Same distinction for an actual IDE.

The Rust and C++ extensions are very far from what an IDE offers. They only handle basic debugging and code completion/browsing. With a few more extensions you can a bit better, but again, you are doing the job that an IDE is supposed to solve for you.


I guess I'll take Rust is my no good "editor" over c++ in a "proper IDE", don't think thats gonna sell most people


CLion has excellent Rust support, among other IDEs..


Yeah, JetBrains has been the first major player to bite, but what others do you know of?


And C++ supports private and public repositories, why waste time always compiling the same binaries for third party dependencies?

There is an eco-system out there for C and C++ developers where companies only sell binary only libraries.

VSCode is not an IDE, just an text editor with a couple of plugins.

C++ Builder, Visual Studio, XCode, Android Studio, QtCreator, KDevelop, those are proper IDEs.


lol "proper IDEs" ok...

vscode is one of the most used editors on the market and I seem to be able to produce quality software in a number of languages with it.

As for binary dependencies, I'm certain Rust will have that in the future. I'm fine without it for now, and what I'm not certain of is whether C++ will ever actually fix their problems because they seem to think they don't have any!


> vscode is one of the most used editors on the market

So not an IDE, see.


funny, it has all the features of an IDE


I guess you never used an IDE.


never in my 10 years of programming a bunch of languages, never done it


Presumably the C++ package managers don’t do very well when interacting with non C/C++ code either? I don’t understand the argument...


It's not possible, because unsafe does not turn anything off; unsafe is a superset of safe.


But if I use unsafe everywhere then couldn't I pass around raw pointers everywhere instead of references to avoid the lifetime checking? (Try to contain your horror! :-) )


Only if you write the entire universe; you're going to want to call functions that accept references, and then you're stuck.

> (Try to contain your horror! :-) )

Ha! Nah, no horror there. It is interesting to think about, for sure.


But I thought you could cast a raw pointer to a reference with "as" in an unsafe block? Obviously that makes it possible for you to create multiple mutable references, or a mutable reference at the same time as an immutable reference, which is undefined behaviour, but undefined behaviour was always going to be the risk of this idea. Also, even if you had a compiler switch to make "unsafe" implicit everywhere, your code is going to be littered with a lot of casts.

(Obviously I'm not a Rust expert, which is why my comments are in the form of questions.)


Nah it's all good! This is a pretty common thing, and sometimes comes in an alternate form ("can't you just Arc all the things?")

You can cast them to a reference. The issue is, the tricky UB happens at this exact boundary. If you're only using references, then the compiler has your back. If you're only using raw pointers, then there are no aliasing issues, so you're good. The hardest part is exactly the boundary between the two. Staying in one world or the other is much easier than going back and forth.


You may have a team of experienced C++ developers and libraries of C++ code to interface with.

I think one make a good argument for Rust, but you will also have a harder time sourcing developers and ramping up to speed. It's still novel, despite maturing rapidly.

There are many many many high quality C++ libraries out there, and the modern C++ language is, for me, decently pleasant to work with, once you pick your style and set of constraints.

Also, I really don't want to go around on this argument _again_, but I don't think Go is a serious competitor for C++ for the systems level programming where C++ dominates. Go is not the language for writing OS kernels, drivers, embedded code, etc. Nor do I think a garbage collected system is appropriate for hard real time systems of most kinds.

I think what we have here in this discussion is another classic case of HN having a bit of a blindspot for anything that isn't web / web services or mobile app development. For many embedded systems developers for example it's a challenge just to get them to consider C++ over C, let alone something like Rust.


The c++ library argument is funny to me because it’s so incredibly difficult to import external projects in c++. This is where Rust is going to eat their lunch.


You're defiantly missing the point and beating it to death.

The issue for you might be ease of configuration, but that's not the issue I was talking about. It's availability of libraries and toolkits, which C++ still dominates in the realms of mathematics, graphics & video, GPU programming, gaming, embedded, networking, etc. And if there's something not available for C++ chances are it's there for C and easily used or wrapped.

Configuration management has indeed been C and C++'s weak point, but in the last 5-10 years things have definitely improved since the world of autotools and the like, and while I appreciate Rust's module and package system for what it is... I can get by with CMake + Hunter or similar systems.

And besides, for my day job (Google) it's either C++ with GN/Ninja or C++ with Blaze/Bazel. And that is also quite excellent for what it is.

At this point my career being able to quickly try out a package or rapidly add a new dependency isn't my measure of quality engineering. In my past life I was a Java developer and a big Maven advocate (when it was pretty new); and the world of bottomless dependency trees that spawned is not something I'm eager to repeat. These days I try to keep my external dependencies ... strategic.


packaging == community

and community is the most important aspect of a language.

Yes c++ still dominates in accelerated computing but it won't for long. All these conversations I've had with c++ devs have just assured me of its demise.

Why would the next generation of developers ever use c++ over Rust?

Don't have a library? Great thats my chance to make my mark.


Had C++ standed still, yes.

Except that now there is vcpkg, conan, prefab (on Android) and contrary to cargo,they support binary libraries, meaning I don't have to build the world every time I start a new project.


Conan and vcpkg are not even remotely standardized on in the C++ community, and C++ teams I've worked on/with recently wouldn't use either of them, preferring raw CMake only. That said, if the whole community could really get behind one of them and throw immense support behind it for several years, it would probably be possible to largely solve this problem for C++.


Those on Microsoft world will need to get used to vcpkg, no matter what, because that is how Microsoft is now delivering some of their C++ libraries.


C++ has had ages to solve this problem, vcpkg and conan are still a ways away from the simplicity of cargo.

Doesn't support binary libraries? I don't really care considering everything else I get, I'm sure they'll support that in the future.


Cargo is only simple if one is doing FOSS with Rust only code.

Speaking of modern landscape where is a Rust IDE comparable with VS, C++ Builder, QtCreator?


Cargo supports non-public package repositories, not sure what you’re referring to here?

You got a similar response in another thread: https://news.ycombinator.com/item?id=24038376


They are complaining about no support for binary-only crates, which is not cargo's fault, but rather Rust's lack of stable ABI.


Ah. With decompilers these days, what’s the point? I only want that for the potential speed of overall compilation benefits.


I think adding external projects to a C++ project is a major decision that should be taken very carefully and the amount of research you need to do to make such a decision pales in comparison with just how exactly you integrate it in your project so you can #include its headers and link against its libraries. Then once all that work has been done it's now part of the internal repository so using it with any number of internal projects should be quite easy.


In the modern world you should be able to grab things and quickly integrate them and see how they work as your prototyping projects.

C++ doesn't conform to this model.


This keeps being repeated and repeated and it is just a myth.

Even without a package manager adding dependencies manually is quite easy for the vast majority of popular libraries. With a manager it is the same as cargo.

I assume you are talking about old, broken, unsupported, closed source, binary only libraries, but then it is not a meaningful comparison.


Its really not, even with current libraries, not when you come from languages that have a modern packaging system.

This is exemplary of why Rust will win out in the end. The c++ crowd can't acknowledge its shortcomings and fix them in a meaningful way


It is the same for cargo, npm, pip, C++ managers and other languages.

Usually a single line does it in all of them, either in the shell or in a config file.

I call FUD.


It was rarely a single line with C++ when I used it over the last year, moving to cargo it is literally always a single line and I was done.

Rust is going to make the C++ community actually look in the mirror for the first time in who knows how long.


So that project didn't use a package manager and you extrapolate that to an entire ecosystem.


Its sooo many projects, if the argument is that c++ has all these libraries, thats mute, but again the c++ devs just think everything is fine!


Well I still can't create a mature cross-platform GUI app in either Go or Rust and Qt seems to be the first class option for that in the C++ world.

Looking at some of the solutions for both Go and Rust, its either immature bindings to wrap around C or C++ for the same thing (the best you would get is GTK+) which are unmaintained and less stable / usable to what you would get with Qt5 with C++.

I still keep seeing lots of cross-platform closed and open-source GUI apps still taking the Qt route.


Anything related to graphics or game programming has very few reasons to switch to something else than C++ (talking about the engines, not the scripting part).


And for the scripting part something like .NET or Python rules, and will hardly change given current industry adoption.


FWIW, C++ has actually had stable async/await (I have been shipping a production product compiled to numerous platforms now for a year built with C++ coroutines) since before Rust finished theirs (and from what I so far know about Rust's, I like C++'s better, though I admit I don't know enough enough about what Rust did). C++ also frankly has a much better cross-platform build system story, with more extensible and hookable builds (the ability to do header injection on library dependencies with #include_next is epic)... I have so many bugs filed against cargo and rustc with respect to even basic cross-compile scenarios it isn't funny anymore :/. (I mean, cargo doesn't even get reproducible builds for cross-compiled binaries correct, though at least I was able to figure out a super awkward workaround for that where I give it a "rustc wrapper" and then run a filter on the command line arguments to strip the host-specific cargo metadata.) Some of us also think Rust made the wrong call on not supporting exceptions (if you want to use "monadic error handling" but you don't actually support defining monads, something seriously broken happened). C++ also has faster serial build times than Rust and fundamentally better support for parallel and incremental compilation than Rust (due to its support for prototypes and translation units; I ship my builds off to AWS lambda and expect to get linear speedup on -j1000 now that Amazon supports EFS mounts). <- So like, while I might agree that Rust's build system is "simple and clean", the reality is that computers aren't and so it is a fundamental mistake to make such a rigid build system :/. Rust is also still lacking in some key type system features, such as being able to template over values (which lets you create compile-time safe buffer types), which is a frustrating tradeoff against Rust's feature of lifetimes (which is absolutely a good thing, but isn't actually a source of issues in my code vs. buffer handling: what I really want is even dependent types... if Rust had at least gone for full linear types it would sell me much more quickly, as dealing with those situations is currently miserable in both languages and I know I could use such a facility to prevent the vast majority of the issues I actually run into in my code with respect to asynchronous cross-computer behavior). C++'s obviously-trivial compatibility with the massive ecosystem of C/C++ libraries is also useful. And like, while I totally appreciate the reasons object oriented programming can suck, for GUI programming it is still an incredibly common paradigm that C++ supports but is directly supported by neither Rust nor Go (which I haven't complained about at all in this comment, but mostly because I consider it a competitor to Python, not C++).


For example, one can code with async/await in UWP via C++/WinRT today, without having to think which runtime to use, or possible incompatibilities across async runtimes.


That’s because WinRT already provides an async executor based on the Windows thread pool for you, C++ coroutines specify the plumbing for writing coroutines but nothing more, just like Rust - Microsoft just spent the time working up the WinRT async interfaces to coroutines.


ISO C++20 defines them in a way that the current incompatibilities in the Rust world aren't happening as such and any C++ library using concurrency features is expected to just work across compilers.

ISO C++ also does not define how std::thread should be mapped into the host platform.


If you are supporting Windows or Linux, and are supporting the x86 platform, then for me the only reasons to use C++ over Rust are for compatibility with existing code/libraries, or lack of Rust expertise on the team and no time to learn Rust.

If you are working in an embedded environment Rust is still very capable, but the tooling for Rust does not seem at the level of the embedded tooling for C and C++.

You can still use Rust for embedded, and there are success stories to be found in the links below.

[1] https://www.rust-lang.org/what/embedded [2] https://rust-embedded.github.io/book/ [3] https://github.com/rust-embedded/awesome-embedded-rust [4] https://github.com/rust-embedded/cortex-m-quickstart


> the only reasons to use C++ over Rust are for compatibility with existing code/libraries, or lack of Rust expertise on the team and no time to learn Rust

But these are huge reasons. It is the difference between theory and practice. In theory you can just replace C++ with Rust. In practice, it can be difficult because of those reasons.

Choosing a language isn't just about the language, but about the entire ecosystem and community.


It really depends. In some domains, compatibility is a big enough reason as to completely rule out Rust or Go. In other domains, it's just not something you need at all.


No, for things like database engines C++ still has significant expressiveness and memory model advantages. While you could write something equivalent in Rust, it would require a lot of "unsafe" since it can't express the memory semantics of some modern architectures and it would require much more code.


as someone whos really interested in this kind of thing, what kind of memory semantics specifically does c++ support compared to rust?


A couple examples:

Rust requires references to memory to be visible at compile time. If you use direct DMA for I/O then the silicon holds mutable memory references at runtime that are not visible in code at compile time. In C++ you can make ownership objects (in the vein of unique_ptr) that automagically track the lifetime of DMA references. Exposing most of your address space to DMA is not optional in databases if you care about performance. DMA has other nuances as well e.g. it can modify memory that is not part of the object you care about and which might be "owned" by someone else.

There are safety models wherein it is provably safe, and optimal code-wise, for multiple mutable references to the same object to coexist at runtime. Modern databases often use schedule-based safety, which dynamically reorders operations on references at a fine-grained level, for performance reasons, and which guarantee correctness of the aggregate execution graph without using locks. This wasn't common a decade ago but it is today. A developer can grab all the mutable references they need to objects, knowing that the execution scheduler can see through and arbitrate any potential conflicts. (This is a sophisticated reimagining of the old "deadlock-free" locking structures in databases without the locks, which didn't prevent deadlocks per se but transparently detect and resolve them.)

You can make all of this work in Rust by using a lot of "unsafe" and inelegant data structure workarounds but it voids most of the safety benefits of Rust and requires more complex code.


It takes work, but you can write safe DMA code in Rust. A good post by Jorge Aparicio explaining how is at his blog[1].

[1] https://blog.japaric.io/safe-dma/#:~:text=DMA%20stands%20for...


thanks for the reply!

> In C++ you can make ownership objects (in the vein of unique_ptr) that automagically track the lifetime of DMA references.

does that require os support to make it work? i assume the tracking is handled by some specific inturrupts?

> You can make all of this work in Rust by using a lot of "unsafe" and inelegant data structure workarounds but it voids most of the safety benefits of Rust and requires more complex code.

i see... so i guess rust would have to take one small step out of static, and into dynamic territory with a smart pointer "trait"?


The OS has to provide syscalls and other APIs for scheduling DMA operations into your address space. Linux has supported this to some degree for a very long time (storage DMA was introduced in the 2.5 kernels). In terms of behavior and APIs, storage is very different than network, since the former is schedule-driven and the latter is interrupt-driven.

There is a lot of implementation detail, but you need object references that are aware when a DMA operation is outstanding on address space they “own”, the type of DMA operation, and rules about when new DMA operations can be scheduled with respect to object reference lifecycles. There are no fixed set of rules but there are a common set of design patterns. The scheduler design does a lot of the heavy lifting.


i see, very interesting, thanks ^^


So giving up on Visual Studio, C++ Builder, QtCreator, NVidia NSight productivity, and fast builds via UWP/COM tooling is compatibility with existing code/libraries?


My dude, we get it, you like your IDEs. You don't have to mention it in every comment thread.

If you find Visual Studio and CLion to be your desired work environments, both of them have support for Rust code via extensions. No it won't be as perfect as what you're used to, but it will be more than sufficient for most people.


Well, there are plenty of dudes like myself to convince to drop 50 years of mature tooling support.


I use Visual Studio Code for both my Rust and my C++ work, and love it. Tooling support comes from plugins there.

I've also used QtCreator, and hated it because for me it was a resource hog, you had to do things its way, and the Qt APIs were horribly designed.


> can do everything that C++ can

Don't know about Rust, but for go:

    . can't match C++ on speed
    . doesn't (yet, AFAIK) have generics.


Go also can't call any C libraries without massive overhead (at least not the reference implementation), nor run without a runtime. Go isn't really an alternative to C/C++/rust and it's not meant to be.



Every programming language is, to different degrees, a replacement for every other programming language. Whether Go is a replacement for C++ or not depends on what you want to do. For a lot of use cases where you might choose C++, Go would be fine too.


I think GP’s point is that the overlap of domains that C++ is well-suited for and that go is well-suited for isn’t particularly large.

Go was at least originally touted as a C++ replacement, but to be honest, that story hasn’t really panned out in practice.



With all due respect, I said the overlap wasn't particularly large. Not that it was entirely nonexistent.


The last few strongholds I see with C++ is probably game development. To crack into gaming industry, C++ is still a must-have skill.

But TBH, I really don't want to use C++ if the circumstance allows. The language spec is just so overtly complex that feels self-defeating, it is harder and harder to justify use it in the first place.


I think if you are on a green field and do not rely on specific i.e. libraries that are not there yet in Rust, I would have a hard time finding good reasons to use C++ over Rust. Mainly I guess if you have really good C++ programmers who are not interested in Rust.

If you are not on a green field, stuff gets complicated. If you have a really good Rust programmer on the team, that is willing to take care of the language interop it can work well, if you have a bunch of Rust learners, you might blow up.


That's a pretty low threshold to pass, obviously it's not doing to die overnight in 2020. C++ will continue its steady decline in mindshare but the user count will stay high, countered by the growth of the programmer population.


> Does the case for C++ in 2020 still exist?

Are there C libraries you want to remain (nearly) source-compatible with while using classes, templates, and other more modern programming features?


> Does the case for C++ in 2020 still exist?

Even if exist, is better to let it die. C/C++ is a costly mistake. VERY costly.

Apart of interact with legacy code, both C/C++ have much better replacements (like pascal).

Is only the stubborn "but what if I need to replace my heavily bug-ridding, unsafe, crash-prone, hard-to-mantain, harder-to-prove is good; source code, and need to retrain my developers that spend a lot of mental energy in workaround them in something, better?????"

Our industry is weird.

In any other, if the "engineers" insist in use a well-know unsafe tooling and refuse to learn safer tooling/practiques you will fire them as incompetents.

By the way, I learn mechanical engineering (at trade level).


> Even if exist, is better to let it die. C/C++ is a costly mistake. VERY costly.

Not sure what you are basing this on but it's probably not an exaggeration to say that C/C++ has generated hundreds of billions of dollars in revenue over decades, not mentioning employment, advancement in programming language theory, learning lessons, etc...

I am really not a fan of C++ overall but its achievements cannot be understated. Saying it's a "VERY costly mistake" is baffling.


> Not sure what you are basing this on but it's probably not an exaggeration to say that C/C++ has generated hundreds of billions of dollars in revenue over decades

And PHP, Cobol, Perl, etc. Just because a tool is useful is not a reason to avoid point their problems.

And C/C++ have very well know problems, since decades ago.

> Saying it's a "VERY costly mistake" is baffling.

Maybe if MS say it?

https://www.zdnet.com/article/microsoft-70-percent-of-all-se...

https://www.zdnet.com/article/microsoft-heres-why-we-love-pr...

Just to point a recent one...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: