Type inference cost
Swift has type inference, so you rarely have to write types, yet your team convention says "annotate types on complex expressions and public APIs." How does type inference work that led to this rule?
Swift has type inference, so you rarely have to write types, yet your team convention says "annotate types on complex expressions and public APIs." How does type inference work that led to this rule?
Swift's type inference is bidirectional: it gathers constraints across the whole expression and solves them together, so in a long expression full of literals and overloaded operators the candidate combinations explode, compilation slows down, or you get an 'expression too complex' error. Writing the type prunes the candidates so solving is faster, and it makes the API contract visible.