4 ms·
Background: C++ since around 1998, added in Python around 2008, Rust around 2016 While I agree with everything in the article, some times I wish I could have i
by epage 4y ago
Background: C++ since around 1998, added in Python around 2008, Rust around 2016
While I agree with everything in the article, some times I wish I could have it both ways with:
> First of all, generics without duck typing are greatly appreciated. Traits clearly indicate the contract struct or function expects from the type, which is great. This also helps compiler to generate helpful error messages. Instead of “invalid reference to method clone() on line Y” you get “type X does not implement Clone” - clean and informative.
I will say that there are times when I wish I could sneak in some duck typed traits, particularly `Debug`. Sometimes you are working in generic or dynamic dispatch code and just want to use `dbg!` but can't because (1) you didn't think ahead or were too lazy to annotate things with `Debug`, (2) you are a bit paranoid about excluding a type that doesn't support `Debug`, or (3) You are doing dynamic dispatch and `FooTrait + Debug` only works for generics.
`Debug` is also just one example. Overall, I love the explicitness but at times I do wish I could fudge things a little.
- tialaramex 4y agoI strongly recommend just writing a #[derive] line for every user defined type you make. Start off with Debug in there, and you'll find often you already know some other traits that'll be trivially derived for this type, Clone, Default, stuff like that.
- epage 4y agoGenerally I do. My comment isn't about whether my own types are `Debug` but others on top of several other problems.
- gpderetta 4y agoThe original C++0x concept proposal had concept checking, but had an escape hatch to instantiation-only checking when needed.