Hacker News new | ask | show | jobs
by leoedin 460 days ago
It's not only not really idiomatic, it's almost never necessary in practice.

I was struggling to think of a time I'd ever given a type annotation to an integer local variable - because normally the place the variable ends up dictates the type.

Local variable becomes part of struct? Struct dictates type. Passed into function? Function dictates type. Multiplied by other variable and then that is passed to function? The type is determined by the function.

1 comments

It can be necessary if you’re passing it to a generic type/function.