8 ms·
I've done my share of C++ and now Rust, and I don't really get why people keep saying that Rust is a 'cleaned-up C++'. In my opinion this couldn't be further fr
by jgilias 6y ago
I've done my share of C++ and now Rust, and I don't really get why people keep saying that Rust is a 'cleaned-up C++'. In my opinion this couldn't be further from my subjective truth. I see C++ as an effort to extend C to enable object oriented programming patterns. And everything else being added to it as more and more people have come to appreciate patterns from other programming paradigms. But fundamentally C++ to me is still 'C with classes'.
Whereas Rust, to me at least, is 'ML-ish with curly braces'. So, a language firmly based in the ML heritage with C-like syntax. So, fundamentally working with types and 'typeclasses' and heavily leaning towards filter/map/fold/reduce/lift/unlift type of thinking. Sure, throwing funtions around as first class objects are not as easy or straightforward as it is in 'real FP' languages, but that's a trade-off I'm willing to take for the guarantees that Rust provides.
I'm genuinely curious what's the reasoning behind being able to assert that 'Rust is a cleaned-up C++'.
- pron 6y agoYou're doing the comparison from the bottom-up, perhaps like how a programming language connoisseur would look at them -- how the linguistic features of C++ and Rust were constructed -- while I'm looking at them from the top down, how just a programmer who doesn't particularly care about PL theory would: what is their design philosophy? Both are low-level languages (so, low-abstraction), which try hard through various syntactical techniques and a nice dose of implicitness to make code, once written, appear high-level on the page. I find those two languages almost indistinguishable in terms of "feel." It doesn't feel like Python, it doesn't feel like Java or Go, and it doesn't feel like C; it feels like C++.
- jgilias 6y agoI do agree that Rust 'feels' more like C++ than Python or Java. But then, from my limited experience with dabbling into Haskell, to me it feels more like Haskell than C++. In Rust, from the language perspective, I have to deal with things like these: - Doing Option<T> -> Option<U> - At what point do I do Option<T> -> Result<T> - Should I transpose Vec<Option<T>> to Option<Vec<T>> now or later? - Often reaching for algebraic data types - How to map over this to collect it into what I need - Ah, it needs to implement Hash, Eq, PartialEq ... SomeTrait to make it work the way I want - Pattern matching all over the place All of which to me mentally feels more like something along the lines of F#, OCaml or Haskell than C++ that 'normal people write'.
- golergka 6y agoBecause people know C++ but don't know ML.
- pjmlp 6y agoDepends on the people. When I did my degree, C++ was taught in the second year and Caml Light in the third.
- TinkersW 6y agoHave you not seen much modern C++? If you are used to this style of C++, Rust is a very obvious variant of it, but with more static guarantees with regards to safety. Working heavily with types has been common in C++ for a couple decades now, and there are libraries with bring in filter/map/fold/reduce/lift/unlift style.
- jgilias 6y agoThe code I've had to work with was definitely more on the OOP paradigm side. Can you provide an example project with a more 'modern' C++ code base that I could check out?
- floatboth 6y agoRust is rather more like "Haskell-ish C++". (Typeclasses were popularized by Haskell and are not available in SML or OCaml.) While the C++ heritage is obviously the memory management – no runtime, heavy use of scope based deterministic destruction ("RAII"). Also the compile-time metaprogramming that gets monomorphized. (All those template/generic instantiations that can bloat the binaries if overused :D)
- jgilias 6y agoI've been bashed before for saying something along the lines of "Haskell-ish C++". Their fair point being that the only Haskell influence is the typeclasses, and all other ML-influences are just ML-influences that are not unique to Haskell. Fair enough :)
- Zababa 6y agoFor reference, here's the "influences" page of the Rust reference: https://doc.rust-lang.org/reference/influences.html https://doc.rust-lang.org/reference/influences.html SML, OCaml, C++ and Haskell are all mentionned.
- carapace 6y agoIt's like C++ is a gas-powered chainsaw and Rust is a newfangled electric "smart" chainsaw.
- steveklabnik 6y agoI often use "table saw" when making this sort of analogy, because there's even a more direct comparison: https://www.sawstop.com/ https://www.sawstop.com/
- carapace 6y ago(As an aside, WOW! What a great invention! The folks who sent in pictures of their tiny cuts (instead of severed fingers) nearly made me cry.) That's a brilliant metaphor to drive home the safety advantages of Rust! "It's a table saw that won't chop off your fingers!" That's a "shut up and take my money" proposition. (And it helps that it's a really good table saw too.) (As another aside, I got to the testimonial from an employer talking about the peace of mind of knowing the workers on the shop floor are safe and it "clicked" for me: you've got metrics and liability for job site safety so you can quantify that peace of mind. We still not there with software quality liability eh?)
- wealthyyy 6y agoReminds me that unprofitable hotness electric car company whose core business is to manipulate both balance sheet and government.