this post was submitted on 08 Oct 2023
66 points (92.3% liked)

Rust

5751 readers
21 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] jcbritobr@mastodon.social 4 points 11 months ago* (last edited 11 months ago) (1 children)

@onlinepersona @snaggen

people write oo code in linux source code using c. With rust is simple. Just use composition, and you can explore the traits, that serves as and is better than interfaces.

[–] jcbritobr@mastodon.social 1 points 11 months ago* (last edited 11 months ago) (1 children)

@onlinepersona @snaggen another problem I see people doing while writing rust, is trying to write code like java. Rust isn't an OO language, but you can organize your code and have hierarchies.

[–] nous@programming.dev 6 points 11 months ago

Rust isn’t an OO language, but you can organize your code and have hierarchies.

IMO I think this is a common fallacy. OOP does not mean inheritance/hierarchies (despite them being part of every introductory OOP course nowadays). The original meaning of OOP had nothing to do with inheritance, that idea was mostly popularised by Java. And these days not even Java devs recommend inheritance as the first port of call but instead often favour composition and interfaces as the better language constructs.

Rust is as good at OOP styles as it is functional or procedural, if you ignore inheritance as a requirement of OOP. And a lot of code in rust can look and feel like OOP code in other languages. The abilities to encapsulate state, and polymorphism your code are far better features of OOP and both are well supported in rust. IMO rust offers the useful features from all paradigms fairly equally, which lets you write in any style you like, or even mix and match depending on the various situations. As one is not always better then the others, but each alone is useful in specific situations. More languages should be like this rather than forcing everything into one mold as it lets you pick the best style for each task.