A collection of Bad Code Smells in a Catalog form for Developers & Researchers. Code Smell is a typical bad code implementation, and learning these concepts immiedietly makes you a better developer!
The only reason why traits are considered better is because in languages like rust it can enable static dispatch. Whereas interfaces in C#, Java, Typescript, (and C++ via abstract classes, not templates) are always dynamic dispatch.
Looking at the Rust docs, it looks like it’s not much more than a difference in implementation under the hood.
It would be clunky, but in C# you could duct tape this: make a static abstract method in an interface that takes an object named ‘self’, then an extension method that extends the class and just casts then runs the function with Unsafe.As<TFrom, TTo>(ref obj), or an explicitly aligned struct with overlapping values.
I don’t expect any such implementation anytime soon though :/
ps: Typescript can go take a hike, it’s a superset for a language that was never designed for this
use an interface?
Yeah Interfaces would be the next best thing.
The only reason why traits are considered better is because in languages like rust it can enable static dispatch. Whereas interfaces in C#, Java, Typescript, (and C++ via abstract classes, not templates) are always dynamic dispatch.
Looking at the Rust docs, it looks like it’s not much more than a difference in implementation under the hood.
It would be clunky, but in C# you could duct tape this: make a static abstract method in an interface that takes an object named ‘self’, then an extension method that extends the class and just casts then runs the function with Unsafe.As<TFrom, TTo>(ref obj), or an explicitly aligned struct with overlapping values.
I don’t expect any such implementation anytime soon though :/
ps: Typescript can go take a hike, it’s a superset for a language that was never designed for this