Simplify and flesh out extension trait speaker notes#3167
Simplify and flesh out extension trait speaker notes#3167mgeisler merged 1 commit intogoogle:mainfrom
Conversation
| - Extension methods can be easier to discover than free functions. Language | ||
| servers (e.g., `rust-analyzer`) will suggest them if you type `.` after an | ||
| instance of the foreign type. |
There was a problem hiding this comment.
Thanks for removing this! I super dislike this argument myself: I find it very hard to "discover" mysterious methods that appear on well-known types in a nearly implicit fashion.
Free functions are much clearer: they are imported by name (barring any glob imports) and used by name. It doesn't get more clear than this when reading the code (which is what we typically optimize for, writing the code while having a full IDE environment powered up is just a small part of the life cycle).
There was a problem hiding this comment.
Yeah agreed, I'd generally suggest starting with free functions and only reaching for an extension trait if you need some functionality that a trait provides (polymorphism or method call syntax). Discoverability is still listed as a motivation in this slide, but I don't think I'm going to emphasize that much while teaching.
dyn.