[swift-evolution] [Pitch] Remove type-inference for stored property

Brent Royal-Gordon brent at architechies.com
Sat Apr 8 01:34:40 CDT 2017


> On Apr 7, 2017, at 12:21 AM, Daniel Duan via swift-evolution <swift-evolution at swift.org> wrote:
> 
> The cons for doing this are obvious too: the inference makes the language feels more friendly and is, undoubtedly, a beloved feature for many. This would be a source breaking change.


Beyond just being more friendly, I think it could be considered a teaching issue. A great way to introduce beginners to custom types would be something like:

	struct Point {
		var x = 0.0
		var y = 0.0
	}

Or:

	struct Person {
		var name = ""
		var age = 18
	}

If you have to explicitly specify types for the properties, that's another thing you need to introduce to people before you can do this.

On the other hand, a very limited form of inference might be fine here. Imagine if we did a sort of limited, single-pass, top-down inference which only understood a few things (literals, tuple syntax, initializer calls), stopped once it had seen enough to infer a complete type, and rejected an expression if it encountered something it didn't understand before finishing. That would probably cover most simple cases, and it would probably only allow expressions whose types were obvious enough that we could use it for arguments, too. (But of course it would mean more code in the compiler, so it might not be worth it.)

-- 
Brent Royal-Gordon
Architechies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170407/0a672160/attachment.html>


More information about the swift-evolution mailing list