Is Rust OOP? If not, what is it oriented to?

I think the thing that confuses people is that Rust isn't class-based OOP. Most people come to Rust from a C++/Python/Java/C#/etc background so that's the perspective they have. If you try to program in Rust the same way as you do using classes, then you're going to run into problems and get frustrated.

Funnily enough people had a similar problem with Javascript's style of OOP. The "solution" there was to glue the class keyword on top of the whole thing and call it a day.

But anyway, all these languages are really multi-paradigm. You can often use procedural style or functional style to a greater or lesser extent. And from a theoretical point of view, merely sticking functions and variables into a class doesn't mean you're doing OOP.

Rust is also multi-paradigm, with good support for some functional programming styles (although people coming from Haskell et al might be disappointed if they expect too much).

I'm going to slightly disagree with @H2CO3 :stuck_out_tongue: in that I think Rust does sort of encourage using an OOP style to at least the extent that you use standard library objects (e.g. Vec, Path, etc).

7 Likes