I think you're talking about one particular form of type inference -- allowing the type to be omitted on a stored property declaration. I think there is a debate to be had whether this is the right tradeoff between readability and concision. I tend to think omitting the type on a local variable is helpful, on stored properties of types, I'm not so sure. However at this stage of the language's evolution, a source breaking change like banning inferred stored property types would be quite a drastic change, and I'm not sure it will ever meet the high bar we've set for these changes.
However that's not the only place where the compiler infers types. There are also the types of intermediate values in expressions -- and this is a form of type inference that even C has:
foo(bar(y + z) + x * 3)
It would be quite inconvenient if you had to declare the type of x * 3
, y + z
, bar(y + z) + x * 3
, and so on. So I think you'll agree that this form of type inference is helpful.
Another form of type inference is inference of generic parameters when calling a function or constructing a type:
func doSomething<T : Sequence>(_ t: T) {
...
}
doSomething([1, 2, 3, 4, 5])
We don't even have a syntax to explicitly pass generic parameters to a function call, but if we did, you'd have to write something like doSomething<Array<Int>>([1, 2, 3, 4, 5])
.
Type checker performance is a separate issue. Adding more type annotations will help the type checker in some cases, but its not a panacea because even in the presence of annotations the type checker still has to verify that the annotation was correct, infer types for intermediate results, figure out what overloads are selected, and so on. The performance story is more complicated than "more annotations = fast".
I hope in the future we can spend more time on making the type checker fast. I believe most of the performance problems users face today can be solved without imposing a specific coding style on the programmer. Of course, if you choose to use more or less annotations in different places, that is your decision and it should be driven by understandability of the code and not compiler implementation concerns.