[Pitch] Remove type-inference for stored property


(Lucas Neiva) #1

(Forgot CC. How's that Discord coming along? :stuck_out_tongue_winking_eye:)

路路路

On 7 Apr 2017, at 13:07, Lucas Neiva <lneiva@me.com> wrote:

+1

I think declaring property types is beneficial to readability.

It seems to me like properties are on the same level as functions, where types are also not inferred. I see them both as 鈥渕embers鈥, if you like.

Another thing is that computed properties also require an explicit type, which sometimes trips me up a bit when mixing computed and normal properties.

On Apr 07, 2017, at 09:21 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

Hi all,

In a discussion about inferring parameter types from default value, Slava brought up some performance problems caused by type inference for stored properties in side types:

https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170313/033882.html

Towards the end, the post mentioned that some Swift team members contemplated requiring types for stored properties in type declarations. I think this idea deserves some more attention. Hence this last minute idea-floating.

In addition to solving a performance headache in implementation, there're always the general benefit of making type declartion more explicit and readable (clarity for reader should out-weigh pleasure of the author). Making the
language slightly more consistent (we are not inferring types for default parameter values in function anyways).

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.

Just thought I'd float the idea to gather some quick reaction. What do y'all think?

Daniel Duan
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Charlie Monroe) #2

+1 on removing the inference. I actually always declare the type for stored properties as well for better readability...

路路路

On Apr 9, 2017, at 5:28 PM, Lucas Neiva via swift-evolution <swift-evolution@swift.org> wrote:

(Forgot CC. How's that Discord coming along? :stuck_out_tongue_winking_eye:)

On 7 Apr 2017, at 13:07, Lucas Neiva <lneiva@me.com <mailto:lneiva@me.com>> wrote:

+1

I think declaring property types is beneficial to readability.

It seems to me like properties are on the same level as functions, where types are also not inferred. I see them both as 鈥渕embers鈥, if you like.

Another thing is that computed properties also require an explicit type, which sometimes trips me up a bit when mixing computed and normal properties.

On Apr 07, 2017, at 09:21 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Hi all,

In a discussion about inferring parameter types from default value, Slava brought up some performance problems caused by type inference for stored properties in side types:

https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170313/033882.html

Towards the end, the post mentioned that some Swift team members contemplated requiring types for stored properties in type declarations. I think this idea deserves some more attention. Hence this last minute idea-floating.

In addition to solving a performance headache in implementation, there're always the general benefit of making type declartion more explicit and readable (clarity for reader should out-weigh pleasure of the author). Making the
language slightly more consistent (we are not inferring types for default parameter values in function anyways).

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.

Just thought I'd float the idea to gather some quick reaction. What do y'all think?

Daniel Duan
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution