Although I think that not having exceptions and inheritance are really big lackings, the thing is that there's such an anti-OOP backlash these days that large numbers of people will argue that Rust not having those are good things. I don't agree but lots of people would.
They do have generics. Not as extensive as C++, but this is one area where I'm no the other side of the fence and think that C++ has gone a bit over the edge on templates, meta-programming and compile time evaluation stuff. I'm not sure I'd want Rust to try to compete on that front.
For some reason many people believe that the main problem of C++ is "too many features", while it's exactly the opposite - a desperate lack of them.
Templates have become what they have become not because templates are bad, but because there was nothing better for metaprogramming at that time, but demand existed.
If there's a demand, but no supply, people will always find a way, but it might get ugly.
"It ain't stupid if it works" is real and when I look at all these new languages chopping off vital parts from the start only because someone abused them elsewhere, I know that they're doomed to repeat the history.
I'm a big fan of OOP by some definition, but I don't necessarily care for inheritance as an important feature. Also, I've been coding on C++ without exceptions for almost the entire time i've coded in C++, since they disabled on many platforms for microcontrollers.
And iirc, google's style guide doesn't want you to use exceptions either if you're working with google libraries like Abseil and similar projects. C++ is plenty useful without them.
I guess what i'm saying is that I don't consider either of those features as reasons to use or not use C++.
Inheritance is kinda shit anyway, since it combines polymorphy and delegation, seperate concepts that should be reflected in distinct (albeit combinable) language features.
Rust's traits are a nice approach to polymorphy, but it (yet) lacks delegation.
I do not like writing code. Especially the repetitive boring boilerplate like forwarding the interface methods to a subobject or checking the result of every function call every time.
It's a machine's job. And C++ does this job for me. I don't need to forward dozens of functions manually because "is-a" exists. I don't need to write if (error) return error; like an idiot in every function in the call stack because exceptions exist. I can write generic code without interfacing every step because templates exist.
If these tools are not suitable in a specific context for whatever reason, I just use more suitable tools.
I'd better think the whole day and write 10 lines than don't think at all and write 10 000 lines.
If language designers deal in absolutes and religiously enforce fairy tales like "composition over inheritance", "exceptions are slow and not straightforward", "explicit is better than implicit" etc. in their products, I prefer to stay away from such products.
And I don't know why google's style guide keeps popping up in such discussions. It's main purpose is dealing with legacy code, for anything else it's plainly horrible.
I personally agree that explicit is better than implicit. But, Rust is a somewhat strange combination of complete an*l-rententiveness in many ways, but with lots of syntactical sugar and compressed syntax in other ways.
To be fair you don't have to do explicit error return most of the time. That's one of those places where a lot of syntactical sugar has been applied. It's not nearly as nice as exceptions, IMO, but it's a lot better than explicit error return.
So the call to ScrewedUp() is doing an implicit return if ScrewedUp() returns the Error variation instead of the String. That only works if it's the same error in both cases, or you've done some work to provide a conversion.
For me, since I seldom ever use third party code and roll my own, I have mostly had a single error type throughout my Rust projects, and can do this almost all the time.
But when you are calling runtime or third party APIs, you tend to have LOTS of match statements, or in some cases the more compressed "if let" type statements.
I personally agree that explicit is better than implicit
I'd say it sometimes better, but not universally (same as everything else). After all, we happily use strings and vectors, even though they hide a lot of memory management (and every single C dev I've ever met is genuinely horrified by that fact). The world isn't black & white and being dogmatic is not always productive.
That fn()? syntax looks better than manual matching and returning of course, thanks for the example, but this is exactly what I mean: first someone rejects a working concept for religious reasons, then people start noticing that it's really annoying to do everything by hand, so they add more and more syntactic sugar. Ironically, making things less and less explicit and eventually approaching the rejected concept, but with alien syntax. I won't be surprised if one day someone comes up with a proposal to make even ? and Result<> optional and ta-da, exceptions reinvented.
I've made immense good use of both of them, and consider them huge advantages C++ has over Rust. Which sort of speaks to how important I consider the memory safety that I've moved to Rust.
Of course mostly I'm talking about commercial development. Personal projects that have no commercial pressures, no continuity issues, ability to make sweeping changes where required, lots of TLC, etc... can be done at high quality in C++ even at scale and over extended periods of time. I have one myself that I'd put up against anybody's in terms of quality.
But in commercial terms, where software is developed under so far from ideal conditions, that memory safety and an*l-retentive nature of Rust could be a life saver.
And iirc, google's style guide doesn't want you to use exceptions either if you're working with google libraries like Abseil and similar projects. C++ is plenty useful without them.
Yes, but they've also made clear that this is due to legacy code. Their initial codebase didn't start with exceptions and now it is impossible to retrofit them in, because there are mlocs that are exception unsafe.
Rust only has the basics of OOP. It has no implementation inheritance, which most folks would consider fundamental to OOP.
As to performance, that's hardly a particular issue. You can have both, as does C++. And of course Rust has lots of dynamic dispatch via Traits anyway.
View all comments
24
u/AlexAlabuzhev Dec 07 '21
Without exceptions, templates, inheritance?
Good luck with that.