Hacker News new | ask | show | jobs
by imtringued 55 days ago
How are traits not intuitive?

All they do is guarantee that a type has methods A,B,C available.

What might be slightly confusing are trait bounds on generics. They are kind of like traits themselves but not exactly. They implicitly say "this generic parameter must make methods A, B, C available via Trait X".

2 comments

The answer to all forms of "How is [X] not intuitive?" is that the person finding it unintuitive doesn't have other points of reference that make it intuitive. Lots of people have spent their programming life working with languages that don't have the concept of generics, or maybe have even worked on things where they were using generics but didn't know that's what they were doing.

Very few things are truly intuitive, they just happen to be similar to other things you've done and so you've got a step up on understanding them. Really good software engineers tend to be constantly playing with things outside their usual domain and so have broader range of concepts they can reach for when the time comes.

because i was stupid lol. i’d only done (very) basic duck typed generics in c++ before then.

all i wanted was to add a new method i could call in the same way as all the methods on Iterator (map, filter, etc.). and was suddenly confronted with `impl Trait2 for T where T: Trait1`. which makes perfect sense now. but at the time was unparseable.