4 ms·
want to write fast rust? write your code in C or C++
by b20000 3y ago
want to write fast rust? write your code in C or C++
- deleted 3y ago[deleted]
- lionkor 3y agoyou're getting downvoted because you said it in a weird way, but fundamentally I have to agree. Both C and C++, if written idiomatically, have less syntactic sugar and macros are less accepted, so that their code ends up hiding a lot less complexity than rust code. Fairly complex code like what the author showed turns out to use a bunch of different random things nobody expected.
- b20000 3y agoyep, i agree. most pro rust arguments are from a safety perspective or that rust does a lot for you. the problem is that in a lot of applications nobody cares about safety or security. it is just that devs operate in evironments where that matters and they think therefore it matters everywhere all the time. when a language does something for you you then typically don’t learn what it actually does under the hood which will come back to bite you later. i have some of that problem with the latest C++ features as well, btw, which is why my C++ tends to look like C with classes and here and there use of a modern feature.
- hyperman1 3y agoI disagree. There was an article somewhere about servo, mentioning advantages of rust vs C++ . One example was how less intermediate copies were made, as rust made it clear what data was immutable. Another was how rust made threading more easy, as it was more clear what data needed locks. Rust safety on the small scale is an enabler for stability in the large scale, giving the possibility to take more risky optimizations. This is exactly where C and C++ fall flat. You can write small scale stable software with them, but multy decade multi team 1000k+ lines of software turns in a CVE fest. A lot more effort in documenting interface details and validation need to be done,because the compiler can't do it for you
- lionkor 3y agoImplicit copy in C++ is a horrible thing, but very consistent. You learn once that anything that doesnt fit in a register should be passed by (const) reference, and always delete your copy ctors by default, and that does a lot for you.
- IshKebab 3y ago> code ends up hiding a lot less complexity than rust code Are you really saying this about C++? For real? I quite like C++ but the idea that it doesn't hide complexity is hilarious. Something as simple as `a = b` can call constructors, copy constructors, assignment constructors, move constructors (depending on a lot of details), do implicit type conversion, throw exceptions, etc. etc. In Rust it's just memcpy. Maybe you're thinking of proc macros which can do a lot more than in C++, but they're just a more convenient way of doing codegen which you can equally do in C++ (e.g. to generate Protobuf code).
- lionkor 3y agoC++ hides complexity, yeah, but arguably Rust should have learned from that, no? Instead, Rust opted to do as much syntactic sugar as possible.
- IshKebab 3y ago> Rust opted to do as much syntactic sugar as possible. Of all the criticisms of Rust, this is really the weirdest. What syntactic sugar do you find objectionable in Rust? It has almost none. Are you talking about macros?