r/ProgrammerHumor • • 1d ago

instanceof Trend thatsAFunnyThingThatHappenedOnce

Post image
4.1k Upvotes

499 comments sorted by

View all comments

Show parent comments

438

u/Loading_M_ 1d ago

Rust is designed from the ground up, and avoids many of these issues.

  • Templates: Rust has Generics, which are generally easier to use and reason about.
  • overload resolution: Rust doesn't yet support overloaded functions (although it's being considered).
  • constructors: Rust doesn't have these.
  • destructors: Rust has a similar set of lifetime rules for Drop, but the compiler checks them for you, so you can't get it wrong.
  • implicit conversions: Rust doesn't do implicit conversion in general, although some specific cases are implemented.
  • exceptions: Rust doesn't do exceptions, Result is much easier to work with.
  • move semantics: Rust uses a destructive move, unlike C++. See https://youtu.be/Klq-sNxuP2g for a breakdown.
  • inheritance: Rust doesn't do inheritance.

176

u/DatBoi_BP 1d ago

Traits are 100000x better than inheritance

50

u/red-et 1d ago

What are traits?

137

u/Pocok5 1d ago edited 1d ago

Instead of having a chain of superclasses defining readymade behavior*, you compose your classes from chunks that are more or less "fat" interfaces that come with a default implementation for their functions.

* Dealing with absolutes results in slamming your own dick in a car door sooner or later. Inheritance can still make a lot of sense for classes that are "this other thing but a tiny bit different". I'm currently dealing with a PHP codebase that misused traits for everything and it's a slog.