3 ms·
For most software I would agree with you. Usually you have some CRUD application where people don't know how to index and use hashing. But the Rust compiler is
by carlmr 7y ago
For most software I would agree with you. Usually you have some CRUD application where people don't know how to index and use hashing.
But the Rust compiler is an amazing static analyzer. Running one on C++ to get the same level of memory safety will often take hours on sizeable projects.
- blub 7y agoA static analyzer which requires correct code to be rewritten in a certain way to satisfy the analyzer does not deserve to be called amazing.
- oblio 7y agoDon't all static analyzers do that? Or they're just ignored, which happened in almost every large project I've ever seen.
- carlmr 7y agoExactly. C++ code has so much variability that 90% of static analyzer warnings are worthless. So people ignore them and create terrible unsafe code.
- blub 7y agoMy comment had nothing to do with C++ or any other particular language, you're using it as a red herring to divert attention from the fact that the Rust analyzer requires changing the way you write code, making it not awesome, but ordinary. And speaking of C++, it's obvious that Rust programmers take a very adversarial stance towards C++, but you should be instead thankful that it exists, because without it many of those marketing articles would lose their meaning. "Slow compiler is now less slow, but probably still slower than those of other languages you know" doesn't quite have the same effect.
- carlmr 7y agoC++ is the obvious benchmark language because it's widespread and has the same benefits (manual memory management, native, high control). High reliability, static checked any language requires you to write code a certain way. C++ is just the most prominent and meaningful example here. ADA would be another good comparison, but I haven't worked with it on large projects so I can't say much about compile speed. It has a lot of similarities in being a safer C++. It felt similarly restrictive to Rust though. I think the fact of the matter is that it you want safety you need some kind of restrictions and your compiler needs to do some extra work (ADA and Rust) or you need to look at the whole toolchain that o of necessary to achieve safety (in C++ this is very long if you run your tests with Static analyzers, ASan and Msan, too which remove some of the bugs Rust tells you about).
- nn3 7y agoYes that's true. Coverity and similar are even slower. But then rust errors out on a lot of things the C++ analyzer wouldn't, a lot of those things are actually being reasonable code. For example I discovered recently that you cannot swap two pointer variables in rust without using unsafe. Surely there is some deep reason for that, that is really important until they can figure out how to fix it in some future Rust version, which they undoubtedly will. It's not that swapping is an obscure operation, many important and fundamental algorithms depend on it. I'm probably overly cynical there, but I sometimes feel that all these arbitrary restrictions that make code hard to write make people feel better about rust because if they get their code to actually compile it's a sense of achievement that makes them proud. Kind of like a journey to find yourself or something like that. But then i see that there is actually some progress in Rust to relax some of these restrictions (e.g. non lexical lifetimes in the borrow checker). If my theory above is true that would actually lower Rust's popularity over time. True? Probably not. But it's an interesting thought.
- carlmr 7y ago>For example I discovered recently that you cannot swap two pointer variables in rust without using unsafe. Surely there is some deep reason for that, that is really important until they can figure out how to fix it in some future Rust version, which they undoubtedly will. Wouldn't this work? https://doc.rust-lang.org/std/mem/fn.swap.html https://doc.rust-lang.org/std/mem/fn.swap.html >But then i see that there is actually some progress in Rust to relax some of these restrictions (e.g. non lexical lifetimes in the borrow checker). If my theory above is true that would actually lower Rust's popularity over time. True? Probably not. But it's an interesting thought. I'm not sure. Sometimes these restrictions are there, because it's too difficult to decide what should happen. I don't think it's malevolence on the language creators side. And I do think usability is always better. I find that I'm running into way fewer such situations now than last year though, so I think a lot is happening here.
- commit 7y ago>Wouldn't this work? https://doc.rust-lang.org/std/mem/fn.swap.html https://doc.rust-lang.org/std/mem/fn.swap.html If you click the [src] link on that page, you'll see that the implementation of std::mem::swap uses unsafe. I'm no Rust expert, but I'm also not aware of a way to swap pointers without unsafe.