4 ms·
I always say it differently: OOP is a paradigm. I've done "object oriented programming" in C and in assembly. Might be more correct to say I've done things like
by lowbloodsugar 2y ago
I always say it differently: OOP is a paradigm. I've done "object oriented programming" in C and in assembly. Might be more correct to say I've done things like polymorphism in C and assembly. By my definition, Rust can do OOP, even without dyn. I tend to take a very low-level view of things, since I was an assembly programmer before I was a C programmer. I think as Rust broadens its footprint, people are going to have to start using dyn more, and as they do, there'll be new patterns becoming idiomatic. The polymorphism-using-enums pattern is reasonable for tight code like embedded systems, but painful for applications generally.
- zamalek 2y ago> The polymorphism-using-enums pattern is reasonable for tight code like embedded systems, but painful for applications generally. Rust rapidly becomes painful if you try to OOP in it. You would be better off using an OOP language for OOP. It wasn't voted the most loved language because people enjoyed learning lifetimes alongside all the accidental complexity OOP creates. Dynamic dispatch is mostly seen in two circumstances: the type can't be known at compile time, and reducing code bloat as an optimization step.
- pjmlp 2y agoI ported the famous Raytracing in a Weeked from C++ OOP into Rust OOP, without any issues, code available on my Github. Likewise, Microsoft teams not only didn't had any major issues adding COM tooling support for Rust, it is much easier to deal with COM in Rust, than all the C++ frameworks Microsoft has created throughout the years. Likewise, code available on the official Windows bindings for Rust.
- lowbloodsugar 2y agoComplex vs complicated. Complexity is a property of the problem you are trying to solve. If the problem is complex, the solution is complex. Complicated is a property of the implementation. It happens particularly if the abstractions available in the language of choice can’t represent the complexity of the problem. My impression so far is that Rust is powerful enough to do OOP without issue, but, strangely, doing so is frowned upon, and instead developers add needless complexity to avoid using a feature of the language (dyn).
- zamalek 2y agoAccidental complexity is an academic term, it means what you refer to as "complicated." Essential complexity would be what you refer to as "complexity." My comment was being precise about it. dyn is avoided because it is typically slower due to the indirection, and because of how its opacity breaks many zero cost abstractions.
- sunshowers 2y agoFYI: https://docs.rs/enum_dispatch https://docs.rs/enum_dispatch This doesn't work for every case of dynamic dispatch (it only works for what I call closed and semi-open universes of choices [1]), but it works for many of them. And there can always be a catch-all variant that uses a trait object. [1] https://sunshowers.io/posts/open-closed-universes/ https://sunshowers.io/posts/open-closed-universes/
- lowbloodsugar 2y agoThanks. I was hoping/dreading that someone had already written such a thing. Hoping, because I have this problem. Dreading, because so much “practical” Rust is macros to make up for missing expressiveness of the language itself.