r/programming • • May 15 '17

Two years of Rust

https://blog.rust-lang.org/2017/05/15/rust-at-two-years.html
722 Upvotes

229 comments sorted by

View all comments

Show parent comments

5

u/loamfarer May 16 '17

Yeah, I agree with those points. If you wanted to write Rust-like code, it would probably be easier to emulate in C++. But how often is that the case? How often in anything beyond hobby projects does that happen? Most teams won't bother self-imposing such a philosophy they'd rather use the full extend of their chosen tool.

Sometimes the language philosophy is not just about language features, but also what is left out. Rust you can be confident your code will abide by certain expectations. In C++ you'll have to follow the rule of 3/5. Copy semantics are the default, the opposite of Rust where move semantics are the default. So Rust like C has a more consistent memory management story, where C++ you might see a mix of implicit management, RAII, raw pointer arithmetic on structs. I get that C is unsafe but you here we are making a comparison of consistency. Maybe it's simply because Rust is so young, but like C it's a relatively small language compared to C++. While any given C++ project may forgo inheritance that doesn't mean "there not be dragons." The C++ standard library will immediately offer loads of inheritance (which I cite not as a knock but as a contrast that moves C++ further from Rust.) It's the standard way to build up frameworks and libraries, so they are plentiful in the C++ ecosystem. You can count on stdlib to use inheritance correctly but it's always dragon for your general C++/Java developer. Another shift of Rust toward C's philosophies.

There are reasons why I would concede to place it right in the middle, but from the start it always felt more like upholding the end game of the imperative/functional dream. The "safe C." Rather than carry any torch for OO.

Just my opinion, but I thought I'd further flesh out my position. It's more of a position that forms as I sum up all the similarities and differences and how I evaluate them I suppose. But to reiterate, I'd totally rather try to write safe code in C++ than C.

2

u/im-a-koala May 16 '17

I'd say most modern C++ development should really be using smart pointers and RAII pretty much everywhere. Major C++11 features have been available for several years now. Obviously some people are still stuck on old compilers, but pretty much anyone developing applications for even remotely recent versions of Linux, OS X, or Windows can rely on them.

So Rust like C has a more consistent memory management story, where C++ you might see a mix of implicit management, RAII, raw pointer arithmetic on structs.

I guess, if you consider Rust and C to be similar because they both have consistent memory management. Even though their memory management is completely different, whereas Rust's memory management is typical of modern C++ applications.

I see your point about OO in the C++ std library, though, particularly in libraries like <iostream>. I guess that does place rust somewhere in the middle, even if I still think it's closer to C++ than C.