Discussion: guidelines (or rules!) for annotating types for readability

I don’t see this trend as incongruent; I’m not arguing types are bad! I think static typing is good, and type inference is good, within limits. We’re purely discussing which limits are the right ones. I think rust’s limits (signatures must be explicitly typed, inference within bodies unless it’s ambiguous) are the right limits, and you’d prefer to not rely on inference as much.

1 Like

I agree that there are probably some reasonable heuristics at least.

As an example, I contributed a Clippy lint which looks for uses of Default::default() because in my opinion it's generally more clear to use a type name than a trait name in that case (e.g. String::default()). It's a pedantic lint, because it's pretty subjective, but I've found it useful. Perhaps this would be worth extending to all trait method accesses, or at least some other common ones (e.g. to_owned vs to_string/to_vec)?

4 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.