11 ms·
Pretty much that. Safety gimmick aside, Rust is (mostly) what C++ would have been if designed with modern knowledge of programming languages theory and compiler
by ribit 5y ago
Pretty much that. Safety gimmick aside, Rust is (mostly) what C++ would have been if designed with modern knowledge of programming languages theory and compiler practice in mind. It’s not like Rust brings that much novel things to the table, it is has its roots in ML and friends that have been around for decades. It’s just that we didn’t know how to make ML-type languages fast in the 80-ties. So C++ designers did the best they could given the time period and the circumstances.
- nu11ptr 5y agoAre there other languages with compile time GC prior to Rust? I thought that was a pretty novel feature. I recall an ML variant with region inference, but that was just an optimization I believe for it's runtime GC. Edit: MLKit was the ML dialect I was thinking of - looked it up
- lmkg 5y agoNothing that has hit the mainstream like Rust. To my knowledge, Rust's lifetimes take influence from a language called Cyclone.
- nu11ptr 5y agoCyclone I believe (has been a while) used region based inference like MLKit I mentioned. I'm not sure off hand if Cyclone was influenced by MLKit or the other way around. Cool tech, but Rust took it to the next level by making it pure compile time.
- ribit 5y agoWhat exactly do you mean by compile time GC? Various techniques like compiler-optimized GC have been around for a while. If you are looking for mainstream stuff, Apple’s automatic reference counting for Objective C comes to mind (has been shipping since around 2009)
- nu11ptr 5y agoI mean that Rust knows exactly when something will be deallocated at compile time due to its lifetime system (for things that are single ownership, Rc/Arc excluded). In contrast, ARC does compiler assisted increments/decrements if I recall, but still uses runtime ref count to know if something needs deallocation.
- ionicgiraffe 5y agoC++ programmers where selectively implementing borrow checkers at runtime decades ago (see library omnetpp as an example). Moving those borrow checkers to compile time with templating is possible (but people did not do it because the borrow checking could be disabled after testing and no overhead would be paid neither at runtime nor compile time). That Rust implements borrow checking as pillar of the language I think it is great.
- ribit 5y agoAh, I see. True, Rust has a more restricted model that allows it to track lifetimes more precisely. As far as I know, Clang will omit reference counting if it can be statically determined but of course it has fewer optimization opportunities here. In the end, the two approaches are not entirely dissimilar: ARC uses static analysis to detect dependencies and will fallback to dynamic RC n complex scenarios; while Rust enforces certain rules that only allow most basic dependencies and requires the user to mark these by using dedicated tools.
- rurban 5y agoPony has some references how they came to it before Rust. Easily doable with escape analysis. Just that pony added a proper GC protocol for it's threaded actors and proper concurrency safety by avoiding blocking IO. More important is tracking the owner, which perl6 used.
- bcrosby95 5y agoSo ignoring the main point of Rust, it's (mostly) what C++ would have been... You could do this with basically any language advancement. Ignoring classes, C++ was (mostly) what C... Ignoring GC, Java was (mostly) what C++... Also, a language is more than the sum of its parts. If it weren't, kitchen sink languages would be the best ones out there, because they have the most parts.
- ParetoOptimal 5y ago> Also, a language is more than the sum of its parts. If it weren't, kitchen sink languages would be the best ones out there, because they have the most parts. I've been hugely interested in this recently, at least part of what you are describing is programming language affordances.
- unfocussed_mike 5y ago> So ignoring the main point of Rust, it's (mostly) what C++ would have been... "And the sanitation" "Oh, yeah, the sanitation, Reg. Remember what the city used to be like?"
- shepherdjerred 5y agoYeah. All right. I’ll grant you the aqueduct and the sanitation are two things that the Romans have done.
- unfocussed_mike 5y agoI am so glad someone got where I was going with that!
- throwaway894345 5y agoI think Go has done a lot in the last 10 years to facilitate a mindset shift in our industry to "less is more". For a long time, Go was (and probably still is) ridiculed for eschewing many of the features that programming language practitioners have dreamt up over the last several decades, but as more people have tried the language in earnest they have to grapple with the fact that there are some advantages to not having to grok an enormous feature matrix even if they disagree with Go's specific feature set. The conversation has advanced beyond the "if you don't like a feature just don't use it" justification for kitchen sink languages.
- adamnemecek 5y ago> Safety gimmick aside Safety is a gimmick?
- stonemetal12 5y agoTo be fair C++ is backwards compatible with C. That meant there was a large amount of design space they couldn't explore. Rust not going there gave them the ability to do better.
- tialaramex 5y agoThat intent to be "backwards compatible with C" doesn't stretch so far as to say, provide any way to spell valid symbols from C. Imagine you have some C that has (for whatever reason) named two important functions "class" and "fn" which are completely reasonable C symbol names. In C++ that word "class" is reserved, so you can't name symbols class, but, that is what the C symbol's name is so too bad? However in Rust, even though fn is a reserved word there's no problem referring to that symbol, you just have to spell it r#fn meaning "the symbol named fn" as distinct from the keyword fn.
- rwaksmunski 5y agoC++ is no longer backwards compatible with modern C.
- kazinator 5y agoC++ compatibility has improved. E.g. I've noticed that C++20 has designated initializers for struct members, which were introduced in C99. So now if you're writing C that has to compile as C++, you can use C99 designated initializers, if you're OK with requiring C++20.
- pjmlp 5y agoLike Ada in 1983, or Modula-3 in 1990's, but I digress.
- sophacles 5y agoSafety is what brings me to the table. I'm not a genius, I'm not a 10^Nx coder. I'm a guy who wants to make neat things. I've been doing this programming thing for a while and have had my forays into C and C++. I've spend a lot of time in python and go too. The thing I like about rust is that it gives me the level of control C and C++ do without all the mental overhead of remembering "is this for reading, writing, both? none of the above?" for each and every pointer and variable. It's written down in the type signature and then the compiler verifies that for me. That saves me time and energy - time because I don't have to wait for my misunderstanding to manifest weeks or months later at runtime (in a worst case) and energy because my editor will fill show me signature information inline - I can just glance up a few lines if I need to remind myself of what the constraints of a variable are. I know for a fact that I don't strictly need this - I am capable of writing C that preserves those contracts, at least for smallish projects. It just takes much more time and effort. And in big projects even the "gods" have trouble with getting it right every time. In fact, I've been willing to tackle much more difficult problems professionally that I would have shied away from (outside a research setting anyway) without the guarantees rust tooling provides. The whole "safety is a gimmick" angle always brings to mind a bunch of 9-fingered carpenters sitting around trying to convince their boss not to buy saw-stop because you just gotta be careful using the tablesaw.
- kazinator 5y agoIf you're capable of writing C that gets things right, even if in just smallish projects, chances are good you could crank out bullet-proof C++98.
- kazinator 5y agoThe initial C++ designers produced a language which was still very understandable, and in which you could easily write bullet-proof programs. In C++98 (the first ISO standard version of C++) you can fairly easily organize a program such that any low-level activities are confined to classes that are almost impervious to misuse by the rest of the application, so there will be no memory misuse or leaks, or out of bounds arithmetic. If Rust takes off, there will be widespread use of its unsafe parts by programmers who are under pressure to deliver something and take the obvious route of telling the machine where to put what bits, exactly like what C++ programmers have been doing.
- dataangel 5y agoBut tools like cargo geiger will tell you exactly where the unsafe parts are so you can progressively remove them. Also safety is usually terser in Rust, so programmer laziness usually leads to safe code.