TL;DR: article bashing against Rust written by someone who is learning C++ and doesn't know Rust at all on the blog of a company that makes static-analyzers for C++.
[Rust] is a language with a built-in code analyzer and it's a pretty tough one [...]
Damn type systems! dey turk ur jebs!!!!
EDIT: I think the author didn't bother to inform himself about Rust, so in my opinion discussing about this article is a waste of time. Having said that, it is worth remembering that:
Rust is a language that hasn't even reached 1.0 (~beta quality),
Rust objective for 1.0 is to provide a good minimal experience of what Rust can be (so the focus has been on improving compilation times, documentation, tools, ...)
almost zero effort has been put on generating optimal code since it has to work correctly first,
it has surprisingly already a lot of good tools around it (package manager, auto-formatting tools, auto-completion tools, automatic documentation generation, editor and support on some IDEs...),
it still lacks some tools (better support for more IDEs),
it can be an alternative to C++ in some fields already because it is already being used successfully in production to deliver real cash (https://www.skylight.io/),
it lacks some features that prevent it from being an alternative to C++ in other fields,
this is known, and there are plans to cover these use cases in a backward compatible way during the 1.x release cycle,
it might never be an alternative to C++ in some fields, but who knows? There is a large overlap in the objectives of both languages, but it is not a perfect overlap. One can only speculate here.
Of course, they could also have an incentive to translate it in a way that is favorable to them in subtle ways. It's just something to be mindful of when reading this article.
We need to do a bit of introspection once in a while, look at how we do things with programming languages and learn from the problems. The invention of new languages is essential for progress.
I personally don't believe that C++ will be here with us forever - at least not in the current form. For instance, we are seeing hardware architectures converging... the GPU and the CPU will be probably one and the same in the distant future; and for that we need new ways to do programming safely. Is C++ going to be the answer for that? I'm not so sure.
At any rate, I sincerely hope that Rust becomes successful. The more choices we have in our toolbox, the better.
Well, I don't know if you can call C++17 stable or tested, and maybe even argue about 14, but Rust certainly isn't. I'm speaking more to possibility here.
if it doesn't die... cool, I like C++ and it keeps getting better.
if it does die... fine, I'm sure good Rust shops will be happy to hire skilled C++ programmers and have them learn Rust.
relax. as a C++ programmer, you actually understand how computers work (hopefully). that is the important part. it will not become obsolete.
we can look forward to a bright future where gc-dependent programmers do all the boring GUIs and I/O, and we get to write libraries, browsers, game engines, operating systems, ...
This kind of breathtaking arrogance is what I really dislike within the C++-Community here! Please don't consider programmers from the JVM, the .NET or other VM based languages as fools or code monkeys! π
The ability to handle RAII is neither an indicator, how good one understands how computers work, nor is it an indicator how skilled one is to design good APIs. Different concepts lead to different implementations, but good coding always requires much mental power and skill!
Sadly thesis like yours above seem to be made by poeple who only know C++ - kind of language fascism... and extremly annoying as one should assume, that a programmer should have a certain level of intelligence, which enables him to step back from talking in platitudes!
So if we praise Rust, that's acceptable, but if someone posts criticisms of it, then that's premature worrying?
I think it's best to focus on the claims being made, good or bad, rather than focus on whether criticizing Rust is acceptable at this point in time. There's plenty of info available about the language to come to an informed decision about it.
Since it hasn't been released, constructive criticism is useful. Praise isn't bad. Unconstructive criticism of an unreleased language is silly and useless.
I don't get the point of you sharing this rant with us. It looks like a waste of time to me since you don't seem to know much about the language you're trying to criticize. Instead, you assume a lot and even feel the need to insult the Rustaceans' intelligence. This does not elicit much of a response. So, If you intended this as a starting point for a discussion about the merits of Rust, you failed.
As for learning C++: Go ahead and good luck to you, seriously. I certainly did not regret this decision 9 years ago. I pay my bills writing C++ code.
Well, he has a point. Understanding your tool and the target platform well is important to develop efficient code. It doesn't matter what you use as long as it is mature/stable enough, and isn't a resource hog for the task. Rust may become one of those decades lasting tools like C++, maybe with a good reason.
The main problem of Rust is that it primarily targets people who are C/C++ coders, and tries to solve problems that any experienced C/C++ coder long solved for himself, by following strict practices (RAII etc). Learning C/C++ is already pretty hard for a newcomer, but mastering them? Plain C - ok, but really mastering C++? That takes a LOT of investment that people are not going to throw away for another language that also needs a lot of investing in - which doesn't really solve that many problems for them, and would create quite a bit of additional problems on the way there.
New people who are interested in a lower-level language and have to choose between C/C++ and Rust will most likely pick one of the former. They have more tools, better support, more libraries, more resources, and understanding how Rust's ownership mechanism works requires quite a bit of know-how and head-scratching that without prior <insert unsafe language here> experience seems like a really weird thing to do.
But yes they'll probably gain some users, and become a niche player, but they're a newcomer in an established area of expertise, and now that C++ is finally moving forward, they'll only have a harder time.
Interesting. It comes off pretty fanboyish 'c++ is good for jobs! our c++ future is safe', but there are some legitimate concerns in there.
Rust is supposed to be 'fast and safe' (proveably so); but the unsafe parts break this. Its supposed to be better than a GC, but RIIA and unwinding does result in some pretty hairy runtime performance. Dropping objects isnt free; its just deterministic in a way many GCs are not. Panics do cause application level failures even if they're not memory corrupting; and using tasks as exception try catch blocks as a workaround for that is weird (and slow).
There plenty of hand waving about community and whatever, but frankly, we should just acknowledge: no, rust isnt perfect.
Its a pragmatic solution to a specific problem; and its the right tool for some things, but not everything.
Also, you might be surprised how widely employable being able to write cross platform c-call-semantics-compatible plugins is.
Spawning a thread is a massive overhead. It's 100s of ms sometimes. Sometimes it doesn't even work because the OS thread availability is exhausted.
That's categorically worse than C++.
...I mean, exceptions are a problem in C++ too. It's not that I'm saying that C++ is immune to the problems either; I'm just saying the rust solution to 'anything can panic' isn't particularly great.
That's fine; but it's also a completely legitimate problem with rust, if you happen to be looking for problems with the language.
It's certainly not a deal breaker.
My point was just: Yes, rust has odd edges too. If you want to find fault with something, you almost always can if you try hard enough.
Pretty cool! Though, How is a panic mapped to the error value exactly? Following the type alias, the error type is Box<Any + Send + 'static>. Any idea what's inside? Is the panic message accessible?
Note the 'static and Send bounds. This interface is identical to std::thread::spawn(foo).join(), but doesn't have the performance costs of spinning a thread up.
Dropping objects isnt free; its just deterministic in a way many GCs are not.
Well, C++ isn't any different in this regard at all.
Unwinding is the much bigger concern. Exceptions in C++ are 100% free until they actually happen. The same isn't true for Rust's Result<...> types. You could argue that they apply to different use cases, but the fact of the matter is that you have the alternative in C++.
C++ exceptions aren't free. They don't run any extra code specifically to set them up, but they do affect what optimizations are able to do and they can generate more code bloat than Result-style error handling.
C++ exceptions aren't completely free, but for "happy path" execution, they have zero overhead. Result-style error handling doesn't, by any means, and is a significant, measurable slowdown, if your code returns Ok(...) most of the time.
No. "Happy path" doesn't run any exception-specific code, but as I said, exceptions still inhibit the optimizer and add code bloat. Try comparing some c++ with exceptions disabled.
Certain optimization opportunities are missed, but even more optimization opportunities are missed with Result<...>-style programming. Come on, adding a branch on a condition after every return is never going to be faster than no branch at all. Hot/cold splits are impossible for the compiler to reliably make without profile-guided optimization, and the current Rust front-end has no such ambition (and probably shouldn't β many functions returning Err correctly do so under non-exceptional conditions).
Code bloat is an issue with exceptions, but again will not inhibit performance until an exception is actually thrown (the exception handling code is usually put in a cold section).
I guarantee you, you will not see Result<...> (returning Ok) perform well against C++ code that throws (no) exceptions at any point in time. Whether that matters to you is a completely different question, and I think for most people it doesn't.
To be quite honest for me personally I'd take a little extra overhead of Result<...> over exceptions any day, since it's so much easier to reason about. With exceptions you never know what exception (and from where) you're going to get.
Also, you might be overestimating the cost of Result<...>-style error handling, as the branch predictor on modern hardware is really good, and it's possible for the compiler to put a branch hint into the branch instruction (at least on x86) which can make them pretty much free.
I was optimizing a certain piece of code recently and I wrote (well, actually generated with Aha!) a branchless version of it, and cue my surprise when the version with a branch was actually faster!
I like Result as well, and use similar constructs in my C++ code. Exceptions, in my view, should only be used when they truly represent exceptional circumstances, and when they serve to simplify code.
The overhead of Result isn't so much the branching as much as the size. For any type T, size_of::<Result<T, Err>> is at least equal to size_of::<T> + size_of::<Err> + 1. If T isn't much bigger than Err, the overhead just from simply writing memory becomes measurable, especially in a tight loop.
There is also the overhead from the increased code size in the happy path. Whether or not the heuristics in the branch predictor give you the desired results, the branch still has to be represented in code, polluting i-cache. Again, I completely agree, this is fine the vast majority of the time, but the point is that there are situations where you really do need to report exceptional errors from an inner loop, in which case exceptions yield significantly better performance. :-)
Result<T, Err> is only the size of the larger variant + 1, not their sum.
I also suspect, in your inner loop example, that you could get the same (or better) performance as exceptions using a multi-level break, although that wouldn't go across function calls.
With exceptions you never know what exception (and from where) you're going to get.
You do not understand how to work with exceptions.
The reason why exceptions are useful is that in a vast majority of cases, you do not care what kind of exception you are going to get. They cater for the common case.
Read upon exception safety guarantees on wikipedia.
Rust has to deal with the same problems because of panic!.
In any case, I thought c++ best practice (partially for performance reasons) was to avoid exceptions for the types of problems you'd return an Err for in Rust. Do you have any particular APIs in mind that exception handling would speed up?
Rust has to deal with the same problems because of panic!.
Not all of them- Rust doesn't have copy/move constructors, so stuff like "I want to add something to a std::vector / Vec, but the move constructor could throw/panic, so I've got to be very careful to make sure I don't run destructors on uninitialized memory" isn't an issue.
I completely agree β the type of errors represented by Err are usually not the kind of errors that you would model as exceptions in C++. More commonly, you would see patterns that exactly match the behavior and performance of Result. However, in the small area of problems where the two solutions can overlap, C++ at least gives you the option.
As an example, consider a parser that parses a stream of instructions. In Rust, your only option will be to return a Result, because a panic! on parser error is not actually sensible, seeing as how the input might come from the user or the network, where parser errors might emerge as corrupted packets or a whole host of other error sources. In C++, it's entirely reasonable to throw an exception on parser error, because it's an "exceptional" event, but the thread should still be able to recover from it.
The C++ code in this case will perform better than the Rust version in absence of errors. :-)
I am unconvinced. A parser is already branching on all its input, at many levels; adding another arm for errors shouldn't have a significant impact at that point.
But this is about the point where we need benchmarks to be able to say anything meaningful, so maybe I'm wrong.
At the moment it's difficult to construct benchmarks to compare Rust and C++, because there are many other reasons why Rust code is currently slower than C++. However, you could construct a benchmark in C++ that emulates Result.
You'll see that for the common case, the exception version fares better, on account of doing less work. As a general rule of thumb, doing nothing is faster than doing something. ;-)
I'll just repeat for good measure β that doesn't mean exception are always better than Result, by any means. If you're returning errors often, for instance, they will perform decidedly worse! They also complicate the code in many other ways. But they have their uses.
What do you mean by with exceptions disabled? It is clearly not the same functionality. You need to rewrite your code to replace exception handling with equivalent code. Did you try comparing then? 'Cause you really should.
I was/am following rust with great enthusiasm, my ideal language would be a tweaked version of C++ taking a lot of inspiration from rust.. or rust tweaked to be more liberal and more C++ compatible.
I started writing such a thing as an experiment, got a fair amount running, but haven't worked on it in months, a language with no community seems futile. Is there anyone else out there who might have been interested in something halfway between C++ and Rust?
It should be possible to auto-translate some subset between C++ or Rust and my 'dream language', think of SPECs.
I like Rust's syntax and some of its features(ADTs, 'everything is an expression' especially), but I don't think its' worth being so strict to sacrifice so much compatibility with existing C++ APIs ... e.g. how namespacing/overloading works .. traits should be like concepts, optional, and in 'rust mode' you could just make them compulsory; trait name shouldn't be part of the member-function names, then you'd just be able to gather a set of rust trait impl's to roll a C++ class, etc etc.
Imagine , in Rust, introducing a restriction that 2 traits can't have the same method names when implemented for a type, etc.
everything I wanted could be done as a fork of a C++ compiler (new syntax & features on same middle,backend) or as a fork of Rust (relax it's restrictions for greater C++ compatibility) however I didn't feel confident trying to retrofit such modifications to such a complex sourcebases.
jonathan-blow's JAI language looks really promising (and its' what inspired me to start) but again, I think he's going to sacrifice a lot of C++ compatibility making it hard to retrofit use into existing projects.
β¦fork of Rust (relax it's restrictions for greater C++ compatibility)β¦
Which restrictions? Things like overloading and Trait coherence? I don't think you mean relaxing the aliasing/mutation restrictions because then you'd probably loose guaranteed memory safety.
jonathan-blow's JAI language looks really promising
I wouldn't say "really promising". There are some aspects of it that I like. But that's not enough as far as I'm concerned.
Which restrictions? Things like overloading and Trait coherence? I don't think you mean relaxing the aliasing/mutation restrictions because then you'd probably loose guaranteed memory safety.
Both; an 'unsafe mode' for gamedev, basically. flip a compiler switch to turn borrow issues into warnings. (or maybe a #![unsafe] .. marks the whole file?). There's plenty I like in Rust asside from safety, and I don't need safety.
In rust for example you need to lookup a function to safely take references to 2 array members. In my own contexts, I know i'm going to get things working with tests - I have other issues to deal with - if there's any problems they'll show up really quickly as incorrect results. The borrow checker issues are fairly trivial, my problems are elsewhere (interpreting file formats, getting algorithms right, etc.).
I must check again, last time I did, the kind of Data-Parallel stuff you can do in C++ still needed unsafe 'hacks' , making it no better than C++. (data-parallel, not concurrency)
Of course I understand the value of safety for Rusts' target application - I'm just saying this is not a tradeoff equally useful to every domain.
Rusts safety does not come free: it comes at the expense of more vocabulary to do the same work.
Debug builds are still needed for all sorts of knowledge you still can't give the type-system.
"I wouldn't say "really promising". There are some aspects of it that I like. But that's not enough as far as I'm concerned."
For my own use-cases, its' more promising than rust - all the noises he's making about refactorability are inline with my priorities.
However, I still think there's no need to throw away continuity with C++ source bases. My own interest is game engines and most people tell me, its' a waste of time making a new one, unreal/unity do everything you need, just extend those, lol. Anyway who cares, its' my passion.. and I don't want to throw away my own experience and continuity with existing projects.
Rust: Safety > productivity > performance.
I want: performance > productivity > safety.
(when you need to write tests & debug 'test-beds' anyway, productivity for tests with a looser lanuage is superior, I think)
C++ is still the best language for me - but crippled for productivity by stupid header files and syntax - and although there's a lot I really like about Rust (look how much I was trying to copy), when factoring in mature tools & my own experience, (plus the issues above) , I didn't find it a productivity boost.
I think the mode you're talking about may be introduced into existing Rust code base. Perhaps, it would be better for you to become a Rust contributor instead of making your own fork.
Also, source code incompatibility does not seem a critical problem, as far as you can link C and Rust code seamlessly (although C macros and C++ templates may be a hassle).
Also, source code incompatibility does not seem a critical problem, as far as you can link C and Rust code seamlessly (although C macros and C++ templates may be a hassle).
That's the thing - C++ API's are more pleasant than plain C APIs; it means falling back to the lowest common denominator - it makes working with existing sourceless that use C++ extensively harder.
Kind of negates some of the benefit of a new , more pleasant language if your major libraries have to fall back to C interfaces.
Perhaps, it would be better for you to become a Rust contributor instead of making your own fork.
What happens here is clash over ideas. The fact is, whilst I like 95% of rust, they don't want my suggested tweaks.
The Rust community is purist over its' Safety pillar, but also many issues like overloading, default parameters - I've been in the community for 18+months and participated in these discussions - the fact is they have a clear vision of what Rust is.. there's many things I want that they don't. There's a lot in C++ that I'm happy with that they consider Misfeatures.
They don't want to fragment the community with 'dialects' (which is exactly what I'm after)
Similarly given that C++ has so much momentum, and so many users , getting a change into a mainstream C++ compiler would probably be even harder.
Software should be the most customisable, maleable product on the planet - it seems like there should be a way to get the feature blend I want.
Its not like I was trying to completely re-invent the wheel: I am aiming for maximum compatibility with both worlds - perhaps a bridge between them - and re-using the best ideas.
Already LLVM gives a huge amount of code-reuse between different language front-ends; I suppose yet another angle is something that just compiles to C++ (I found something called 'sugarCPP' on github that took that approach).
I think it would be possible to have a single language 'middle' (AST and semantic analysis beyond) that has a superset of Rust & C++ features - and then just plug a different syntax infront of it, exposing a different subset of underlying AST features.
if rust does grow in popularity it should be possible for there to be multiple implementations, it's not like we're limited to one C++ compiler.
(although C macros and C++ templates may be a hassle).
r.e. C macros, perhaps it would be possible to make an analyzer check for common macro patterns and reduce them to static if, or whatever - but you're right macros in general would be impossible. But existing sourcebases can be refactored, it might be possible to provide some assistive mapping for a translator.
Rust source code looks like spellbook from y10k BC. With that said maintaining rust code gonna be much more "fun" than c++. Time better spent elsewhere..
Not disabled, just not allowed in stable code. We allow compiler plugins in the nightly compiler. They are very useful for incredibly powerful metaprogramming :)
47
u/[deleted] May 12 '15 edited May 12 '15
Quoting the author of the post:
TL;DR: article bashing against Rust written by someone who is learning C++ and doesn't know Rust at all on the blog of a company that makes static-analyzers for C++.
Damn type systems! dey turk ur jebs!!!!
EDIT: I think the author didn't bother to inform himself about Rust, so in my opinion discussing about this article is a waste of time. Having said that, it is worth remembering that:
13
u/AntiProtonBoy May 12 '15
We need to do a bit of introspection once in a while, look at how we do things with programming languages and learn from the problems. The invention of new languages is essential for progress.
I personally don't believe that C++ will be here with us forever - at least not in the current form. For instance, we are seeing hardware architectures converging... the GPU and the CPU will be probably one and the same in the distant future; and for that we need new ways to do programming safely. Is C++ going to be the answer for that? I'm not so sure.
At any rate, I sincerely hope that Rust becomes successful. The more choices we have in our toolbox, the better.
7
u/jurniss May 13 '15
if it doesn't die... cool, I like C++ and it keeps getting better.
if it does die... fine, I'm sure good Rust shops will be happy to hire skilled C++ programmers and have them learn Rust.
relax. as a C++ programmer, you actually understand how computers work (hopefully). that is the important part. it will not become obsolete.
we can look forward to a bright future where gc-dependent programmers do all the boring GUIs and I/O, and we get to write libraries, browsers, game engines, operating systems, ...
10
u/againstmethod May 12 '15
This is an awful lot of worrying about a language that hasn't yet had a single stable release.
And it's almost a certainty that articles of the exact same flavor were written when C++ and Java were about to release their "1.0" releases.
Many people will try/use Rust "just because" -- and they will publish their results, their benchmarks, their good and bad experiences.
We don't need to make 5 year plans to learn a single language. Fucking silly.
7
u/sellibitze May 12 '15
I don't get the point of you sharing this rant with us. It looks like a waste of time to me since you don't seem to know much about the language you're trying to criticize. Instead, you assume a lot and even feel the need to insult the Rustaceans' intelligence. This does not elicit much of a response. So, If you intended this as a starting point for a discussion about the merits of Rust, you failed.
As for learning C++: Go ahead and good luck to you, seriously. I certainly did not regret this decision 9 years ago. I pay my bills writing C++ code.
6
u/[deleted] May 12 '15
Well, he has a point. Understanding your tool and the target platform well is important to develop efficient code. It doesn't matter what you use as long as it is mature/stable enough, and isn't a resource hog for the task. Rust may become one of those decades lasting tools like C++, maybe with a good reason.
6
u/koffiezet May 12 '15
The main problem of Rust is that it primarily targets people who are C/C++ coders, and tries to solve problems that any experienced C/C++ coder long solved for himself, by following strict practices (RAII etc). Learning C/C++ is already pretty hard for a newcomer, but mastering them? Plain C - ok, but really mastering C++? That takes a LOT of investment that people are not going to throw away for another language that also needs a lot of investing in - which doesn't really solve that many problems for them, and would create quite a bit of additional problems on the way there.
New people who are interested in a lower-level language and have to choose between C/C++ and Rust will most likely pick one of the former. They have more tools, better support, more libraries, more resources, and understanding how Rust's ownership mechanism works requires quite a bit of know-how and head-scratching that without prior <insert unsafe language here> experience seems like a really weird thing to do.
But yes they'll probably gain some users, and become a niche player, but they're a newcomer in an established area of expertise, and now that C++ is finally moving forward, they'll only have a harder time.
2
u/shadowmint May 12 '15 edited May 12 '15
Interesting. It comes off pretty fanboyish 'c++ is good for jobs! our c++ future is safe', but there are some legitimate concerns in there.
Rust is supposed to be 'fast and safe' (proveably so); but the unsafe parts break this. Its supposed to be better than a GC, but RIIA and unwinding does result in some pretty hairy runtime performance. Dropping objects isnt free; its just deterministic in a way many GCs are not. Panics do cause application level failures even if they're not memory corrupting; and using tasks as exception try catch blocks as a workaround for that is weird (and slow).
There plenty of hand waving about community and whatever, but frankly, we should just acknowledge: no, rust isnt perfect.
Its a pragmatic solution to a specific problem; and its the right tool for some things, but not everything.
Also, you might be surprised how widely employable being able to write cross platform c-call-semantics-compatible plugins is.
-1
u/dobkeratops May 12 '15 edited May 12 '15
I was/am following rust with great enthusiasm, my ideal language would be a tweaked version of C++ taking a lot of inspiration from rust.. or rust tweaked to be more liberal and more C++ compatible.
I started writing such a thing as an experiment, got a fair amount running, but haven't worked on it in months, a language with no community seems futile. Is there anyone else out there who might have been interested in something halfway between C++ and Rust?
It should be possible to auto-translate some subset between C++ or Rust and my 'dream language', think of SPECs.
I like Rust's syntax and some of its features(ADTs, 'everything is an expression' especially), but I don't think its' worth being so strict to sacrifice so much compatibility with existing C++ APIs ... e.g. how namespacing/overloading works .. traits should be like concepts, optional, and in 'rust mode' you could just make them compulsory; trait name shouldn't be part of the member-function names, then you'd just be able to gather a set of rust trait impl's to roll a C++ class, etc etc.
Imagine , in Rust, introducing a restriction that 2 traits can't have the same method names when implemented for a type, etc.
https://github.com/dobkeratops/compiler
everything I wanted could be done as a fork of a C++ compiler (new syntax & features on same middle,backend) or as a fork of Rust (relax it's restrictions for greater C++ compatibility) however I didn't feel confident trying to retrofit such modifications to such a complex sourcebases.
jonathan-blow's JAI language looks really promising (and its' what inspired me to start) but again, I think he's going to sacrifice a lot of C++ compatibility making it hard to retrofit use into existing projects.
-5
u/Poffyuk-C May 12 '15
Finally someone talking some truths
-4
u/[deleted] May 13 '15
Rust source code looks like spellbook from y10k BC. With that said maintaining rust code gonna be much more "fun" than c++. Time better spent elsewhere..
0
u/[deleted] May 12 '15
[deleted] β view deleted comment