3 ms·
There are no classes in Rust, and it's better for it. That's my point, some abstractions like classes are NOT necessary. There were arguments before Rust 1.0 t
by iopq 5y ago
There are no classes in Rust, and it's better for it. That's my point, some abstractions like classes are NOT necessary.
There were arguments before Rust 1.0 that people will simply try to emulate classes. But nobody actually bothered, because traits provide enough functionality that you don't actually need to have classes to actually write maintainable and understandable programs.
I'm attacking the exact point of the article that you need X. Maybe you actually don't need X, and your programs will be better for it.
- Zababa 5y ago> There were arguments before Rust 1.0 that people will simply try to emulate classes. But nobody actually bothered, because traits provide enough functionality that you don't actually need to have classes to actually write maintainable and understandable programs. It's not only traits. Traits (well, traits objects) are used for dynamic dispatch, traits themselves are used as composable interfaces, and structs + impl blocs are used for basic classes. My point was that your example, implementing a trait that may or may not use a weight for barking, is not making the program better. It's making it more complex for no good reason. Here's what your program could be: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ef14838f18c88d6d7de35f96f0d4d189 https://play.rust-lang.org/?version=stable&mode=debug&editio... Adding traits doesn't make the code better. There's only dogs that are barking. You don't even need to have bark() be a method, a plain function will do.
- CRConrad 5y ago> There's only dogs that are barking. class DogSoundFile constructor Create(MP3File, Weight); ... Bit silly, innit? (Are bigger MP3 files heavier...? :-)
- iopq 5y agoOf course it can be as simple as that, that's beside the point But almost every time you actually won't ship a program that just prints stuff to the console That's why I did it that way, because how you actually output won't be println, but probably to a window or a socket, or whatever The core functionality of passing a slice will be actually useful in those cases, you can include this code in your final program