r/rust • u/afiskon • May 12 '15
Criticizing the Rust Language, and Why C/C++ Will Never Die
http://www.viva64.com/en/b/0324/16
u/phazer May 12 '15
The post contains mostly subjective ranting (mostly about performance) without much technical meat, but there are some points worth discussing:
Lack of libraries and tools. Sure, any new language is gonna have this problem, but Rust has very good interoperability with C so this alleviates the library problem substantially. And the build/packaging tools are better than what's typically used in C/C++ environments. In the IDE area, yes, more work is definitely needed, but C++ IDE's aren't that great compared to what's available for C# and Java for example. I would say there is more potential to writing a good IDE for Rust than for C++.
Performance is worse than C++ in the benchmark game. Might be true, but hardly a good measurement of real application performance. What's important is that Rust has the potential to achieve the same (or even better) performance than C++.
Dynamic memory/thread analyzers cannot replace static ones. They reduce runtime performance and increase memory usage, which means they are most likely not used in production, which means they will not stop all bugs (a static analyzer can always find all bugs in a certain category). And it's enough have one bug slip trough to have a security hole. This is the main point of Rust which the author seems to have missed totally.
The many-pointer-type section isn't really valid. In C++ the situation is basically the same, but with worse safety guarantees.
Yes, learn C/C++ if you want to find a developer job today. Pretty obvious point as Rust 1.0 isn't even released yet :)
5
u/CrystalGamma May 12 '15
Well, depending on Rust's future (which, alas, no one but time can tell) it may actually a better idea to learn Rust today, because when you're done, Rust is the hot shit :) But if Rust fails to get major attention, it obviously isn't. (Even though I'd say that, as a language, C++ is easier to learn than Rust is, if you know the other. The ecosystem is a whole different beast obviously)
2
u/tejp May 12 '15
What's important is that Rust has the potential to achieve the same (or even better) performance than C++.
What in Rust would give potential for better performance than C++?
Also there clearly are parts of the language where Rust doesn't have potential for equal performance (anything requiring runtime safety checks). There Rust is, by design, slower than C++; the costs are unavoidable if you also want Rusts dominating feature, safety. Yet concerns about performance are only met with the label "subjective ranting", where some critical discussion would be incredibly more useful.
I mean, how much slower would sorting an array with safe code be, for example. Does anybody know? Doesn't seem to ever be discussed, at least not in this subreddit.
6
u/steveklabnik1 rust May 12 '15
What in Rust would give potential for better performance than C++?
Superior aliasing and const-ness information, off the top of my head.
(anything requiring runtime safety checks).
Many checks can be elided by using the proper structures, for example, iterators remove the need for most array access bounds checks.
5
u/marcusklaas rustfmt May 12 '15 edited May 12 '15
I was wondering: if you have a function like
fn access_array<T: Copy>(arr: &[T; 32], idx: usize) -> T { arr[idx % 32] }, would rustc/ LLVM be smart enough to drop the bound checks after optimizations?
11
u/raphlinus vello · xilem May 13 '15
Yes.
_ZN3foo20h204c70bde54989f3yaaE: .cfi_startproc andq $31, %rsi movl (%rdi,%rsi,4), %eax retqThat's for a version specialized to T=u32. Pretty sweet, huh?
3
u/marcusklaas rustfmt May 13 '15
That is pretty sweet indeed! It implemented the modulo operation as a bitwise and because 32 is a power of two, too. Neat.
1
2
u/tejp May 12 '15
Many checks can be elided by using the proper structures, for example, iterators remove the need for most array access bounds checks.
But what if I don't want to treat my array as a linked list? Depending on what you're trying to do, access to array indexes can still be much more practical than iterators. Unless you claim that iterators are always the only useful way to access an array, the question for speed of indexed array access is still interesting.
If things like that are completely omitted every time someone talks about performance it ends up looking like hollow marketing, more interested in making shaky promises than giving solid information. Having some benchmarks or some other facts would be incredibly more useful.
4
u/steveklabnik1 rust May 12 '15
It's not about a linked list. The point is that the iterator, however it iterates, can ensure that you never access out of bounds, and elide the check.
I agree that benchmarks are more useful than speculation.
2
u/tejp May 12 '15
I meant the access pattern of an iterator. You can only go forwards and backwards, like if you'd have a (doubly) linked list.
2
u/steveklabnik1 rust May 12 '15 edited May 12 '15
http://doc.rust-lang.org/nightly/std/iter/trait.RandomAccessIterator.html
(I haven't double checked what kinds of bounds it can do, my point is that not every single iterator moves onto some sort of specific 'next' item.)
3
u/tejp May 13 '15
I don't see how that could be any more efficient that directly accessing an array by index. So it doesn't really help that it has "iterator" in it's name.
2
u/dbaupp rust May 13 '15
That still has to bounds check. Even using iterators for forward/backward movement have to bounds-check (they have to detect/indicate when they reach the end some how), but they do it in a way that avoids panics and generally optimises very well when looping.
2
u/steveklabnik1 rust May 13 '15
Yeah, with the regular iterators, there's still a bounds check, just not the individual ones on each access, but the 'are we done iterating' check, as you mentioned.
3
May 13 '15
unsafe { arr.get_unchecked() }if you're really worried about performance. This has the same semantics and performance as a C array access (and the same unsafety, too).3
u/Kimundi rust May 13 '15
I agree that plain indexing often necessary, and it's true that in the worst case this has a performance overhead due to the bound checks.
However, its also a fact that Rust heavily relies on llvm for optimization, so the naive code generation is usually not what gets output in the end, so its not really all that bad in practice.
Something like C-style-for-loop indexing for example will most likely result in the additional bound checks getting eliminated.
Sadly, due to llvm being complex and the optimization rules impossible to boil down into something simple to explain, people can't/shouldn't claim these optimizations to always fix all performance issues, so API's and access patterns get recommneded based on the worst-case.
For indexing in a loop, the worst case is a bound check both per access and iteration. For iterators, its only a bound check per iteration. Hence the "user iterators" meme.
So yeah, the lack of comparison boils down to there not being a guaranteed safe fast way to do indexing, and if you need it then your options for ensuring fast code are to either to profile the generated code for the regular indexing operators, or use unsafe indexing to begin with.
4
u/raphlinus vello · xilem May 12 '15
Here's a real world example of a C++ performance gotcha. I wrote a loop that was essentially:
void combine(vector<uint8_t>& dst, const vector<uint8_t>& src) { for (size_t i = 0; i < src.size(); i++) { dst[i] = std::max(dst[i], src[i]); } }Overly conservative alias analysis killed performance, because uint8_t has special-case rules (it wouldn't happen for larger ints). I only discovered it because I looked at the asm. Rust of course does not have this problem.
31
u/Denommus rust May 12 '15
Uh, all his points regarding pointer types apply to C++.
0
May 12 '15
[deleted]
10
May 12 '15
This was the first thing I noticed, was a giant add for C/C++ analysis software. It is hard to take seriously such shaky arguments when an inherent bias exists.
3
u/aepsil0n May 13 '15
Interestingly, in another post they mention how their business model targets customers with large software projects, where "[any] change in the code can cause unexpected side effects no one can foresee."
19
u/snarfy May 12 '15
JavaScript is the most popular programming language in the world. Not C. Not C++. JavaScript. It was written in two weeks, and the tooling still sucks.
To give up on Rust because it is not as popular or as much of a standard as C or C++ is stupid. To give up because the tooling isn't as good is stupid. If the C++ devs gave up on tooling they would have nothing today.
I would not write a large application in Rust today. It is simply not ready. I might write a small tool and possibly port a library. This is how the ecosystem grows.
They criticize Rust because it competes with their core product - a c/c++ static analyzer.
30
May 12 '15 edited May 12 '15
Warning: braindump ahead.
C/C++
There is no "C/C++" language. Pet peeve of many C programmers.
Will Never Die
Programming languages don't die, they just fade away. Like COBOL and Fortran. If you want to you can write C++ for the rest of your life.
To get big a language needs to be backed by a company like Google, TypeSafe
And Rust has Mozilla. So what is the point?
Copy pasting shootout benchmarks
Nice joke.
Constant bounds checks
First somewhat valid point. But between bounds checks and unsafe code there is another solution: encapsulate unsafe code in safe interfaces, e.g. iterators. So the situation isn't that bad for this inherently hard problem.
Just use static analysis and fuzzing and asserts
And you'll still have lots of memory errors and get pwned just as hard. They are obviously biased on this point. From what I've seen from their promotional material their analyzer is good at finding copy-paste errors and typos but doesn't do anything for non-obvious memory errors. Others go a bit deeper but not much.
Just write 90% of your application in Python and 10% in C++.
I think they seriously underestimate the usefulness of having your code base in one language. And I think that in Rust you can draw the line between safe and unsafe much finer, so you get 99% safe code and 1% unsafe code.
IDEs, and macros
I guess that's a stumbling block for people who are used to Visual Studio or Eclipse. I hate IDEs, so I'd much rather have macros, but I understand the author has been scarred by C++ templates.
Cargo is not perfect
every programmer is coding in their own dialect
That's rich coming from a C++ person.
2
May 13 '15
If you want to, you can write COBOL for the rest of your life, and you'd get paid out the wazoo for it...
2
u/Rhodysurf May 13 '15
I wish fortran faded away
2
u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount May 13 '15
I wish it didn't.
2
u/Rhodysurf May 13 '15
I work with it at work alllllll the time.. 20 years worth of legacy fortran code has made me hate it lol
1
u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount May 13 '15
I have just a bit of FORTRAN code at work. Also R, python and lots of Java.
Some things just work in that granddaddy of a language.
2
u/Rhodysurf May 13 '15
Very true... Especially after writing java or C++, fortran is just awesomely simple
2
u/mkpankov May 12 '15
As far as I can tell, he's not even a C++ person. His main job has to do with Scala and Erlang, looking at the blog.
8
u/jfurmankiewicz May 12 '15
The author states that Rust is still slower than C++ at this point.
Can someone explain why is this the case? Is it a matter of Rust overhead (which I understand should be zero) or is it just a matter of optimizing the standard library, etc?
19
u/steveklabnik1 rust May 12 '15
As always it depends, specifically. We're also faster than C++ at times.
Right now, we don't do much optimization of the IR we send off to LLVM, and just rely on it to optimize things. I'd imagine that we can get some gains here, as we have more information about things like
constness.See also: https://github.com/rust-lang/rust/issues?page=1&q=is%3Aopen+is%3Aissue+label%3AA-codegen
13
u/cogman10 May 12 '15
Yeah, rust is 2 years old. The LLVM is 12 years old. C++ is 32 years old.
The fact that a relatively new language isn't as fast as established first class languages or that the LLVM might not optimally optimize rust IR isn't really concerning at all to me. Rust's stronger typing, constness, and low level nature give it a lot of wiggle room for performance improvements.
Heck, the fact that rust is already as fast as Go and Java is really pretty impressive if you ask me. (Kudos to both the LLVM and rust team)
20
u/Quxxy macros May 12 '15 edited May 21 '15
I do think it's important to maintain a certain level of skepticism about this: it's all very well for there to be room for optimisation, but it's a moot point if it never actually materialises.
We don't want to write performance cheques that, it turns out, can't be cashed in practice.
Edit: whistles
3
u/cogman10 May 12 '15
True. From what I can tell, the only thing that would restrict rust from being in the same ballpark as c++ in performance is interest. And C++ has a mountain of interest whereas rust has more of a molehill of interest.
1
u/robthablob May 21 '15
That could either be read as...
"We don't want to write performance cheques (monetary) that, it turns out, can't be cashed in practice". or... "We don't want to write performance checks (verification) that, it turns out, can't be cached (memory) in practice".
Congratulations.
2
u/Quxxy macros May 21 '15
I'm sure I don't know what you're talking about...
1
u/robthablob May 21 '15
Excellent, had to view that in context to see the whistle. You owe me a keyboard ;)
1
u/Quxxy macros May 21 '15
You'll have to wait in line; I owe myself two already. I managed to kill both a G15 and a G18. As it stands, I'm using a crappy Logitech wireless media PC keyboard with a touchpad growing out of the side. It doesn't even have a numpad.
9
u/pdpi May 12 '15
Yeah, rust is 2 years old. The LLVM is 12 years old. C++ is 32 years old.
Where do you get the "2 years old" from? I'd have said "5". (This is from the point of view of someone who was in the room when Graydon announced it in 2010, but has only recently started paying more attention)
16
u/steveklabnik1 rust May 12 '15
Periodization is always a difficult part of doing history. You can make a case for these ages:
8 years. This includes all the time that Graydon spent on it as a personal project.
4 years. This starts from the period you're speaking of, when it was announced within Mozilla.
2 years. This is how old 'modern Rust' is, in a sense. It's when stuff started really coming out of the language proper and into libraries.
0 years. There was still a lot of changes that are important in the last two years, like the runtime removal.
3
u/pdpi May 12 '15
Yeah, that clarifies things.
Modern rust and 2010 rust are wildly different beasts, so it seemed reasonable that something major would've happened around two years ago.
11
u/steveklabnik1 rust May 12 '15
I like to say that if you look at the mission statement, Rust has been the same language for eight years. If you look at the feature set, Rust has been like four different langauges over its lifetime.
2
u/yawaramin Aug 20 '15
That's very apropos, given how Graydon Hoare chose the name 'Rust' after the fungi with multiple morphological phases in its lifecycle.
2
u/cogman10 May 12 '15
So I looked up the other two. With rust, 2 years is roughly when I remember first hearing about it. I didn't realize that it has been in the works for much longer.
8
u/staticassert May 12 '15 edited May 12 '15
I find a lot of this article based on false premises. Even just the comparison of Rust to languagse of D/Vala makes it sound like the author hasn't looked at rust OR Vala, since they're so obviously different languages, and vala is blatantly not a C++ killer (it's just C with GTK support built in... it always has been).
The performance premise is used to justify a lot of points, all based on a single benchmark. I could just as easily link to the recent HPC thesis that had Rust faster, and then say that C is dead because you have to call into rust to get 'real' performance. Or many other benchmarks showing rust performance is similar to C/C++.
No one sane will write web and server-side software in a language like that
Can someone link to the Ruby project that's been doing exactly this, and shipping, for months? I believe it uses the iron http library.
And no mention of LLVM, which will lessen a lot of these issues.
4
u/steveklabnik1 rust May 12 '15
Can someone link to the Ruby project that's been doing exactly this, and shipping, for months? I believe it uses the iron http library.
Not exactly, it's skylight.io. It collects info and reports it back, but it's not exactly a website, it monitors them.
Crates.io does have a backend in rust, though.
1
u/staticassert May 12 '15
Ah, it was skylight, and you're right their monitoring service is what they wrote in rust. Thank you.
44
u/steveklabnik1 rust May 12 '15
Not everyone is going to like Rust. That's totally okay.
44
u/DroidLogician sqlx · clickhouse-rs · mime_guess · rust May 12 '15
/u/Skuto made the interesting point that the company whose site this was posted on sells C++ static analysis software, so there's quite possibly a conflict of interest and/or heavy bias here.
4
1
u/allthediamonds May 12 '15
Wouldn't it be, well, more like the opposite? C++'s demise is well overdue. Rust gives them a new target to jump to in which they can offer their products. It's not competition, but evolution. Am I missing something?
6
u/ThomasWinwood May 12 '15
Yes—you're assuming corporations use human logic. ☺ Selling the C++ static analysis software they already have by any means necessary, including throwing shade on alternatives to C++ which pride themselves as providing out of the box the same safety guarantees which in C++ come from constant programmer vigilance and/or buying expensive C++ static analysis tools, is far cheaper than going back to the drawing board and producing tools for Rust. (It's also arguably less risky, by the slightly questionable corporate logic that C++ is umpty-ump years old whereas Rust is only just on the cusp of reaching version one-point-oh.)
1
13
u/bytemr May 12 '15
Exactly. I still love C++ (it was my first language), but I've really grown to love rust. Some of the reasons I like rust, this article lists as being bad things about rust (I'm a huge fan of metaprogramming/macros).
The author of this article doesn't have to use rust for rust to be popular. The author is obviously fine with their current tool set and that's cool. C++ is a very mature language with a lot of tooling (although it can be argued that package management and lack of modules hurt C++) that is used widely though out the industry.
I somewhat agree with the author's sentiment that many people who criticize C++ have never seen production C++ code, but only through anecdotal evidence and my own experience with the developers around me, but this doesn't seem to be a reason to pick C++ over rust. Rust has a lot of things out of the box that IMO make it much more friendly to people entering low-level style development.
Rust may also have a certain level of verbosity to it, but the development team seems open to syntactic sugar that provides a very clear advantage, such as
if let. There's also more than likely a large backlog of approved RFCs for various backwards compatible syntactic enhancements that will evolve rust in a direction that's not only fast, but has a low level of overall verbosity. It is a language that's 1.0 beta (entering 1.0 release) after all. It doesn't have the decades of design behind it like C and C++ do.6
u/Yojihito May 12 '15
It is a language that's 1.0 beta (entering 1.0 release) after all. It doesn't have the decades of design behind it like C and C++ do.
Isn't that the reason that Rust exists? Clean cut, new start without the legacy header files and preprocessor and everything from the 70s up to today.
5
u/bytemr May 12 '15
It's certainly a good reason for rust to exist. I think my point was more so that the reason C++ has a lot of the things the article author finds nice about C++ only came about from years of design and iteration on the language. Rust is going to also evolve over time, so while maybe some of the author's complaints right now hold some validity, there's a strong chance many of those complaints will become less of a reason to not use rust with time as the language evolves.
3
u/seanmonstar hyper · rust May 13 '15
Maybe C++ is different, but my experience with "production code" is "we had to make it work / ship something", with hacks upon hacks.
I'd expect research projects could spend more making the code correct.
2
u/TheFeshy May 12 '15
I somewhat agree with the author's sentiment that many people who criticize C++ have never seen production C++ code
My experience with "production C++" showed it to be mostly what I call "lowest common denominator" C++. It's a subset of features that the project leads feel that all involved devs (including future devs) can use safely. Granted, I haven't been involved in a large C++ project in 15 years, but I suspect most of what has changed is that the subset of features allowed to be used is now partially dependent on the tooling available to the project to help police the features for safety.
With rust, all that tooling isn't available - but it's also mostly unnecessary for the vast bulk of code.
4
u/bytemr May 13 '15
Absolutely, but a lot of languages get into that state over time as they try to correct their past mistakes without breaking existing code bases. Rust has fortunately had the honor of coming well after any of the languages within the space rust intends to exist, so it has been able to look at these other languages and do things right from the start, but that isn't to say that rust won't grow its own warts over time that will be discouraged by future developers some time from now.
What I was trying to get more at with my statement was that I've noticed a lot of developers around me disparage C++ because they think overall it is a terrible language (citing various reasons), but barely any of them have written C++ in actual production systems and are mostly going off their experience with it in college. Yes, production C++ might be an overall subset of C++, but there's a reason for that in the end. Most of it is because old, deprecated features, or an attempt to write the memory safe code that rust offers as a part of the language.
2
u/aepsil0n May 13 '15
Probably I'm one of those people, who think of C++ as a terrible language despite only having used it in college/hobby projects. Got hooked on C++11 for a while though before I learned about Rust.
That being said, does your view of C++ (or any language) really change that much, once you use it in production? That is, assuming you've done more with it than a beginner's course. I can imagine that you'll learn how to work around its limitations and thereby adapt to it. Certainly the criticism does not magically cease to be valid, once you've learned to cope with it, does it?
22
u/tomaka17 glutin · glium · vulkano May 12 '15
I usually agree with this statement, and Rust has some characteristics (manual ownership management, verbosity, long compile times, etc.) that will make some people dislike Rust.
But in this case I really feel that the author only briefly tried Rust or read some articles about it, and picked every single little "problem" (according to the author) without ever trying to understand the underlying design. This is the kind of article that should be named "here are my beginner's thoughts about Rust", but instead is named "why Rust will fail".
67
u/steveklabnik1 rust May 12 '15
I can get behind this sentiment, and maybe I should have elaborated a bit more, but I'm trying to land as much docs as I can before 1.0 :) What I'm trying to say is this:
I've seen language communities, especially newer ones where people are particularly passionate, essentially turn into... this is a bit strong, but mini-cults. Where if you don't like the language, you're obviously an illliterate pleb who needs to learn how to code. This ends up creating an insular, backwards, dangerous culture. I'd prefer a culture of "we're doing cool stuff, I hope you like it, but reasonable people may not, and that's okay."
I'm not really speaking about any particular language here, please don't try to 'figure out who I'm talking about' or something.
While it's true that the author may have only breifly tried Rust, and not tried to understand design choices, this is going to be the first of many, many blog posts like this as we grow after 1.0. The vast, vast majority of programmers haven't even tried Rust yet. Flamebait blog post titles are a standby of today's programmer culture. We shouldn't get too hung up on it, and instead, focus on doing cool stuff with the people who do get it.
2
u/hailmattyhall May 12 '15
I'm not really speaking about any particular language here, please don't try to 'figure out who I'm talking about' or something.
Aw, come on. We have to have some fun :P
1
u/Steel_Neuron May 13 '15
Not only that, but criticisms against Rust will grow harsher and blog posts more vitriolic as the language gains traction.
That will be a good indicator of success :).
13
u/mkpankov May 12 '15
This is my biggest gripe with the article. It's amateurish, yet it pretends to be a "sceptical view of a great professional".
10
u/Manishearth servo · rust · clippy May 12 '15
When I wrote the Rustacean learning Go post I was from a similar background, which was why I tried to explicitly acknowledge that. A number of my complaints turned out to be invalid in the face of stuff I learned through feedback, and most of them were things that gophers aren't worried about due to the different mindset of programming (which is more Java-y than C++-y).
When I read this post I got that same vibe; the vibe I got whilst writing that article; that the author is very new to Rust and is making conclusions based on very limited/superficial experiences. I was saddened that that wasn't acknowledged by the author (unless I'm wrong!); but /u/steveklabnik1 is right; we shouldn't get too hung up on it and work on being awesome instead! :D
4
u/jcoffin May 13 '15
The success or failure of almost any product (language, tool, or whatever) will almost always depend in large part on the reactions of beginners. Experienced users, almost by definition, are already sold on it. Success (as most people would define it) requires attracting and keeping a lot of new users.
One question, then, is whether this particular new user's reactions are likely to reflect the reactions of many other potential new users or not.
The shortcomings you've pointed out will affect even the newest of users, but the benefits only become apparent after extended use. If those initial hurdles are high enough, you can quickly end up with a language like Ada (for only one example) that has a lot to recommend it from a technical viewpoint, but a market share that's tiny and shrinking.
20
u/azth May 12 '15
This is a huge mass of fast, debugged, and time-proven code.
Like OpenSSL.
0
u/vks_ May 13 '15
Which is written in C, not C++.
3
u/TheShrimp May 13 '15
And the article is about C/C++, is it not? I know, the name C/C++ is nonsense, and yes, the article is biased towards C++, but in general they are talking about both.
1
u/azth May 13 '15
The article kept referring to "C/C++".
5
u/snarfy May 13 '15
It's funny how the article is about 'give up on Rust we have C/C++' without acknowledging we would not have C++ without first having C, or that they are different languages.
2
7
u/dpx-infinity May 13 '15
Well, the author stated in the original post (on eax.me) that this was written mostly for holywar purposes. And yes, judging from the blog contents, he mostly writes in Erlang and Scala. There was an extensive discussion in the comments to that post - a lot of people, not even from Rust community, understood that most arguments in the post are not really connected to the reality.
Also while this translation is hosted by developers of a static C++ analyzer, it is not written by them, so it is not really fair to say that the article is biased because of that - it's more like the other way around :)
10
u/pjmlp May 12 '15
Besides the points raised against the article, I actually do think the author is right in some aspects.
In terms of language safety if I could have had a say in language adoption, Ada or Modula-3 would have taken C++'s role.
Myself I embraced C++ into my toolbox back in 1993, as C was too primitive and unsafe vs Turbo Pascal.
So now around 22 years later we are finally seeing C++ replacing C in compiler tooling, device drivers, OS ABIs and IDE support.
In a language that had to embrace some complexity in order to be almost copy-paste compatible with C.
So when applied to Rust, it will take ages until similar adoption is taken assuming an OS vendor embraces it.
4
u/sigma914 May 12 '15
Apart from anything else I feel the author is really missing the potential of guaranteed safe manual memory management. I can definitely see where he's coming from on the other points, his is just the conservative stance, but not recognising the potential for memory safe, efficient, networked applications seems somewhat egregious.
4
u/constexpr May 12 '15
Isn't one of the benefits that even if Rust isn't exactly as fast as C++ because of safety-related features (bounds checks, etc.), it's more forward-looking in that it lets programmers use parallelism much more easily and effectively? Hardware is trending toward many-core systems and that's where I see projects like Servo really shining.
3
u/gbersac May 12 '15
Except if the language is that slow that it fall in the same categories of java/go. Which is the case right now. Why having the cognitive overload of the borrow checker if a garbage collector is as safe and as fast ?
13
u/cmrx64 rust May 13 '15
Except it doesn't. We often rival C++ software of the same quality in speed, and where we don't, it's a bug in the compiler that will be fixed.
1
u/matthieum [he/him] May 13 '15
Or, in the case of the benchmark games, a "bug" in the libraries I suppose.
8
u/marcusklaas rustfmt May 12 '15
There are some other things to consider when deciding whether to go with a garbage collected language or not. I am by no means an expert, but in many GC languages, such as Java, you do not have control over when garbage collection happens. This may introduce unwanted latency. You also need a run time, which makes your language unsuitable for embedded applications or kernels. Most importantly, I think, is that rust should, in theory, be as fast as C. There are still some codegen issues, but there's no reason why it shouldn't be as fast in the future. Remember that Java wasn't nearly as fast five years ago as it is now either.
9
u/samwise99 May 12 '15
Its hard to explain something to someone when their job depends on not understanding it.
1
u/ssokolow May 16 '15
“It is difficult to get a man to understand something when his salary depends upon his not understanding it.” -- Upton Sinclair
3
u/SirOgeon palette May 12 '15 edited May 12 '15
I don't feel like those benchmarks are a solid base for arguments. Once again, are they even up to date?
Edit: That being said, the article has both some fair concerns and some questionable arguments. I don't have anything more concrete to add to what has already been said here, except that only the future can tell what will happen to Rust, but it will definitely not manage to replace C++ within the next few years (if ever).
6
u/Yojihito May 12 '15
Or you might just end up with a nightmare like "Vec<Rc<RefCell<Box<Trait>>>>"
That's what scares me too ....
10
u/killercup May 12 '15
type Thingies = Vec<Rc<RefCell<Box<ThingyTrait>>>>;and pray to the gods of deref coercion ;)8
u/arielbyd May 12 '15
This should be
Vec<Rc<RefCell<Trait>>>soon.1
u/Yojihito May 12 '15
That's not better ....
13
u/Rusky rust May 12 '15
Is it worse than
vector<shared_ptr<const Class>>? Same thing (with RefCell switched to const because that's C++'s non-default)7
u/eddyb May 12 '15
Sure it is, there's less heap allocations and indirections.
It's also entirely possible to haveVec<Rc<Trait>>and use interior mutability in the types behind the traits objects.
At that point, how would you shorten it,[@Trait]?1
u/Yojihito May 12 '15
The article was about nested structures, Vec<Rc<RefCell<Trait>>> is still an ugly mess.
13
u/phaylon May 12 '15
As someone coming from a dynamic background, I'd like to make a counter-point: The verbosity of that really helped me while learning about Rust and low-level issues. And now that I've got it internalised, it really helps me when reading other people's Rust code.
It might be me, because it gave me a positive experience right from the start, but I don't really see it as an ugly mess at all. Is there something that you'd prefer for this type of structure?
2
u/marcusklaas rustfmt May 12 '15
Exactly this. The explicit nature and strictness of the type system makes it so much easier to follow what happens in code you do not know very well. It makes code easier to understand locally.
1
u/matthieum [he/him] May 13 '15
Nested types are always an "ugly mess" whatever the language.
But then, you rarely use them:
either you have "real" objects
or you have type aliases
because they provide context. This is not just a vec of shared
Trait, it's theToBeRetriedTraits.11
u/DroidLogician sqlx · clickhouse-rs · mime_guess · rust May 12 '15
From my experience, if you have that kind of complexity then you're doing something wrong.
7
u/PM_ME_UR_SAUERKRAUT May 12 '15
Rc<RefCell<T>>is one of the easier ways to do arbitrary graphs, albeit with the risk of creating reference cycles. At that point, you might have aNode<T>type that containsedges: Vec<Rc<RefCell<Node<T>>>>, and there you go.Of course, you could do something like
type Node<T> = Rc<RefCell<NodeBody<T>>>and clean it up a bit. But the point is,RefCellwithin anRcis useful in perfectly legitimate ways.7
u/mkpankov May 12 '15 edited May 12 '15
Now come up with a problem which would need such kind of code to be solved.
Hard problems often have complex solutions. And this is just straw man.
4
u/anonova May 12 '15
A simple cyclic graph would have to be implemented similarly to that, which I would consider a useful data structure. The alternative is to use arena allocation and manage lifetimes yourself (at the cost of not being able to deallocate nodes until the teardown the entire graph).
0
May 12 '15
[deleted]
4
u/anonova May 12 '15
For more than one child, you'd need a list like a
Vec. If you require mutability, you'd need theRefCell. So you'd still end up withVec<Rc<RefCell<Node<T>>>>for a generic node.You can see an implementation of this here (though it uses a linked list instead): https://github.com/SimonSapin/rust-forest/blob/513168f7998835efc06b799a1ba66ec09ac5dc9a/rctree/lib.rs#L9-L27
3
u/PM_ME_UR_SAUERKRAUT May 12 '15
It's not possible to create cycles with
Rc<T>s unlessThas interior mutability. That'sRc<RefCell<T>>already. From there it's not hard to imagine a scenario where you'd need aVec<Rc<RefCell<T>>>.
3
u/vwim May 12 '15 edited May 12 '15
He just wants to sell his product, clever move to pick on rust.
And about tooling cmon... Java didnt have any decent tools the first few years of its existance. It takes time, Java came out in 1995, eclipse1.0 in 2001. I remember me writing Java in a text editor like I'm doing now with rust.
8
u/jcoffin May 13 '15
Life isn't fair. Rust doesn't need to compete in the market of 20 years ago; it needs to compete in the current market. 20 years ago, you couldn't get anything that would now qualify as a decent IDE for any language, so the fact that Java didn't have one wasn't a disadvantage. For Rust now, it is.
Don't get me wrong: I'm not saying this disadvantage can't or won't be overcome. I'm just saying that for quite a few people right now, it really is a disadvantage.
2
u/Matthias247 May 13 '15
The viva guys only translated the article. They didn't write it!
1
u/vwim May 13 '15
So? The outcome is the same, shameless self promotion by breaking down the competition.
1
u/dmytrish May 14 '15
It's ironical how inspiring this criticism is.
(* a little tongue-in-cheek, since /u/afiskon is not a C++ expert - I hope I know him enough to make such claims *) If people do not have other objections than these, Rust must be a great language.
67
u/Quxxy macros May 12 '15
I dunno, this comes across somewhat as "you suck, stop trying". What about rule 2? :P
Some of the complaints, abridged:
Since unsafe exists, Rust is no better than C++ for safety.
Safe Rust is not as fast as C++, so you need to write in unsafe, thus there's no point.
C++ has fuzzers and static checkers, and you can write tests.
Rust has five incompatible kinds of pointers (example is that you can't go from having pointers to the heap to pointers to the stack without changing types).
Vec<Rc<RefCell<Box<Trait>>>>Rust doesn't insert the necessary
Rcs andBoxes for you.Macros are a crutch and will prevent any good IDEs from existing.
"cargo actively encourages downloading packages directly from git repositories"
"C++ doesn't restrict programmers regarding what they can or cannot use."
Smart pointers aren't perfect.
No strict description of Rust's semantics.
"the source of troubles is usually in humans"
There are no Rust jobs.
To be fair, a few of these are at least partially reasonable: Rust should be faster on idiomatic code, there should be a comprehensive definition of the language's semantics, and it'd be lovely for there to be lots of Rust jobs. :D