[Pitch] Remove type-inference for stored property

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:

[swift-evolution] Infer types of default function parameters

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?

Although it seems like only an implementation-side problem(i.e. "let's just improve implementation"), I see a benefits to require type for stored property *if* it is not obvious what the type is for *reader*. I.e. if we have something like this, I don't think we should require a type:
struct S {
var x = 0
}

I think there is value in requiring a type annotation there. For example, this bug would be avoided: https://twitter.com/benjaminencz/status/851892622213783552

I believe the pointed problem is much wider, than type-inference and I even think this is bug(in design?) that should be fixed at least with warning.

Please consider this example:

protocol P {
  var value : Int32 {get}
}

extension P {
  var value : Int32 {return 20}
}

class C : P {
  let value = 4_000_000_000

  /// or even this:
      // let value : Int = 4_000_000_000
}

First, as class C conforms to P protocol, it must have *mutable* 'value' property
Second, currently it seems like class C has two 'value' properties with different type. It is very strange(the principle of less surprise, yes?) and as we can see dangerous behavior. Was bug to bugs.swift.org submitted? If so, what was the reply of the core team?

···

On 12.04.2017 7:19, Jaden Geller wrote:

On Apr 7, 2017, at 4:07 AM, Vladimir.S via swift-evolution >> <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
On 07.04.2017 10:21, Daniel Duan via swift-evolution wrote:

but I do think it will be better to require a type in such cases :

struct S{
var x = something(SomeType(), 123, "123") // can be generic func
}

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

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

I would be alright with this change. The slight inconvenience, even in
teaching, would be worth it, in my opinion. It is easier for developers to
reason about the types intended when they are made explicit.

···

On Sun, Apr 9, 2017 at 6:01 PM, Jon Shier via swift-evolution < swift-evolution@swift.org> wrote:

I generally dislike any language change desired because it makes the
compiler implementation easier. We saw a few such changes for Swift 3 and
all of them were net negatives for the actual users of the language (to a
minor extent for most, to be fair). I would hope that, as the compiler
matures, these types of inference performance issues will become less of a
problem. Removing a rather nice language feature, especially one that plays
such a big role in the “feel” of the language, for short term gain seems
rather shortsighted to me.

Jon Shier

On Apr 9, 2017, at 11:23 AM, Lucas Neiva via swift-evolution < > swift-evolution@swift.org> wrote:

If inference only works in simple cases, I think it would seem like it
works unpredictability to anyone unfamiliar with the implementation details.

I image the question of "why do I have to declare a type here, but not in
this case?" coming up.

Declaring types is one of the first things you have to learn anyway. Just
declaring a function already requires some understanding of types.
Properties are not much different IMO.

On 8 Apr 2017, at 08:34, Brent Royal-Gordon via swift-evolution < > swift-evolution@swift.org> wrote:

On Apr 7, 2017, at 12:21 AM, Daniel Duan via swift-evolution < > swift-evolution@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

_______________________________________________
swift-evolution mailing list
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

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

This is not really a helpful comment, but: I kinda wish they did.

l8r
Sean

···

On Apr 10, 2017, at 10:54 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

Neither of these works btw.

func bar(myString = “hello”)
class Baz {
  let myString = { return “hello” }()
}

On Apr 9, 2017, at 11:26 PM, Jean-Daniel <mailing@xenonium.com> wrote:

I’m full -1 on this one. It will make the language inconsistent. How do you explain a new comer that type inference work in some case, but not in other cases, while in both the compiler is completely capable to define the type.

Why

let myString = "hello"

would be accepted but not

class Foo {
  let myString = "hello"
}

Le 10 avr. 2017 à 04:05, Daniel Duan via swift-evolution <swift-evolution@swift.org> a écrit :

I’m still not sure whether *I* want this. But here’s a proposal anyways: remove-type-inference-for-stored-proprety.md · GitHub

On Apr 7, 2017, at 12: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:

[swift-evolution] Infer types of default function parameters

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

_______________________________________________
swift-evolution mailing list
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

I'm honestly having trouble believing that this is being seriously proposed... I always saw type inference as one of the most important advantages of Swift over some older languages, the Swift ebook mentions many times how smart Swift is that it can infer types for you so that you don't have to type too much boilerplate. And here we're talking about removing this feature that was advertised from the beginning as Swift's strong point, in order to make the compilation faster? The compiler speeds will be improved, the syntax will stay with us.

Yes, specifying the type is often clearer, I do it myself, e.g. "var enabled: Bool = true". But that's my choice, not something I should be forced to do. It's something to put in style guides, not to enforce with the compiler.

To be clear, it's being "seriously proposed" in the sense that someone sent an email to a mailing list.

John.

···

On Apr 11, 2017, at 8:18 PM, Jakub Suder via swift-evolution <swift-evolution@swift.org> wrote:

On 8 April 2017 at 07:40, Pranshu Goyal via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
I agree with the sentiment of the proposal, it does add value to overall efficiency of swift and make things simpler for the swift team, but as Matthew said a blanket ban will add noise to the code. Also this particular feature is one of those niceties about swift which makes it very welcoming to new adopters.

If some middle ground can be proposed to this problem then I think we will be making a lot of people happy.

On 7 April 2017 at 18:31, Matthew Johnson via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

> On Apr 7, 2017, at 2: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:
>
> [swift-evolution] Infer types of default function parameters
>
> 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?

I’m willing to keep an open mind on this topic but I don’t think wholesale banning of inference is the right thing to do. Here is an example of a case where I do not want to give up inference. When a property is initialized inline by calling an initializer of a non-generic type (very common) any annotation is strictly redundant.

struct {
    let foo = Foo()
}

Requiring a type annotation here feels very unnecessary and boilerplate-y. I adds no additional clarity to a reader of the code, only noise. Noise reduces clarity. Small amounts of unnecessary or redundant information such as in an individual stored property declaration are not that big a deal. But on balance they add up quickly and have an undesirable impact on the overall clarity of code.

>
> 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 <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

--
Pranshu Goyal
iOS Developer
tlkn

_______________________________________________
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

  I generally dislike any language change desired because it makes the compiler implementation easier. We saw a few such changes for Swift 3 and all of them were net negatives for the actual users of the language (to a minor extent for most, to be fair).

I’m going to have to call shenanigans on this claim :-) At least I can’t _think_ of any Swift 3 features that were designed with the goal of making the implementation simpler. Even the feature removals, such as nuking the ‘function currying’ syntax, took time to implement (and this is not even fully removed yet).

I would hope that, as the compiler matures, these types of inference performance issues will become less of a problem. Removing a rather nice language feature, especially one that plays such a big role in the “feel” of the language, for short term gain seems rather shortsighted to me.

I agree. The type checker might have pathological behavior in some cases now, but we hope to fix those over time, and none of it is specific to the expressions people usually write in stored property initializers.

Slava

···

On Apr 9, 2017, at 3:01 PM, Jon Shier via swift-evolution <swift-evolution@swift.org> wrote:

Jon Shier

On Apr 9, 2017, at 11:23 AM, Lucas Neiva via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

If inference only works in simple cases, I think it would seem like it works unpredictability to anyone unfamiliar with the implementation details.

I image the question of "why do I have to declare a type here, but not in this case?" coming up.

Declaring types is one of the first things you have to learn anyway. Just declaring a function already requires some understanding of types. Properties are not much different IMO.

On 8 Apr 2017, at 08:34, Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

On Apr 7, 2017, at 12:21 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@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

_______________________________________________
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 <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

I'm honestly having trouble believing that this is being seriously proposed... I always saw type inference as one of the most important advantages of Swift over some older languages, the Swift ebook mentions many times how smart Swift is that it can infer types for you so that you don't have to type too much boilerplate.

I think Swift and its compiler have. A lot of other strong points beyond type inference and emphasis on static typing too, but type inference has a very very real cost and sooner or later the language and its community will have to deal with compile times that are a lot slower (some people were reporting about 2+ times slower) than a similar project in Objective-C... that is a very real productivity cost.

···

Sent from my iPhone

On 12 Apr 2017, at 01:18, Jakub Suder via swift-evolution <swift-evolution@swift.org> wrote:

And here we're talking about removing this feature that was advertised from the beginning as Swift's strong point, in order to make the compilation faster? The compiler speeds will be improved, the syntax will stay with us.

Yes, specifying the type is often clearer, I do it myself, e.g. "var enabled: Bool = true". But that's my choice, not something I should be forced to do. It's something to put in style guides, not to enforce with the compiler.

On 8 April 2017 at 07:40, Pranshu Goyal via swift-evolution <swift-evolution@swift.org> wrote:
I agree with the sentiment of the proposal, it does add value to overall efficiency of swift and make things simpler for the swift team, but as Matthew said a blanket ban will add noise to the code. Also this particular feature is one of those niceties about swift which makes it very welcoming to new adopters.

If some middle ground can be proposed to this problem then I think we will be making a lot of people happy.

On 7 April 2017 at 18:31, Matthew Johnson via swift-evolution <swift-evolution@swift.org> wrote:

> On Apr 7, 2017, at 2: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:
>
> [swift-evolution] Infer types of default function parameters
>
> 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?

I’m willing to keep an open mind on this topic but I don’t think wholesale banning of inference is the right thing to do. Here is an example of a case where I do not want to give up inference. When a property is initialized inline by calling an initializer of a non-generic type (very common) any annotation is strictly redundant.

struct {
    let foo = Foo()
}

Requiring a type annotation here feels very unnecessary and boilerplate-y. I adds no additional clarity to a reader of the code, only noise. Noise reduces clarity. Small amounts of unnecessary or redundant information such as in an individual stored property declaration are not that big a deal. But on balance they add up quickly and have an undesirable impact on the overall clarity of code.

>
> Daniel Duan
> _______________________________________________
> swift-evolution mailing list
> 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

--
Pranshu Goyal
iOS Developer
tlkn

_______________________________________________
swift-evolution mailing list
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

As I explained on Twitter, the behavior is initially counterintuitive but
in many ways the least surprising result.

(First, you are incorrect about P requiring a mutable property. That is not
what var means in a protocol.)

However, you are right that two properties named value are being allowed.
It seems strange at first but consider:

Given: a protocol P with only one requirement, but with a default
implementation for that requirement. One would expect that any type T could
retroactively conform to P. After all, either T has its own implementation
of the requirement or it does not.

If the requirement is a property and not a method, and T has an identically
named but not identically typed property, we allow this sort of
"overloading" which is very much like overloading on the return type. This
fulfills the expectation above that T can conform to P. Even requiring a
warning in this scenario would break retroactive conformance.

The behavior at the call site is not harmful. A user of T may or may not
see that it conforms to P. This is because conformance can be retroactive.
Thus, when using an instance of T, references to the property are to T's
own implementation. However, if the user can see P and the conformance T :
P, they can always explicitly request P's differently typed implementation
explicitly by using "as" (just like selecting an overloaded method with a
different return type).

The behavior that is unexpected and potentially harmful is for the author
of a type T trying to conform to P. It falls into the category of
near-misses that includes unintentional typos in method names, etc. It is
no more surprising than any of those cases where you, say, get the argument
label spelled slightly wrong and end up without an intended override of a
default implementation but two methods instead.

As mentioned earlier on this list, the user experience of writing a
conforming type is suboptimal, and there are likely to be clever ways for
the compiler or other tools to help. However, ripping out type inference or
breaking retroactive conformance is not the way forward to solving this
issue.

···

On Wed, Apr 12, 2017 at 05:15 Vladimir.S via swift-evolution < swift-evolution@swift.org> wrote:

On 12.04.2017 7:19, Jaden Geller wrote:
>
>> On Apr 7, 2017, at 4:07 AM, Vladimir.S via swift-evolution > >> <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
>>
>> On 07.04.2017 10:21, Daniel Duan via swift-evolution 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:
>>>
>>>
[swift-evolution] Infer types of default function parameters
>>>
>>> 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?
>>
>> Although it seems like only an implementation-side problem(i.e. "let's
just improve
>> implementation"), I see a benefits to require type for stored property
*if* it is
>> not obvious what the type is for *reader*. I.e. if we have something
like this, I
>> don't think we should require a type:
>> struct S {
>> var x = 0
>> }
>
> I think there is value in requiring a type annotation there. For
example, this bug
> would be avoided:
https://twitter.com/benjaminencz/status/851892622213783552

I believe the pointed problem is much wider, than type-inference and I
even think
this is bug(in design?) that should be fixed at least with warning.

Please consider this example:

protocol P {
        var value : Int32 {get}
}

extension P {
        var value : Int32 {return 20}
}

class C : P {
        let value = 4_000_000_000

        /// or even this:
        // let value : Int = 4_000_000_000
}

First, as class C conforms to P protocol, it must have *mutable* 'value'
property
Second, currently it seems like class C has two 'value' properties with
different
type. It is very strange(the principle of less surprise, yes?) and as we
can see
dangerous behavior. Was bug to bugs.swift.org submitted? If so, what was
the reply of
the core team?

>
>>
>> but I do think it will be better to require a type in such cases :
>>
>> struct S{
>> var x = something(SomeType(), 123, "123") // can be generic func
>> }
>>
>>
>>
>>>
>>> Daniel Duan _______________________________________________
>>> swift-evolution mailing listswift-evolution@swift.org
>>> <mailto:swift-evolution@swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>
>> _______________________________________________
>> 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

I think it’s worth thinking about, clarifying, and possibly documenting where inference happens and where it doesn’t.

As mentioned, there are limits to inference. Some of those limits are imposed by design, as in functions (check out F# to have your mind blown by how far type inference goes there).

- Type inference of function-local variable declarations is not the topic here. Everybody loves that :-D.

- For properties there are some levels to it, depending on the initial value:
  - [inferred] Literals (String, Int, ...)
  - [inferred] Constructor call, e.g. `Foo(a, b)`
  - [inferred] Function call without generics, e.g. `someFunc()`
  - [inferred] Function call with generics, e.g. `someArray.map(someGenericFunc)` (I believe this triggered the discussion, as it can cause performance issues)
  - [NOT inferred] Function call with AMBIGUOUS types (impossible to infer)
  - [NOT inferred] Closure, e.g. `{ /* do some stuff */ return /* some initial value */ }()`

- Computed properties, where currently the type is NOT inferred

- I’m unsure about how global properties are implemented, but I think the inference behaviour is the same there.

As I explained on Twitter, the behavior is initially counterintuitive but in many ways the least surprising result.

(First, you are incorrect about P requiring a mutable property. That is not what var means in a protocol.)

Yes, sorry, my mistake. But actually this does not change anything for this example:

protocol P {
  var value : Int32 {get set} // get+set
}

extension P {
  var value : Int32 {get{return 10} set{}}
}

class C : P {
  let value : Int = 4_000_000_000 // let constant
}

However, you are right that two properties named value are being allowed. It seems strange at first but consider:

Given: a protocol P with only one requirement, but with a default implementation for that requirement. One would expect that any type T could retroactively conform to P. After all, either T has its own implementation of the requirement or it does not.

If the requirement is a property and not a method, and T has an identically named but not identically typed property, we allow this sort of "overloading" which is very much like overloading on the return type. This fulfills the expectation above that T can conform to P. Even requiring a warning in this scenario would break retroactive conformance.

The behavior at the call site is not harmful. A user of T may or may not see that it conforms to P. This is because conformance can be retroactive. Thus, when using an instance of T, references to the property are to T's own implementation. However, if the user can see P and the conformance T : P, they can always explicitly request P's differently typed implementation explicitly by using "as" (just like selecting an overloaded method with a different return type).

The behavior that is unexpected and potentially harmful is for the author of a type T trying to conform to P. It falls into the category of near-misses that includes unintentional typos in method names, etc. It is no more surprising than any of those cases where you, say, get the argument label spelled slightly wrong and end up without an intended override of a default implementation but two methods instead.

Not agree here. We *can* have methods with the same name but different argument/result type defined in the *same* type.
But we can't have property with the same name but different type in the same type.

As mentioned earlier on this list, the user experience of writing a conforming type is suboptimal, and there are likely to be clever ways for the compiler or other tools to help. However, ripping out type inference or breaking retroactive conformance is not the way forward to solving this issue.

I agree that retroactive conformance is important feature, but in this particular case, the situation IMO is not the same as with near-miss for methods.

And actually I still believe that such near-miss(even for methods) will be usually an hidden/delayed error, when user do expect that type's methods/props will conform the type to protocol, not protocol's default method. And I do believe that be able to prevent such error is more important than no-worry retroactive conformance. (and then spent a number of hours to debug such hard-to-find bug)

Plus, if we *want* we can suggest a way to silence such warning even for retroactive conformance. The question if the problem worth to be solved.

···

On 12.04.2017 15:35, Xiaodi Wu wrote:

On Wed, Apr 12, 2017 at 05:15 Vladimir.S via swift-evolution > <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

    On 12.04.2017 7:19, Jaden Geller wrote:
     >
     >> On Apr 7, 2017, at 4:07 AM, Vladimir.S via swift-evolution > >> <swift-evolution@swift.org <mailto:swift-evolution@swift.org> > <mailto:swift-evolution@swift.org <mailto:swift-evolution@swift.org>>> wrote:
     >>
     >> On 07.04.2017 10:21, Daniel Duan via swift-evolution 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:
     >>>
    [swift-evolution] Infer types of default function parameters
     >>>
     >>> 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?
     >>
     >> Although it seems like only an implementation-side problem(i.e. "let's just
    improve
     >> implementation"), I see a benefits to require type for stored property *if* it is
     >> not obvious what the type is for *reader*. I.e. if we have something like this, I
     >> don't think we should require a type:
     >> struct S {
     >> var x = 0
     >> }
     >
     > I think there is value in requiring a type annotation there. For example, this bug
     > would be avoided: https://twitter.com/benjaminencz/status/851892622213783552

    I believe the pointed problem is much wider, than type-inference and I even think
    this is bug(in design?) that should be fixed at least with warning.

    Please consider this example:

    protocol P {
             var value : Int32 {get}
    }

    extension P {
             var value : Int32 {return 20}
    }

    class C : P {
             let value = 4_000_000_000

             /// or even this:
             // let value : Int = 4_000_000_000
    }

    First, as class C conforms to P protocol, it must have *mutable* 'value' property
    Second, currently it seems like class C has two 'value' properties with different
    type. It is very strange(the principle of less surprise, yes?) and as we can see
    dangerous behavior. Was bug to bugs.swift.org <http://bugs.swift.org> submitted?
    If so, what was the reply of
    the core team?

     >
     >>
     >> but I do think it will be better to require a type in such cases :
     >>
     >> struct S{
     >> var x = something(SomeType(), 123, "123") // can be generic func
     >> }
     >>
     >>>
     >>> Daniel Duan _______________________________________________
     >>> swift-evolution mailing listswift-evolution@swift.org
    <mailto:listswift-evolution@swift.org>
     >>> <mailto: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 <mailto:swift-evolution@swift.org>
    <mailto: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 <mailto:swift-evolution@swift.org>
    https://lists.swift.org/mailman/listinfo/swift-evolution

I am 110% AGAINST this change. Having complex expressions as a stored property initializer is bad practice anyway, and having the type prefixed in that case provides at best marginal improvement in clarity and doesn’t fix the underlying problem.

Type inference on simple expressions allows you to put the emphasis on the value, rather than the type—e.g. `let defaultTimeout = 5 as TimeInterval` is way easier to read and understand than `let defaultTimeout: TimeInterval = 5`; and it only gets worse if you declare something with a long class name—`let fooBarBazzerciser: MyReallyReallyLongType = MyReallyReallyLongType(argumentOne: 1, argumentTwo: 2)`—you might even have to scroll horizontally just to see what the arguments are! Clarity lost, none gained.

···

On Apr 9, 2017, at 3:04 PM, T.J. Usiyan via swift-evolution <swift-evolution@swift.org> wrote:

I would be alright with this change. The slight inconvenience, even in teaching, would be worth it, in my opinion. It is easier for developers to reason about the types intended when they are made explicit.

On Sun, Apr 9, 2017 at 6:01 PM, Jon Shier via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
  I generally dislike any language change desired because it makes the compiler implementation easier. We saw a few such changes for Swift 3 and all of them were net negatives for the actual users of the language (to a minor extent for most, to be fair). I would hope that, as the compiler matures, these types of inference performance issues will become less of a problem. Removing a rather nice language feature, especially one that plays such a big role in the “feel” of the language, for short term gain seems rather shortsighted to me.

Jon Shier

On Apr 9, 2017, at 11:23 AM, Lucas Neiva via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

If inference only works in simple cases, I think it would seem like it works unpredictability to anyone unfamiliar with the implementation details.

I image the question of "why do I have to declare a type here, but not in this case?" coming up.

Declaring types is one of the first things you have to learn anyway. Just declaring a function already requires some understanding of types. Properties are not much different IMO.

On 8 Apr 2017, at 08:34, Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

On Apr 7, 2017, at 12:21 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@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

_______________________________________________
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 <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
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

It is helpful in the sense that it tells us what’s really inconsistent: beginner’s have to learn when inference is available when declaring their types. That’s story is sketchy.

···

On Apr 10, 2017, at 8:55 AM, Sean Heber <sean@fifthace.com> wrote:

This is not really a helpful comment, but: I kinda wish they did.

l8r
Sean

On Apr 10, 2017, at 10:54 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

Neither of these works btw.

func bar(myString = “hello”)
class Baz {
let myString = { return “hello” }()
}

On Apr 9, 2017, at 11:26 PM, Jean-Daniel <mailing@xenonium.com> wrote:

I’m full -1 on this one. It will make the language inconsistent. How do you explain a new comer that type inference work in some case, but not in other cases, while in both the compiler is completely capable to define the type.

Why

let myString = "hello"

would be accepted but not

class Foo {
  let myString = "hello"
}

Le 10 avr. 2017 à 04:05, Daniel Duan via swift-evolution <swift-evolution@swift.org> a écrit :

I’m still not sure whether *I* want this. But here’s a proposal anyways: remove-type-inference-for-stored-proprety.md · GitHub

On Apr 7, 2017, at 12: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:

[swift-evolution] Infer types of default function parameters

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

_______________________________________________
swift-evolution mailing list
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

Well, I’m not really a beginner, but for me personally, the computer is here to help me do my work and to do some of the thinking for me. I really hate repeating myself when it comes to types - especially if the types get wordy (collections, etc). Swift is pretty good about it - but these warts stick out. The idea that we should make it *less* good at this really rubs me the wrong way. How many times have you seen lines of code like this in C++-ish/C#-ish languages:

Foo foo = new Foo();

Every time I see that sort of thing, I cringe a little.

IMO if you wanted to be super opinionated, the language would actually warn if you did this:

let foo: Foo = Foo()

And offer a fixit to:

let foo = Foo()

With no warning for things like this because you’re obviously doing something intentional:

let foo: FooSuperclass = Foo()

But I’d settle for no warnings and getting the inference to work in all contexts. :)

l8r
Sean

···

On Apr 10, 2017, at 10:58 AM, Daniel Duan <daniel@duan.org> wrote:

It is helpful in the sense that it tells us what’s really inconsistent: beginner’s have to learn when inference is available when declaring their types. That’s story is sketchy.

On Apr 10, 2017, at 8:55 AM, Sean Heber <sean@fifthace.com> wrote:

This is not really a helpful comment, but: I kinda wish they did.

l8r
Sean

On Apr 10, 2017, at 10:54 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

Neither of these works btw.

func bar(myString = “hello”)
class Baz {
let myString = { return “hello” }()
}

On Apr 9, 2017, at 11:26 PM, Jean-Daniel <mailing@xenonium.com> wrote:

I’m full -1 on this one. It will make the language inconsistent. How do you explain a new comer that type inference work in some case, but not in other cases, while in both the compiler is completely capable to define the type.

Why

let myString = "hello"

would be accepted but not

class Foo {
  let myString = "hello"
}

Le 10 avr. 2017 à 04:05, Daniel Duan via swift-evolution <swift-evolution@swift.org> a écrit :

I’m still not sure whether *I* want this. But here’s a proposal anyways: remove-type-inference-for-stored-proprety.md · GitHub

On Apr 7, 2017, at 12: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:

[swift-evolution] Infer types of default function parameters

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

_______________________________________________
swift-evolution mailing list
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

I’m not questioning the value of type inference in general. Just that there are practical implications when we want more of them. There’s a difference in inferencing type declaration properties and local variables: the former is more likely to be exported and read by others. These arguments are all in the draft proposal.

···

On Apr 10, 2017, at 9:07 AM, Sean Heber <sean@fifthace.com> wrote:

Well, I’m not really a beginner, but for me personally, the computer is here to help me do my work and to do some of the thinking for me. I really hate repeating myself when it comes to types - especially if the types get wordy (collections, etc). Swift is pretty good about it - but these warts stick out. The idea that we should make it *less* good at this really rubs me the wrong way. How many times have you seen lines of code like this in C++-ish/C#-ish languages:

Foo foo = new Foo();

Every time I see that sort of thing, I cringe a little.

IMO if you wanted to be super opinionated, the language would actually warn if you did this:

let foo: Foo = Foo()

And offer a fixit to:

let foo = Foo()

With no warning for things like this because you’re obviously doing something intentional:

let foo: FooSuperclass = Foo()

But I’d settle for no warnings and getting the inference to work in all contexts. :)

l8r
Sean

On Apr 10, 2017, at 10:58 AM, Daniel Duan <daniel@duan.org> wrote:

It is helpful in the sense that it tells us what’s really inconsistent: beginner’s have to learn when inference is available when declaring their types. That’s story is sketchy.

On Apr 10, 2017, at 8:55 AM, Sean Heber <sean@fifthace.com> wrote:

This is not really a helpful comment, but: I kinda wish they did.

l8r
Sean

On Apr 10, 2017, at 10:54 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

Neither of these works btw.

func bar(myString = “hello”)
class Baz {
let myString = { return “hello” }()
}

On Apr 9, 2017, at 11:26 PM, Jean-Daniel <mailing@xenonium.com> wrote:

I’m full -1 on this one. It will make the language inconsistent. How do you explain a new comer that type inference work in some case, but not in other cases, while in both the compiler is completely capable to define the type.

Why

let myString = "hello"

would be accepted but not

class Foo {
  let myString = "hello"
}

Le 10 avr. 2017 à 04:05, Daniel Duan via swift-evolution <swift-evolution@swift.org> a écrit :

I’m still not sure whether *I* want this. But here’s a proposal anyways: remove-type-inference-for-stored-proprety.md · GitHub

On Apr 7, 2017, at 12: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:

[swift-evolution] Infer types of default function parameters

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

_______________________________________________
swift-evolution mailing list
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

I’m not questioning the value of type inference in general. Just that there are practical implications when we want more of them. There’s a difference in inferencing type declaration properties and local variables: the former is more likely to be exported and read by others. These arguments are all in the draft proposal.

When a declaration is exported outside a module whoever is reading it isn’t reading the source directly. They are reading documentation or a generated header of some kind. The annotation can easily be added by tools that produce these.

···

On Apr 10, 2017, at 11:11 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

On Apr 10, 2017, at 9:07 AM, Sean Heber <sean@fifthace.com> wrote:

Well, I’m not really a beginner, but for me personally, the computer is here to help me do my work and to do some of the thinking for me. I really hate repeating myself when it comes to types - especially if the types get wordy (collections, etc). Swift is pretty good about it - but these warts stick out. The idea that we should make it *less* good at this really rubs me the wrong way. How many times have you seen lines of code like this in C++-ish/C#-ish languages:

Foo foo = new Foo();

Every time I see that sort of thing, I cringe a little.

IMO if you wanted to be super opinionated, the language would actually warn if you did this:

let foo: Foo = Foo()

And offer a fixit to:

let foo = Foo()

With no warning for things like this because you’re obviously doing something intentional:

let foo: FooSuperclass = Foo()

But I’d settle for no warnings and getting the inference to work in all contexts. :)

l8r
Sean

On Apr 10, 2017, at 10:58 AM, Daniel Duan <daniel@duan.org> wrote:

It is helpful in the sense that it tells us what’s really inconsistent: beginner’s have to learn when inference is available when declaring their types. That’s story is sketchy.

On Apr 10, 2017, at 8:55 AM, Sean Heber <sean@fifthace.com> wrote:

This is not really a helpful comment, but: I kinda wish they did.

l8r
Sean

On Apr 10, 2017, at 10:54 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

Neither of these works btw.

func bar(myString = “hello”)
class Baz {
let myString = { return “hello” }()
}

On Apr 9, 2017, at 11:26 PM, Jean-Daniel <mailing@xenonium.com> wrote:

I’m full -1 on this one. It will make the language inconsistent. How do you explain a new comer that type inference work in some case, but not in other cases, while in both the compiler is completely capable to define the type.

Why

let myString = "hello"

would be accepted but not

class Foo {
  let myString = "hello"
}

Le 10 avr. 2017 à 04:05, Daniel Duan via swift-evolution <swift-evolution@swift.org> a écrit :

I’m still not sure whether *I* want this. But here’s a proposal anyways: remove-type-inference-for-stored-proprety.md · GitHub

On Apr 7, 2017, at 12: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:

[swift-evolution] Infer types of default function parameters

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

_______________________________________________
swift-evolution mailing list
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

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

I guess I'm using the word "export" loosely. Often times I find myself reading type signatures in my own codebase either because it's written by someone else on my team or by myself long time ago. I think open-source library users have the same problem. Exposure to a particular local variable is less likely.

Daniel Duan

···

Sent from my iPhone

On Apr 10, 2017, at 9:16 AM, Matthew Johnson <matthew@anandabits.com> wrote:

On Apr 10, 2017, at 11:11 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

I’m not questioning the value of type inference in general. Just that there are practical implications when we want more of them. There’s a difference in inferencing type declaration properties and local variables: the former is more likely to be exported and read by others. These arguments are all in the draft proposal.

When a declaration is exported outside a module whoever is reading it isn’t reading the source directly. They are reading documentation or a generated header of some kind. The annotation can easily be added by tools that produce these.

On Apr 10, 2017, at 9:07 AM, Sean Heber <sean@fifthace.com> wrote:

Well, I’m not really a beginner, but for me personally, the computer is here to help me do my work and to do some of the thinking for me. I really hate repeating myself when it comes to types - especially if the types get wordy (collections, etc). Swift is pretty good about it - but these warts stick out. The idea that we should make it *less* good at this really rubs me the wrong way. How many times have you seen lines of code like this in C++-ish/C#-ish languages:

Foo foo = new Foo();

Every time I see that sort of thing, I cringe a little.

IMO if you wanted to be super opinionated, the language would actually warn if you did this:

let foo: Foo = Foo()

And offer a fixit to:

let foo = Foo()

With no warning for things like this because you’re obviously doing something intentional:

let foo: FooSuperclass = Foo()

But I’d settle for no warnings and getting the inference to work in all contexts. :)

l8r
Sean

On Apr 10, 2017, at 10:58 AM, Daniel Duan <daniel@duan.org> wrote:

It is helpful in the sense that it tells us what’s really inconsistent: beginner’s have to learn when inference is available when declaring their types. That’s story is sketchy.

On Apr 10, 2017, at 8:55 AM, Sean Heber <sean@fifthace.com> wrote:

This is not really a helpful comment, but: I kinda wish they did.

l8r
Sean

On Apr 10, 2017, at 10:54 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

Neither of these works btw.

func bar(myString = “hello”)
class Baz {
let myString = { return “hello” }()
}

On Apr 9, 2017, at 11:26 PM, Jean-Daniel <mailing@xenonium.com> wrote:

I’m full -1 on this one. It will make the language inconsistent. How do you explain a new comer that type inference work in some case, but not in other cases, while in both the compiler is completely capable to define the type.

Why

let myString = "hello"

would be accepted but not

class Foo {
   let myString = "hello"
}

Le 10 avr. 2017 à 04:05, Daniel Duan via swift-evolution <swift-evolution@swift.org> a écrit :

I’m still not sure whether *I* want this. But here’s a proposal anyways: remove-type-inference-for-stored-proprety.md · GitHub

On Apr 7, 2017, at 12: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:

[swift-evolution] Infer types of default function parameters

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

_______________________________________________
swift-evolution mailing list
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

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

I guess I'm using the word "export" loosely. Often times I find myself reading type signatures in my own codebase either because it's written by someone else on my team or by myself long time ago. I think open-source library users have the same problem. Exposure to a particular local variable is less likely.

If you’re reading code in a codebase you work on most of the time you’ll be reading it using a tool that can give you the annotation using something like opt-click in Xcode. I don’t think it’s worth cluttering up our code with annotations that are readily available to most readers. Most of the time annotations introduce noise that reduces clarity. I don’t think relying on tools in the occasional case where the type isn’t obvious to an individual reader is a bad thing.

···

On Apr 10, 2017, at 11:22 AM, Daniel Duan <daniel@duan.org> wrote:

Daniel Duan
Sent from my iPhone

On Apr 10, 2017, at 9:16 AM, Matthew Johnson <matthew@anandabits.com> wrote:

On Apr 10, 2017, at 11:11 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

I’m not questioning the value of type inference in general. Just that there are practical implications when we want more of them. There’s a difference in inferencing type declaration properties and local variables: the former is more likely to be exported and read by others. These arguments are all in the draft proposal.

When a declaration is exported outside a module whoever is reading it isn’t reading the source directly. They are reading documentation or a generated header of some kind. The annotation can easily be added by tools that produce these.

On Apr 10, 2017, at 9:07 AM, Sean Heber <sean@fifthace.com> wrote:

Well, I’m not really a beginner, but for me personally, the computer is here to help me do my work and to do some of the thinking for me. I really hate repeating myself when it comes to types - especially if the types get wordy (collections, etc). Swift is pretty good about it - but these warts stick out. The idea that we should make it *less* good at this really rubs me the wrong way. How many times have you seen lines of code like this in C++-ish/C#-ish languages:

Foo foo = new Foo();

Every time I see that sort of thing, I cringe a little.

IMO if you wanted to be super opinionated, the language would actually warn if you did this:

let foo: Foo = Foo()

And offer a fixit to:

let foo = Foo()

With no warning for things like this because you’re obviously doing something intentional:

let foo: FooSuperclass = Foo()

But I’d settle for no warnings and getting the inference to work in all contexts. :)

l8r
Sean

On Apr 10, 2017, at 10:58 AM, Daniel Duan <daniel@duan.org> wrote:

It is helpful in the sense that it tells us what’s really inconsistent: beginner’s have to learn when inference is available when declaring their types. That’s story is sketchy.

On Apr 10, 2017, at 8:55 AM, Sean Heber <sean@fifthace.com> wrote:

This is not really a helpful comment, but: I kinda wish they did.

l8r
Sean

On Apr 10, 2017, at 10:54 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

Neither of these works btw.

func bar(myString = “hello”)
class Baz {
let myString = { return “hello” }()
}

On Apr 9, 2017, at 11:26 PM, Jean-Daniel <mailing@xenonium.com> wrote:

I’m full -1 on this one. It will make the language inconsistent. How do you explain a new comer that type inference work in some case, but not in other cases, while in both the compiler is completely capable to define the type.

Why

let myString = "hello"

would be accepted but not

class Foo {
  let myString = "hello"
}

Le 10 avr. 2017 à 04:05, Daniel Duan via swift-evolution <swift-evolution@swift.org> a écrit :

I’m still not sure whether *I* want this. But here’s a proposal anyways: remove-type-inference-for-stored-proprety.md · GitHub

On Apr 7, 2017, at 12: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:

[swift-evolution] Infer types of default function parameters

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

_______________________________________________
swift-evolution mailing list
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

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

Using tools isn't a bad thing. Designing language assuming users are using tools with certain capability is kind of a bad thing.

Where tools *can* help is if the tools enhance the language user's experience, which is why I proposed the inference capabilities be kept for diagnostics.

I also disagree with the characterization that types in properties is "clustering up" the code. The value inference provided here is make the authoring experience better. I can see for obvious default expressions (string/number literal perhaps) the readability isn't degraded by too much. But it's not as clear as explicit types for the *reader*.

Daniel Duan

···

Sent from my iPhone

On Apr 10, 2017, at 9:26 AM, Matthew Johnson <matthew@anandabits.com> wrote:

On Apr 10, 2017, at 11:22 AM, Daniel Duan <daniel@duan.org> wrote:

I guess I'm using the word "export" loosely. Often times I find myself reading type signatures in my own codebase either because it's written by someone else on my team or by myself long time ago. I think open-source library users have the same problem. Exposure to a particular local variable is less likely.

If you’re reading code in a codebase you work on most of the time you’ll be reading it using a tool that can give you the annotation using something like opt-click in Xcode. I don’t think it’s worth cluttering up our code with annotations that are readily available to most readers. Most of the time annotations introduce noise that reduces clarity. I don’t think relying on tools in the occasional case where the type isn’t obvious to an individual reader is a bad thing.

Daniel Duan
Sent from my iPhone

On Apr 10, 2017, at 9:16 AM, Matthew Johnson <matthew@anandabits.com> wrote:

On Apr 10, 2017, at 11:11 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

I’m not questioning the value of type inference in general. Just that there are practical implications when we want more of them. There’s a difference in inferencing type declaration properties and local variables: the former is more likely to be exported and read by others. These arguments are all in the draft proposal.

When a declaration is exported outside a module whoever is reading it isn’t reading the source directly. They are reading documentation or a generated header of some kind. The annotation can easily be added by tools that produce these.

On Apr 10, 2017, at 9:07 AM, Sean Heber <sean@fifthace.com> wrote:

Well, I’m not really a beginner, but for me personally, the computer is here to help me do my work and to do some of the thinking for me. I really hate repeating myself when it comes to types - especially if the types get wordy (collections, etc). Swift is pretty good about it - but these warts stick out. The idea that we should make it *less* good at this really rubs me the wrong way. How many times have you seen lines of code like this in C++-ish/C#-ish languages:

Foo foo = new Foo();

Every time I see that sort of thing, I cringe a little.

IMO if you wanted to be super opinionated, the language would actually warn if you did this:

let foo: Foo = Foo()

And offer a fixit to:

let foo = Foo()

With no warning for things like this because you’re obviously doing something intentional:

let foo: FooSuperclass = Foo()

But I’d settle for no warnings and getting the inference to work in all contexts. :)

l8r
Sean

On Apr 10, 2017, at 10:58 AM, Daniel Duan <daniel@duan.org> wrote:

It is helpful in the sense that it tells us what’s really inconsistent: beginner’s have to learn when inference is available when declaring their types. That’s story is sketchy.

On Apr 10, 2017, at 8:55 AM, Sean Heber <sean@fifthace.com> wrote:

This is not really a helpful comment, but: I kinda wish they did.

l8r
Sean

On Apr 10, 2017, at 10:54 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

Neither of these works btw.

func bar(myString = “hello”)
class Baz {
let myString = { return “hello” }()
}

On Apr 9, 2017, at 11:26 PM, Jean-Daniel <mailing@xenonium.com> wrote:

I’m full -1 on this one. It will make the language inconsistent. How do you explain a new comer that type inference work in some case, but not in other cases, while in both the compiler is completely capable to define the type.

Why

let myString = "hello"

would be accepted but not

class Foo {
  let myString = "hello"
}

Le 10 avr. 2017 à 04:05, Daniel Duan via swift-evolution <swift-evolution@swift.org> a écrit :

I’m still not sure whether *I* want this. But here’s a proposal anyways: remove-type-inference-for-stored-proprety.md · GitHub

On Apr 7, 2017, at 12: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:

[swift-evolution] Infer types of default function parameters

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

_______________________________________________
swift-evolution mailing list
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

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

Using tools isn't a bad thing. Designing language assuming users are using tools with certain capability is kind of a bad thing.

Where tools *can* help is if the tools enhance the language user's experience, which is why I proposed the inference capabilities be kept for diagnostics.

I also disagree with the characterization that types in properties is "clustering up" the code. The value inference provided here is make the authoring experience better. I can see for obvious default expressions (string/number literal perhaps) the readability isn't degraded by too much. But it's not as clear as explicit types for the *reader*.

I said “cluttering”, not “clustering” (which has a more derogatory implication for many people).

In any case, this is an area where there are differing perspectives each with some merit. I think it’s best to leave it up to each of us what makes the most sense for our code. IMO, and that of at least some others who have commented, some code is more clear to readers with annotations and some is more clear to readers without annotations.

Like I said earlier, I’m willing to keep an open mind on proposals in this area but I don’t support a wholesale ban on inference directly initialized member declarations. It may not be possible to do something less than a wholesale ban without introducing more confusion than we have today as to when inference is permitted and when it isn’t. If it isn’t that’s ok with me. If it is, I’ll consider such a proposal on its merit if one is brought forward.

···

On Apr 10, 2017, at 11:38 AM, Daniel Duan <daniel@duan.org> wrote:

Daniel Duan
Sent from my iPhone

On Apr 10, 2017, at 9:26 AM, Matthew Johnson <matthew@anandabits.com <mailto:matthew@anandabits.com>> wrote:

On Apr 10, 2017, at 11:22 AM, Daniel Duan <daniel@duan.org <mailto:daniel@duan.org>> wrote:

I guess I'm using the word "export" loosely. Often times I find myself reading type signatures in my own codebase either because it's written by someone else on my team or by myself long time ago. I think open-source library users have the same problem. Exposure to a particular local variable is less likely.

If you’re reading code in a codebase you work on most of the time you’ll be reading it using a tool that can give you the annotation using something like opt-click in Xcode. I don’t think it’s worth cluttering up our code with annotations that are readily available to most readers. Most of the time annotations introduce noise that reduces clarity. I don’t think relying on tools in the occasional case where the type isn’t obvious to an individual reader is a bad thing.

Daniel Duan
Sent from my iPhone

On Apr 10, 2017, at 9:16 AM, Matthew Johnson <matthew@anandabits.com <mailto:matthew@anandabits.com>> wrote:

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

I’m not questioning the value of type inference in general. Just that there are practical implications when we want more of them. There’s a difference in inferencing type declaration properties and local variables: the former is more likely to be exported and read by others. These arguments are all in the draft proposal.

When a declaration is exported outside a module whoever is reading it isn’t reading the source directly. They are reading documentation or a generated header of some kind. The annotation can easily be added by tools that produce these.

On Apr 10, 2017, at 9:07 AM, Sean Heber <sean@fifthace.com <mailto:sean@fifthace.com>> wrote:

Well, I’m not really a beginner, but for me personally, the computer is here to help me do my work and to do some of the thinking for me. I really hate repeating myself when it comes to types - especially if the types get wordy (collections, etc). Swift is pretty good about it - but these warts stick out. The idea that we should make it *less* good at this really rubs me the wrong way. How many times have you seen lines of code like this in C++-ish/C#-ish languages:

Foo foo = new Foo();

Every time I see that sort of thing, I cringe a little.

IMO if you wanted to be super opinionated, the language would actually warn if you did this:

let foo: Foo = Foo()

And offer a fixit to:

let foo = Foo()

With no warning for things like this because you’re obviously doing something intentional:

let foo: FooSuperclass = Foo()

But I’d settle for no warnings and getting the inference to work in all contexts. :)

l8r
Sean

On Apr 10, 2017, at 10:58 AM, Daniel Duan <daniel@duan.org <mailto:daniel@duan.org>> wrote:

It is helpful in the sense that it tells us what’s really inconsistent: beginner’s have to learn when inference is available when declaring their types. That’s story is sketchy.

On Apr 10, 2017, at 8:55 AM, Sean Heber <sean@fifthace.com <mailto:sean@fifthace.com>> wrote:

This is not really a helpful comment, but: I kinda wish they did.

l8r
Sean

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

Neither of these works btw.

func bar(myString = “hello”)
class Baz {
let myString = { return “hello” }()
}

On Apr 9, 2017, at 11:26 PM, Jean-Daniel <mailing@xenonium.com <mailto:mailing@xenonium.com>> wrote:

I’m full -1 on this one. It will make the language inconsistent. How do you explain a new comer that type inference work in some case, but not in other cases, while in both the compiler is completely capable to define the type.

Why

let myString = "hello"

would be accepted but not

class Foo {
  let myString = "hello"
}

Le 10 avr. 2017 à 04:05, Daniel Duan via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> a écrit :

I’m still not sure whether *I* want this. But here’s a proposal anyways: remove-type-inference-for-stored-proprety.md · GitHub

On Apr 7, 2017, at 12: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:

[swift-evolution] Infer types of default function parameters

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 <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
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 <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

I see this sentiment on this list a lot. Where does it come from? Is there any supporting research? What drives it?

(I don’t mean to pick on Daniel - I’m curious about this overall from anyone that has sources. It has become such a prevailing refrain at times that I think it’d be best for everyone if we knew if it was even true!)

l8r
Sean

···

On Apr 10, 2017, at 11:38 AM, Daniel Duan <daniel@duan.org> wrote:

Using tools isn't a bad thing. Designing language assuming users are using tools with certain capability is kind of a bad thing.

That's kind of my perspective too. Personally I adore this feature. But compiling speed is such a severe issue at work that I'm willing to part with it. (Not saying other arguments aren't important).

I'm lucky enough to work on a project that is:
1. purely Swift
2. Vigilantly monitored for compilation slow-down from complex expressions
3. Really large (enough that compiling speed is a severe problem).

I think with time more and more ppl will experience the same thing.

As I noted in the proposal, swiftc has space for speed improvement in this area and I believe the implementators will get there. In the mean time inference may still pose a theoretic performance upper bound.

Daniel Duan

···

Sent from my iPhone

On Apr 10, 2017, at 9:51 AM, Matthew Johnson <matthew@anandabits.com> wrote:

On Apr 10, 2017, at 11:38 AM, Daniel Duan <daniel@duan.org> wrote:

Using tools isn't a bad thing. Designing language assuming users are using tools with certain capability is kind of a bad thing.

Where tools *can* help is if the tools enhance the language user's experience, which is why I proposed the inference capabilities be kept for diagnostics.

I also disagree with the characterization that types in properties is "clustering up" the code. The value inference provided here is make the authoring experience better. I can see for obvious default expressions (string/number literal perhaps) the readability isn't degraded by too much. But it's not as clear as explicit types for the *reader*.

I said “cluttering”, not “clustering” (which has a more derogatory implication for many people).

In any case, this is an area where there are differing perspectives each with some merit. I think it’s best to leave it up to each of us what makes the most sense for our code. IMO, and that of at least some others who have commented, some code is more clear to readers with annotations and some is more clear to readers without annotations.

Like I said earlier, I’m willing to keep an open mind on proposals in this area but I don’t support a wholesale ban on inference directly initialized member declarations. It may not be possible to do something less than a wholesale ban without introducing more confusion than we have today as to when inference is permitted and when it isn’t. If it isn’t that’s ok with me. If it is, I’ll consider such a proposal on its merit if one is brought forward.

Daniel Duan
Sent from my iPhone

On Apr 10, 2017, at 9:26 AM, Matthew Johnson <matthew@anandabits.com> wrote:

On Apr 10, 2017, at 11:22 AM, Daniel Duan <daniel@duan.org> wrote:

I guess I'm using the word "export" loosely. Often times I find myself reading type signatures in my own codebase either because it's written by someone else on my team or by myself long time ago. I think open-source library users have the same problem. Exposure to a particular local variable is less likely.

If you’re reading code in a codebase you work on most of the time you’ll be reading it using a tool that can give you the annotation using something like opt-click in Xcode. I don’t think it’s worth cluttering up our code with annotations that are readily available to most readers. Most of the time annotations introduce noise that reduces clarity. I don’t think relying on tools in the occasional case where the type isn’t obvious to an individual reader is a bad thing.

Daniel Duan
Sent from my iPhone

On Apr 10, 2017, at 9:16 AM, Matthew Johnson <matthew@anandabits.com> wrote:

On Apr 10, 2017, at 11:11 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

I’m not questioning the value of type inference in general. Just that there are practical implications when we want more of them. There’s a difference in inferencing type declaration properties and local variables: the former is more likely to be exported and read by others. These arguments are all in the draft proposal.

When a declaration is exported outside a module whoever is reading it isn’t reading the source directly. They are reading documentation or a generated header of some kind. The annotation can easily be added by tools that produce these.

On Apr 10, 2017, at 9:07 AM, Sean Heber <sean@fifthace.com> wrote:

Well, I’m not really a beginner, but for me personally, the computer is here to help me do my work and to do some of the thinking for me. I really hate repeating myself when it comes to types - especially if the types get wordy (collections, etc). Swift is pretty good about it - but these warts stick out. The idea that we should make it *less* good at this really rubs me the wrong way. How many times have you seen lines of code like this in C++-ish/C#-ish languages:

Foo foo = new Foo();

Every time I see that sort of thing, I cringe a little.

IMO if you wanted to be super opinionated, the language would actually warn if you did this:

let foo: Foo = Foo()

And offer a fixit to:

let foo = Foo()

With no warning for things like this because you’re obviously doing something intentional:

let foo: FooSuperclass = Foo()

But I’d settle for no warnings and getting the inference to work in all contexts. :)

l8r
Sean

On Apr 10, 2017, at 10:58 AM, Daniel Duan <daniel@duan.org> wrote:

It is helpful in the sense that it tells us what’s really inconsistent: beginner’s have to learn when inference is available when declaring their types. That’s story is sketchy.

On Apr 10, 2017, at 8:55 AM, Sean Heber <sean@fifthace.com> wrote:

This is not really a helpful comment, but: I kinda wish they did.

l8r
Sean

On Apr 10, 2017, at 10:54 AM, Daniel Duan via swift-evolution <swift-evolution@swift.org> wrote:

Neither of these works btw.

func bar(myString = “hello”)
class Baz {
let myString = { return “hello” }()
}

On Apr 9, 2017, at 11:26 PM, Jean-Daniel <mailing@xenonium.com> wrote:

I’m full -1 on this one. It will make the language inconsistent. How do you explain a new comer that type inference work in some case, but not in other cases, while in both the compiler is completely capable to define the type.

Why

let myString = "hello"

would be accepted but not

class Foo {
  let myString = "hello"
}

Le 10 avr. 2017 à 04:05, Daniel Duan via swift-evolution <swift-evolution@swift.org> a écrit :

I’m still not sure whether *I* want this. But here’s a proposal anyways: remove-type-inference-for-stored-proprety.md · GitHub

On Apr 7, 2017, at 12: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:

[swift-evolution] Infer types of default function parameters

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

_______________________________________________
swift-evolution mailing list
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

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