3 ms·
> Why not? I don't see any reason why it can't compete. Heck, it's a pretty corporate language too in terms of its mozilla backing. It's niche, been around for
by zelly 7y ago
> Why not? I don't see any reason why it can't compete. Heck, it's a pretty corporate language too in terms of its mozilla backing.
It's niche, been around for over a decade, still hasn't reached critical mass. Golang did. Numerous mainstream projects are in Go that drive entire industries now e.g. docker, k8s. Rust's biggest deployed code is the CSS renderer of a web browser with single digit market share. I'm not saying Golang is better on PL theoretic grounds (obviously it's worse), but it proves what corporate marketing can do, which we have known since the Sun era. Also Python was not that popular until the same corporation behind Golang decided to adopt it and hired Guido.
C++ compilers don't catch all the errors, but static analyzers do. Taking your code snippet as an example:
% cppcheck ./main.cxx
Checking main.cxx ...
main.cxx:8:16: error: Using pointer to local variable 'v' that may be invalid. [invalidContainer]
std::cout << *ref;
^
main.cxx:6:13: note: Address of variable taken here.
auto ref = &v [0];
^
main.cxx:7:2: note: After calling 'push_back', iterators or references to the container's data may be invalid .
v.push_back (10);
^
main.cxx:5:19: note: Variable created here.
std::vector<int> v = {1};
^
There are proprietary static analyzers that go much deeper and catch less obvious bugs. Even without paying, you have ASan, TSan, UBSan, valgrind, afl, among others to do runtime analysis or fuzzing to catch memory errors and data races. Unfortunately these aren't used as much as they should be. Maybe those programmers have a point. In practice, memory management is not remotely the most difficult or bug-prone part of software. If you are using C++11 or later, the standard practice is to never do raw new and delete. std::move(std::unique_ptr...) has the same benefits as Rust borrowing without the borrow checker (although it is not rocket science to detect use-after-move with analyzers). Arc <-> shared_ptr. Sure, Rust's versions are better, but let's not get carried away, it's <10x better than C++ (with 1/10000x the ecosystem, jobs, books, libraries, people).
- steveklabnik 7y ago> been around for over a decade, Rust 1.0 happened in 2015; everything before that was incompatible with other releases, sometimes multiple times per day.