5 ms·
I think Rust will teach you out of the box a lot more about concepts of ownership and lifetime, i know i learned a lot from Rust.
by lossolo 11y ago
I think Rust will teach you out of the box a lot more about concepts of ownership and lifetime, i know i learned a lot from Rust.
- nostrademons 11y agoI found learning Rust to be a lot easier having learned C++11 first. Move semantics, RAII, borrowing (const references), mutable borrowing (references), option-types (pointers), and iterators are all C++ concepts. The big advantage Rust gives you is that the compiler handles a number of things that required manual bookkeeping or coding conventions in C++, and doesn't let you screw them up.
- pcwalton 11y agoBut you could equally say that all those C++ concepts are really Rust concepts. So I don't see how that's an argument that C++ is easier to learn than Rust. The strict checking seems to me to be a win, because the compiler tells you what you did wrong instead of having to debug undefined behavior (e.g. dereference after move of unique ptr).
- nostrademons 11y agoI'm not arguing that C++ is easier to learn than Rust (I actually believe the opposite). I'm arguing that learning C++ helps with learning Rust. If it were a completely green-field environment, I'd much rather write in Rust than in C++. (But then, in a completely green-field environment, I'd much rather write in a language suitable for prototyping like Python or Javascript than Rust, and then port it over to Rust when I have an idea what the shape of the problem is.) We don't exist in a completely green-field environment. The main advantage of C++ is that you can look at any number of open-source databases, GUI frameworks, servers, compilers, browser engines, and libraries and see how they chose to design their object models and ownership systems.
- bluejekyll 11y ago> suitable for prototyping like Python or Javascript than Rust, and then port it over to Rust In all my years, every time someone prototypes, it either never gets used, or it does, its successful and then it never gets rewritten because there's no time for technical debt. Now I prototype in the language I plan to use long term, but what that means is stubbing out sections, or putting in todos if there are spots that can be better. The prototype should be able to scale into your real application, otherwise your just building something that will haunt you.
- nostrademons 11y agoA prototype is supposed to never get used. The point is to learn - to explore the territory so you have an idea of what's a good idea and what's a bad when you start implementing the real thing. I just threw out a prototype last week, and started on implementation for real. I was able to cut about 70% of the features, throw out a couple third-party libraries and bleeding-edge language features that turned out to be more trouble than they're worth, identify 2 areas that really needed to be firmed up and made more robust before they'll support a "real" system (and have about 20 concrete examples of the first and 80 of the second, so I can design the features with actual data), and revise the API 4 times, for 5 weeks of work. It helps that I'm both CEO and only developer and so have the political clout to do this. And I'm under no illusions that this is the "final" revision - I'm doing this incarnation with somewhat more robust development practices, but I still expect I'll have to throw it out in a year or two. But it certainly beats doing those 4 revisions over a year (with a 7-person team) and then going out of business, as happened in a startup I'd previously worked at.
- jholman 11y agoIt's a lot cheaper buying a macbook if you can get a 20% off credit, which you can get by buying a new porsche. Spend $100k, save several hundred dollars! Saying that learning C++ helps with learning Rust is almost certainly true in a banal way. Learning any N languages will make the incremental cost of learning language N+1 a little lower, even if those languages are not closely related. Are you actually claiming that, if you knew someone who knew, say, Python and JS, but no statically compiled unmanaged language, and that person needed to know Rust by 2017, that your advice would be to spend the first several months learning C++? I find this implausible. C++ is a baroque language with way too many conflicting features, conflicting cultural standards, and general all-around cruft. Isn't it? Disclaimer: I know so little C++ that we should assume that I don't know it, and I haven't written any Rust yet.
- AstralStorm 11y agoSadly, it won't teach you what happens if you fail to consider something. This means, long hours of tracing, debugging, leak checks etc. The lesson is: never ever rely on compiler, framework, language or other potentially buggy tools to think for you. Even with Rust's "hard" approach, you can get complacent and hemorrhage performance and memory until there's no turning back. Those things were written by fallible people without hard mathematical proof everywhere, after all. Rust and especially its libraries too. Understand libraries, their implementation and design trade-offs if you're using them.
- lossolo 11y agoInteresting, could you give some example of such Rust code?
- pcwalton 11y ago> This means, long hours of tracing, debugging, leak checks etc. But you don't have undefined behavior to debug, and that makes debugging easier. Trying to reverse engineer from a corrupted memory dump from a production system what the compiler did to your code and relate that back to where it went wrong is something you will have to do in C++, given enough time. You don't have to do that in Rust.