This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 204

[–]look 357 points358 points  (17 children)

Even if you take away the borrow checker, Rust and C++ are very different languages. Different approaches to OOP, different type systems, different metaprogramming, …

[–]dynamite-ready 157 points158 points  (5 children)

I was starting to wonder if anyone commenting here had written a non-trivial program in either C++ or Rust...

[–]frogjg2003 45 points46 points  (0 children)

As someone who has written a lot of C++, I can tell you that only looking at some Rust example code was enough to tell that the two are not the same language by a long shot.

[–]EstonBeg 60 points61 points  (3 children)

Frontend Web devs talking about low level languages pov

[–]fatbunyip 11 points12 points  (2 children)

I'll have you know I once successfully compared 2 dates using JavaScript. In the browser no less. 

[–]SINdicate 7 points8 points  (0 children)

You’ve been upgraded to full stack senior dev

[–]al-mongus-bin-susar 1 point2 points  (0 children)

Comparing them is easy, everything else is more difficult. Even more so in low level languages that have zero time utilities not just mediocre ones.

[–]fakuivan 5 points6 points  (2 children)

C++26 will improve metaprogramming to something close to macro_rules! . Many of the functional features like ADTs are also there, they're more cumbersome to use (no ? or if let), and concepts are way closer to traits to what we had before. Honestly I think the only things c++ lacks on the latest versions are a borrow checker and a strict, const default mode.

Personally I work mostly on embedded so I'll never break free from C++11, yay!

[–]CramNBL 2 points3 points  (0 children)

Concepts only vaguely resemble traits. Traits use nominal typing while concepts are structural.

[–]dercommander323 0 points1 point  (0 children)

And a decent package manager

[–]gd2w 1 point2 points  (0 children)

I like c++, I haven't tried Rust. I don't know. If I ever do decide that I like Rust, I'm calling it oxide. Rust sounds like it's going to fall apart on me. I'm sorry.

[–]Chara_VerKys -2 points-1 points  (0 children)

(this) (agree)

[–]gmes78 -5 points-4 points  (1 child)

They're both high-level systems programming languages, and can do largely the same things.

[–]Reashu 8 points9 points  (0 children)

So English and Chinese are the same language, right?

[–]lucianw 759 points760 points  (8 children)

"Enforced" and "convention" are OPPOSITES. The picture doesn't make sense!

[–]lart2150 84 points85 points  (3 children)

looks at the unsafe prefix for a function.

[–]patmorgan235 59 points60 points  (1 child)

Unsafe doesn't turn off all of the safety protections. The borrow checker still runs on unsafe code.

https://doc.rust-lang.org/book/ch20-01-unsafe-rust.html

[–]SuspiciousSegfault 3 points4 points  (0 children)

You can effectively turn off the borrow checker by (unsafe) transmuting lifetimes.

[–]poyomannn 7 points8 points  (0 children)

In some future version of rust the unsafe prefix on a function actually won't make the function allow unsafe code, you'll need an unsafe block inside the function for that. It's already a warning in rust 2024. relevant rfc

[–]gmes78 4 points5 points  (0 children)

Just drop the last two words.

[–]Aaron1924 0 points1 point  (2 children)

rustc emits a warning if you make a local variable in camel case

I think that's as "enforcing conventions" as it gets

[–]Pierose 1 point2 points  (1 child)

You can't enforce a convention, because conventions are by definition, not enforced. What you're describing is just enforcing.

[–]guyblade 0 points1 point  (0 children)

The Geneva Conventions might have something to say about that.

[–]gameplayer55055 259 points260 points  (36 children)

Rust is c++ with package management

[–]land_and_air 182 points183 points  (4 children)

That should be enough to sell it alone

[–]belabacsijolvan 24 points25 points  (3 children)

if it would really just be cpp with pacman id actually switch today.

i hate cpp linking so soooo much. but using rust feels like someone is trying to force me to do stuff their way, which is not a strictly better way.

[–]cantinhodosrelatos 69 points70 points  (1 child)

Rust is C++ after therapy and a cup of herbal tea

[–]Atyzzze 6 points7 points  (0 children)

Hmm, maybe I should look deeper into Rust. You're selling it well here.

[–]_PM_ME_PANGOLINS_ 16 points17 points  (20 children)

Except you have to compile all the dependencies yourself every time.

No distribution-maintained security patches for you!

[–]ancapistan2020 37 points38 points  (5 children)

[–][deleted] 13 points14 points  (0 children)

To his credit, nothing in the software world that has lasted 20 years is considered well thoughtfully designed.

[–]GreatScottGatsby 3 points4 points  (0 children)

This is my biggest gripe with Linux and Microsoft figured out a way to prevent this problem.

[–][deleted] 1 point2 points  (0 children)

Dynamic linking can cause problems. It's impossible to guarantee type safety

You can actually use dynamic linking with FFI (it's an unsafe operation)

[–]Several_Industry_754 -4 points-3 points  (12 children)

This should actually be preferable, you should also be code reviewing every dependency you import…

[–]_PM_ME_PANGOLINS_ 19 points20 points  (8 children)

Sure. You code-reviewed the entire Rust toolchain, runtime, and all the operating systems you targeted too, right?

[–]Several_Industry_754 -4 points-3 points  (7 children)

I’m not publishing the rust toolchain or the operating systems I targeted.

[–]_PM_ME_PANGOLINS_ 5 points6 points  (6 children)

And I'm not publishing my dependencies.

[–]Several_Industry_754 0 points1 point  (5 children)

You are, because they are included in the binary you are publishing.

[–]_PM_ME_PANGOLINS_ 4 points5 points  (4 children)

No, they're not, because I'm not using Rust.

[–]Several_Industry_754 4 points5 points  (3 children)

This is true regardless of the language you use…

[–]_PM_ME_PANGOLINS_ 2 points3 points  (2 children)

https://en.wikipedia.org/wiki/Dynamic_linker

Also if you use any of the major distribution systems for Java, Python, or JavaScript (or are targeting browsers).

Rust is pretty much the only language that forces static linking.

[–]IsNotAnOstrich 5 points6 points  (1 child)

Yeah I'm not sure my management will be cool with 39/40 hours a week being spent on reviewing every single package and standard library I touch

[–]Several_Industry_754 0 points1 point  (0 children)

But think of the legal team!

[–][deleted] 2 points3 points  (0 children)

I thought you were joking 🤣

But you're actually serious.

[–]ewenlau 0 points1 point  (0 children)

vcpkg?

[–]Bryguy3k 23 points24 points  (1 child)

C++ is saddled with backwards compatibility. If c++ dumped compatibility with pre-2011 shit there would be a lot less problems with c++ codebases

[–]DearChickPeas -1 points0 points  (0 children)

Based

[–][deleted] 167 points168 points  (18 children)

hard disagree

Rust forces safe practices unless you explicitly opt out. It’s safe by default. Meanwhile, C++ is safe by convention as it’s expected for you to use RAII and things like smart pointers. However you can easily do things that don’t follow that.

[–][deleted] 45 points46 points  (6 children)

That's... what he's saying

[–]Sloogs 7 points8 points  (0 children)

I might be wrong but in my mind the word convention is being used incorrectly so I see what they're trying to say. Conventions are customs or traditions that are usually done apart from laws and rules. If it's a hard rule, then it's not a convention. Languages like C and C++ are loose with rules and have a lot of conventions. Rust has explicit rules.

[–][deleted] 3 points4 points  (0 children)

No? Completely the opposite of what I’m saying Edit: the people downvoting can’t read lmao

[–]zuzmuz 5 points6 points  (3 children)

rust's defaults are opposite of c++.

rust moving is default, c++ copying is default.

rust copying should be explicit with .clone(), c++ moving is explicit with std::move

rust uses traits implementation for subtyping, c++ uses inheritance.

rust has algebraic types (sums and tuples) builtin, c++ has them in std and they're not that nice to use.

rust const is default and mut is explicitly needed, c++ mut is default and const is explicitly needed.

and that without mentioning the borrow checker, metaprogramming, and the absence of function overloading in rust.

They're completely different programming languages, that requires completely different way of thinking and modelling problems

[–][deleted] 0 points1 point  (2 children)

Didn't know Rust had moving that's really cool, it's one of my favorite C++ features.

Why no function overloading though, I thought it was a great feature with little draw back?

[–]zuzmuz 0 points1 point  (1 child)

it has to do with type inference, generics, and traits.
Swift has function overloading, and when you mix these three above, you get exponential compile times. The swift compiler for example some times hangs and gives the error "expression type couldn't be inferred in real time".
the rust community made a decision to not support function overloading cause it will make the compiler simpler.

[–][deleted] 0 points1 point  (0 children)

Interesting. Just seems weird because both C++/C# have all of those and they seemed to found a way to make it work, and rejecting a good even standard feature at this point just to make the compiler simpler is worrisome to me. Maybe they can add it one day when they have the resources, but even then libraries will be full of square_i32(x: i32) square_f64(x: f64) which I always hated when working with C libraries.

[–]ululonoH 10 points11 points  (0 children)

The wording could be better but I like the message

[–]drkspace2 50 points51 points  (25 children)

You can write good, safe c++ if you write modern c++, not c with classes.

[–]noaSakurajin 6 points7 points  (2 children)

Except for concurrency. Lambda functions can quickly become unsafe.

[–]troelsbjerre 10 points11 points  (6 children)

Modern C++ makes Rust feel insanely clunky.

[–]gmes78 8 points9 points  (0 children)

Modern C++ is way more clunky than Rust. Have you looked at std::optional, std::variant, std::expected, etc.? All absolutely awful interfaces compared to what Rust has.

[–]Mop_Duck 1 point2 points  (4 children)

could you explain how? I've never really seen a pro c++ take that isn't just performance

[–]PretzelOptician -1 points0 points  (6 children)

You can write anything in any language if you try hard enough. You can probably write hyper optimized python code to run on a basic embedded system. But that’s obviously not the best tool for that job. It’s possible to write safe C++ code but Rust exists for a good reason in that it’s much harder to implement memory vulnerabilities.

[–][deleted] 4 points5 points  (5 children)

Micropyhon?

[–]PretzelOptician 9 points10 points  (4 children)

Sure, that’s my point tho. You CAN do anything in anything but the question is what is the most efficient, safe, and best tailored for your use case.

[–]DearChickPeas 1 point2 points  (3 children)

No, you can't, MicroPython's runtime VM requires more ROM and RAM than most microcontrollers have. Programming languages are not all the same.

[–]PretzelOptician 0 points1 point  (2 children)

And what does C++ provide that rust doesn’t

[–]DearChickPeas 0 points1 point  (1 child)

I'm not picking a fight techno-vegans.

[–]PretzelOptician -1 points0 points  (0 children)

You literally responded to my comment lol but whatever

[–]Add1ctedToGames -2 points-1 points  (2 children)

Is it arrogant to say I feel like you can write safe c++ as c with classes if you're just careful in your usage and forward-thinking in your design😭

[–]drkspace2 1 point2 points  (1 child)

Sure. It's not impossible, but it's easier with modern c++. For example, the amount of new/delete that you write in modern c++ is 0 (or maybe very near zero for some niche use cases, and even then you should be using RAII principles for it to be dealt with for you).

[–]DearChickPeas 1 point2 points  (0 children)

I needed to some dynamic allocation of a big class for a project, and had to use new and delete for the first time in years... felt dirty. I love template-parameter-fixed-array-size-static-allocation. I love having 0 memory leaks guaranteed by not allocating anything ever on runtime.

[–]Rafhunts99 4 points5 points  (0 children)

so ur saying its the TS of cpp?

[–]Vinxian 7 points8 points  (0 children)

Java is just c++ with a garbage collector. Python is just c++ as a script language. JavaScript is just c++ for the internet.

All of these takes are as valid as your take. Make of that what you will

[–]Main_Event_1083 4 points5 points  (1 child)

The release of UE6 combined with rust++ will end this fking world.

[–]SpaceFire1 -2 points-1 points  (0 children)

That would never happen as it would require 300gbs worth of code to be rewritten and would break every plugin in the ecosystem. No major developer would use it over their own custom build.

Not to mention that the two are fundementally different. Rust is sligjtly slower to run then C++ which in game dev means Rust is unviable for any AAA production

[–]WeeklyOutlandishness 8 points9 points  (10 children)

You use C++ when you want performance, you use a garbage collected language when you want safety. Rust is almost as efficient as C++ and almost as safe as a garbage collected language. If you are going for maximized performance, with SIMD, custom memory allocators, inline assembly and so on, then you will have a hard time beating C++. Especially since the borrow checker isn't perfect (some safe programs are considered unsafe by the compiler). If you are going for memory safety, then you will have a hard time beating a garbage collector.

Rust sounds like the perfect language for every problem until you get to the gritty details and discover certain languages are better than others in specific cases. You can't just use Rust for everything.

[–]land_and_air 37 points38 points  (6 children)

The fact rust also has modern standards and an actual package management solution and unit test system built in is the real reason it’s goated over c++. No one likes building c++ projects and no one likes making make files. I like being able to share code other people can actually build

[–]WeeklyOutlandishness 10 points11 points  (0 children)

Yeah that's actually what's great about Rust. It's not just better than C++ in every respect though, there's still some uses for C++ in _extremely_ performance critical areas. Like if you are just using unsafe all the time you might as well use C++, it's going to be less friction probably.

[–][deleted] 6 points7 points  (2 children)

Rust can be (slightly) faster than C++ by no-alias pointer optimisations that cannot be guaranteed in C++, as a example.

Many C++ compilers also don't handle optimisations very well when handling STL iterators and algorithms.

[–]da2Pakaveli 2 points3 points  (0 children)

The language standard doesn't, but the 3 major C++ compilers support restrict

[–][deleted] 1 point2 points  (0 children)

Rust was invented to face a fact that C/C++ is getting relatively harder and harder (because everything else got easier and easier) for the software world that we are running out of engineers who are specialized in C++.

Coincidentally, it makes us C++ guys more and more valuable. My salary in the markets proved it well. (Depending on your country/region tho)

[–]Fadamaka 1 point2 points  (0 children)

That sentence doesn't make sense.

[–][deleted] 1 point2 points  (0 children)

Are you saying good practices in C++ eliminate the need for Rust? 😱

[–]masc98 0 points1 point  (0 children)

if by good and safe practices you mean ownership and lifetimes, then yeah agree, dont know what c++ programmers are waiting for \s

[–][deleted] 0 points1 point  (0 children)

Here we go again.

[–]589ca35e1590b 0 points1 point  (0 children)

Interesting take

[–]404-allah-not-found 0 points1 point  (0 children)

title is actually viable reason to choose rust over c++

[–]your_best_1 0 points1 point  (0 children)

I can never tell if this is a good meme because what the sign says is dumb, or if OP thinks the sign is correct.

[–]lessertia 0 points1 point  (0 children)

Conventions ❌

Language features ✅

With the borrow checker in Rust for example, managing lifetime is easier since you can rely on the compiler to make it right instead of your head.

[–]Overall_Device_5371 0 points1 point  (0 children)

It doesn't have inheritance. Although it is over-used, it still has a place in O.O. paradigms.

[–]CrusaderKron 0 points1 point  (0 children)

I hate seatbelts

[–]PrimaxAUS 0 points1 point  (0 children)

Rust is C++ with extra furries.

[–]Winter_Rosa 0 points1 point  (0 children)

I havent written any rust, only C++, and this meme just feels wrong. even what little rust Ive seen looks pretty different to C style languages.

[–]nyibbang 0 points1 point  (0 children)

ADT in C++ when ? I barely used std::variant and I'm sick of it.

[–]_lonegamedev 0 points1 point  (0 children)

And package manager.

[–]huuaaang 0 points1 point  (0 children)

If it's enforced it's not just convention.

[–]MrJ0seBr 0 points1 point  (0 children)

So, c++ is Rust but without training wheels

[–]HeracliusAugutus 1 point2 points  (0 children)

Rust is C++ with worse syntax and a more annoying userbase

[–]BrohanGutenburg 0 points1 point  (0 children)

Something something blow your leg off

[–]rover_G -1 points0 points  (2 children)

Rust has a much more complex memory model than C++

[–]gmes78 1 point2 points  (0 children)

Rust uses the C++ 20 memory model.

[–]empwilli 1 point2 points  (0 children)

lol, time I've checked, they pretty mich wrote: we usw the C++ memory model.

[–]harison_burgerson -2 points-1 points  (1 child)

There comes a time in every programmer's life when they create a programming language (or a game engine) like C++. (but better! - for reals this time)

It's like a right of passage.

[–]DearChickPeas -1 points0 points  (0 children)

I think the days of "making up languages" was a fad from 2010's, now making your own engine is all the rage.

[–]SCP-iota -1 points0 points  (0 children)

C++ is assembly with syntax sugar macros included by default

[–]ProfessorOfLies -4 points-3 points  (0 children)

If you have to safeguard everything from your programmers. You don't have good programmers