Removing explicit use of `let` from Function Parameters


(Nicholas Maccharoli) #1

​As a follow-up to proposal SE-0003​: "Removing var from Function
Parameters" being accepted,
I think it might make sense to disallow explicitly declaring function
parameters with the `let` keyword since function parameters are immutable
by default.

Basically disallow writing functions like this:

func foo(let i: Int) { ... }

and only allow the function above to be expressed as this:

func foo(i: Int) { ... }

​- Nick​


(Adrian Kashivskyy) #2

+1, this should be consistent.

P.S. Finally somebody wrote an email using non-black Comic Sans. :joy:

Pozdrawiam – Regards,
Adrian Kashivskyy

···

Wiadomość napisana przez Nicholas Maccharoli via swift-evolution <swift-evolution@swift.org> w dniu 17.03.2016, o godz. 09:27:

​As a follow-up to proposal SE-0003​: "Removing var from Function Parameters" being accepted,
I think it might make sense to disallow explicitly declaring function parameters with the `let` keyword since function parameters are immutable by default.

Basically disallow writing functions like this:

func foo(let i: Int) { ... }

and only allow the function above to be expressed as this:

func foo(i: Int) { ... }

​- Nick​

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


(Douglas Gregor) #3

This makes perfect sense to me. Want to write up a proposal?

  - Doug

···

On Mar 17, 2016, at 1:27 AM, Nicholas Maccharoli via swift-evolution <swift-evolution@swift.org> wrote:

​As a follow-up to proposal SE-0003​: "Removing var from Function Parameters" being accepted,
I think it might make sense to disallow explicitly declaring function parameters with the `let` keyword since function parameters are immutable by default.

Basically disallow writing functions like this:

func foo(let i: Int) { ... }

and only allow the function above to be expressed as this:

func foo(i: Int) { … }


(Harlan Haskins) #4

Since we’re allowing keywords as argument names, shouldn’t this:

func foo(let i: Int)

be allowed, such that it’ll be called as this:

foo(let: 3)

— Harlan

···

On Mar 17, 2016, at 11:08 AM, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:

On Mar 17, 2016, at 1:27 AM, Nicholas Maccharoli via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

​As a follow-up to proposal SE-0003​: "Removing var from Function Parameters" being accepted,
I think it might make sense to disallow explicitly declaring function parameters with the `let` keyword since function parameters are immutable by default.

Basically disallow writing functions like this:

func foo(let i: Int) { ... }

and only allow the function above to be expressed as this:

func foo(i: Int) { … }

This makes perfect sense to me. Want to write up a proposal?

  - Doug

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


(Douglas Gregor) #5

Since we’re allowing keywords as argument names, shouldn’t this:

func foo(let i: Int)

Right now, you’d have to declare this as

  func foo(`let` i: Int)

but the proposal would fix that.

be allowed, such that it’ll be called as this:

foo(let: 3)

Right.

  - Doug

···

On Mar 17, 2016, at 11:22 AM, Harlan Haskins <harlan@harlanhaskins.com> wrote:

— Harlan

On Mar 17, 2016, at 11:08 AM, Douglas Gregor via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

On Mar 17, 2016, at 1:27 AM, Nicholas Maccharoli via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

​As a follow-up to proposal SE-0003​: "Removing var from Function Parameters" being accepted,
I think it might make sense to disallow explicitly declaring function parameters with the `let` keyword since function parameters are immutable by default.

Basically disallow writing functions like this:

func foo(let i: Int) { ... }

and only allow the function above to be expressed as this:

func foo(i: Int) { … }

This makes perfect sense to me. Want to write up a proposal?

  - Doug

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


(Douglas Gregor) #6

The three reserved words are, if memory serves: let, var, and inout

var is gone. this would kill let. and `inout` is moved to modify types.

So by upending this part of the language we've managed to remove the special cases for argument labels. I view that as success.

  - Doug

···

Sent from my iPhone

On Mar 17, 2016, at 11:49 AM, Erica Sadun <erica@ericasadun.com> wrote:

-- E

On Mar 17, 2016, at 12:26 PM, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:

On Mar 17, 2016, at 11:22 AM, Harlan Haskins <harlan@harlanhaskins.com> wrote:

Since we’re allowing keywords as argument names, shouldn’t this:

func foo(let i: Int)

Right now, you’d have to declare this as

  func foo(`let` i: Int)

but the proposal would fix that.

be allowed, such that it’ll be called as this:

foo(let: 3)

Right.

  - Doug


(Erica Sadun) #7

The three reserved words are, if memory serves: let, var, and inout

var is gone. this would kill let. and `inout` is moved to modify types.

-- E

···

On Mar 17, 2016, at 12:26 PM, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:

On Mar 17, 2016, at 11:22 AM, Harlan Haskins <harlan@harlanhaskins.com <mailto:harlan@harlanhaskins.com>> wrote:

Since we’re allowing keywords as argument names, shouldn’t this:

func foo(let i: Int)

Right now, you’d have to declare this as

  func foo(`let` i: Int)

but the proposal would fix that.

be allowed, such that it’ll be called as this:

foo(let: 3)

Right.

  - Doug


(Erica Sadun) #8

Sent from my iPhone

The three reserved words are, if memory serves: let, var, and inout

var is gone. this would kill let. and `inout` is moved to modify types.

So by upending this part of the language we've managed to remove the special cases for argument labels. I view that as success.

  - Doug

Agreed.

If Nicholas doesn't bite, I'm happy to throw this one into the "SadunProposalGeneratorType" instance.
I think I can write proposals now in my sleep and this is one that just seems to have an absolute beautiful
resonance with clarifying the language and letting the special cases disappear into the aether.

-- E

···

On Mar 17, 2016, at 12:58 PM, Douglas Gregor <dgregor@apple.com> wrote:
On Mar 17, 2016, at 11:49 AM, Erica Sadun <erica@ericasadun.com <mailto:erica@ericasadun.com>> wrote:


(Chris Lattner) #9

The intention was for this to be included as part of SE-0003. If it wasn’t, then that was an accidental omission. Do we really need a full proposal for that?

-Chris

···

On Mar 17, 2016, at 11:08 AM, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:

On Mar 17, 2016, at 1:27 AM, Nicholas Maccharoli via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

​As a follow-up to proposal SE-0003​: "Removing var from Function Parameters" being accepted,
I think it might make sense to disallow explicitly declaring function parameters with the `let` keyword since function parameters are immutable by default.

Basically disallow writing functions like this:

func foo(let i: Int) { ... }

and only allow the function above to be expressed as this:

func foo(i: Int) { … }

This makes perfect sense to me. Want to write up a proposal?


(Nicholas Maccharoli) #10

Thank you for the feedback!

I checked SE-0003 again and didnt see explicit mention of this.

I would like to write up a quick proposal today if its ok.

Chris, I promise to make it very concise is it ok to send over a PR to
swift evolution?

- Nick

2016年3月18日金曜日、Chris Lattner<clattner@apple.com>さんは書きました:

···

On Mar 17, 2016, at 11:08 AM, Douglas Gregor via swift-evolution < > swift-evolution@swift.org > <javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');>> wrote:

On Mar 17, 2016, at 1:27 AM, Nicholas Maccharoli via swift-evolution < > swift-evolution@swift.org > <javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');>> wrote:

​As a follow-up to proposal SE-0003​: "Removing var from Function
Parameters" being accepted,
I think it might make sense to disallow explicitly declaring function
parameters with the `let` keyword since function parameters are immutable
by default.

Basically disallow writing functions like this:

func foo(let i: Int) { ... }

and only allow the function above to be expressed as this:

func foo(i: Int) { … }

This makes perfect sense to me. Want to write up a proposal?

The intention was for this to be included as part of SE-0003. If it
wasn’t, then that was an accidental omission. Do we really need a full
proposal for that?

-Chris

--

All the best,

Nicholas

Linked in:
http://lnkd.in/328U22


(Chris Lattner) #11

Sure, I’m ok with that if that is what Doug prefers.

-Chris

···

On Mar 17, 2016, at 4:54 PM, Nicholas Maccharoli <nmaccharoli@gmail.com> wrote:

Thank you for the feedback!

I checked SE-0003 again and didnt see explicit mention of this.

I would like to write up a quick proposal today if its ok.

Chris, I promise to make it very concise is it ok to send over a PR to swift evolution?

- Nick

2016年3月18日金曜日、Chris Lattner<clattner@apple.com <mailto:clattner@apple.com>>さんは書きました:

On Mar 17, 2016, at 11:08 AM, Douglas Gregor via swift-evolution <swift-evolution@swift.org <javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');>> wrote:

On Mar 17, 2016, at 1:27 AM, Nicholas Maccharoli via swift-evolution <swift-evolution@swift.org <javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');>> wrote:

​As a follow-up to proposal SE-0003​: "Removing var from Function Parameters" being accepted,
I think it might make sense to disallow explicitly declaring function parameters with the `let` keyword since function parameters are immutable by default.

Basically disallow writing functions like this:

func foo(let i: Int) { ... }

and only allow the function above to be expressed as this:

func foo(i: Int) { … }

This makes perfect sense to me. Want to write up a proposal?

The intention was for this to be included as part of SE-0003. If it wasn’t, then that was an accidental omission. Do we really need a full proposal for that?

-Chris

--

All the best,

Nicholas

Linked in:
http://lnkd.in/328U22


(Douglas Gregor) #12

Yes, please file a PR.

···

Sent from my iPhone

On Mar 17, 2016, at 5:05 PM, Chris Lattner <clattner@apple.com> wrote:

Sure, I’m ok with that if that is what Doug prefers.

-Chris

On Mar 17, 2016, at 4:54 PM, Nicholas Maccharoli <nmaccharoli@gmail.com> wrote:

Thank you for the feedback!

I checked SE-0003 again and didnt see explicit mention of this.

I would like to write up a quick proposal today if its ok.

Chris, I promise to make it very concise is it ok to send over a PR to swift evolution?

- Nick

2016年3月18日金曜日、Chris Lattner<clattner@apple.com>さんは書きました:

On Mar 17, 2016, at 11:08 AM, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:

On Mar 17, 2016, at 1:27 AM, Nicholas Maccharoli via swift-evolution <swift-evolution@swift.org> wrote:

​As a follow-up to proposal SE-0003​: "Removing var from Function Parameters" being accepted,
I think it might make sense to disallow explicitly declaring function parameters with the `let` keyword since function parameters are immutable by default.

Basically disallow writing functions like this:

func foo(let i: Int) { ... }

and only allow the function above to be expressed as this:

func foo(i: Int) { … }

This makes perfect sense to me. Want to write up a proposal?

The intention was for this to be included as part of SE-0003. If it wasn’t, then that was an accidental omission. Do we really need a full proposal for that?

-Chris

--

All the best,

Nicholas

Linked in:
http://lnkd.in/328U22


(Nicholas Maccharoli) #13

Thank you!

I have filed a PR here: https://github.com/apple/swift-evolution/pull/215

How does it look?

- Nick

All the best,

Nicholas

Linked in:
http://lnkd.in/328U22

···

On Fri, Mar 18, 2016 at 9:07 AM, Douglas Gregor <dgregor@apple.com> wrote:

Yes, please file a PR.

Sent from my iPhone

On Mar 17, 2016, at 5:05 PM, Chris Lattner <clattner@apple.com> wrote:

Sure, I’m ok with that if that is what Doug prefers.

-Chris

On Mar 17, 2016, at 4:54 PM, Nicholas Maccharoli <nmaccharoli@gmail.com> > wrote:

Thank you for the feedback!

I checked SE-0003 again and didnt see explicit mention of this.

I would like to write up a quick proposal today if its ok.

Chris, I promise to make it very concise is it ok to send over a PR to
swift evolution?

- Nick

2016年3月18日金曜日、Chris Lattner<clattner@apple.com>さんは書きました:

On Mar 17, 2016, at 11:08 AM, Douglas Gregor via swift-evolution < >> swift-evolution@swift.org> wrote:

On Mar 17, 2016, at 1:27 AM, Nicholas Maccharoli via swift-evolution < >> swift-evolution@swift.org> wrote:

​As a follow-up to proposal SE-0003​: "Removing var from Function
Parameters" being accepted,
I think it might make sense to disallow explicitly declaring function
parameters with the `let` keyword since function parameters are immutable
by default.

Basically disallow writing functions like this:

func foo(let i: Int) { ... }

and only allow the function above to be expressed as this:

func foo(i: Int) { … }

This makes perfect sense to me. Want to write up a proposal?

The intention was for this to be included as part of SE-0003. If it
wasn’t, then that was an accidental omission. Do we really need a full
proposal for that?

-Chris

--

All the best,

Nicholas

Linked in:
http://lnkd.in/328U22


(Douglas Gregor) #14

Looks great, thanks!

  - Doug

···

On Mar 17, 2016, at 9:45 PM, Nicholas Maccharoli <nmaccharoli@gmail.com> wrote:

Thank you!

I have filed a PR here: https://github.com/apple/swift-evolution/pull/215

How does it look?

- Nick

All the best,

Nicholas

Linked in:
http://lnkd.in/328U22

On Fri, Mar 18, 2016 at 9:07 AM, Douglas Gregor <dgregor@apple.com <mailto:dgregor@apple.com>> wrote:
Yes, please file a PR.

Sent from my iPhone

On Mar 17, 2016, at 5:05 PM, Chris Lattner <clattner@apple.com <mailto:clattner@apple.com>> wrote:

Sure, I’m ok with that if that is what Doug prefers.

-Chris

On Mar 17, 2016, at 4:54 PM, Nicholas Maccharoli <nmaccharoli@gmail.com <mailto:nmaccharoli@gmail.com>> wrote:

Thank you for the feedback!

I checked SE-0003 again and didnt see explicit mention of this.

I would like to write up a quick proposal today if its ok.

Chris, I promise to make it very concise is it ok to send over a PR to swift evolution?

- Nick

2016年3月18日金曜日、Chris Lattner<clattner@apple.com <mailto:clattner@apple.com>>さんは書きました:

On Mar 17, 2016, at 11:08 AM, Douglas Gregor via swift-evolution <swift-evolution@swift.org <>> wrote:

On Mar 17, 2016, at 1:27 AM, Nicholas Maccharoli via swift-evolution <swift-evolution@swift.org <>> wrote:

​As a follow-up to proposal SE-0003​: "Removing var from Function Parameters" being accepted,
I think it might make sense to disallow explicitly declaring function parameters with the `let` keyword since function parameters are immutable by default.

Basically disallow writing functions like this:

func foo(let i: Int) { ... }

and only allow the function above to be expressed as this:

func foo(i: Int) { … }

This makes perfect sense to me. Want to write up a proposal?

The intention was for this to be included as part of SE-0003. If it wasn’t, then that was an accidental omission. Do we really need a full proposal for that?

-Chris

--

All the best,

Nicholas

Linked in:
http://lnkd.in/328U22


(Erica Sadun) #15

Because the proposals act as documentation for the evolution process, I think it may be worth
expanding the motivation section and the impact on existing code slightly.

You mention SE-0003 <https://github.com/apple/swift-evolution/blob/master/proposals/0003-remove-var-parameters.md> which removed var parameters and state "it would make sense
that the syntax for function parameters being explicitly declared as `let` would be removed as well."

I think it may be worth adding that SE-0001 <https://github.com/apple/swift-evolution/blob/master/proposals/0001-keywords-as-argument-labels.md> restricted `inout`, `var`, and `let` as argument labels.
SE-0003 removed `var, and SE-0031 <https://github.com/apple/swift-evolution/blob/master/proposals/0031-adjusting-inout-declarations.md> moved `inout` declarations to the type, leaving `let`
as the last remaining exception to SE-0001. Removing it reverts SE-0001 to a clear implementation
without special cases.

You might also mention `let` in its current use is redundant since its inclusion does not and
cannot modify the behavior of the declaration it decorates. It is rarely if ever used and in the
circumstances when added produces no positive contribution to the language since the behavior
is identical to its absence.

In the Impact on Existing Code section, you suggest "The `let` keword would have to be deleted if
placed before a function parameter." I'd recommend mentioning the migrator specifically and
adding that if not migrated, the let will be be now be interpreted as an external label.

-- E, who probably thought about this one a little too hard

···

On Mar 17, 2016, at 10:45 PM, Nicholas Maccharoli via swift-evolution <swift-evolution@swift.org> wrote:

Thank you!

I have filed a PR here: https://github.com/apple/swift-evolution/pull/215

How does it look?

- Nick


(Nicholas Maccharoli) #16

Thanks for the pointers Erica!
I have updated the motivation section and the section on the impact on
existing code.

How does the proposal look now?

- Nick

All the best,

Nicholas

Linked in:
http://lnkd.in/328U22

···

On Fri, Mar 18, 2016 at 11:33 PM, Erica Sadun <erica@ericasadun.com> wrote:

On Mar 17, 2016, at 10:45 PM, Nicholas Maccharoli via swift-evolution < > swift-evolution@swift.org> wrote:

Thank you!

I have filed a PR here: https://github.com/apple/swift-evolution/pull/215

How does it look?

- Nick

Because the proposals act as documentation for the evolution process, I
think it may be worth
expanding the motivation section and the impact on existing code slightly.

You mention SE-0003
<https://github.com/apple/swift-evolution/blob/master/proposals/0003-remove-var-parameters.md> which
removed var parameters and state "it would make sense
that the syntax for function parameters being explicitly declared as
`let` would be removed as well."

I think it may be worth adding that SE-0001
<https://github.com/apple/swift-evolution/blob/master/proposals/0001-keywords-as-argument-labels.md> restricted
`inout`, `var`, and `let` as argument labels.
SE-0003 removed `var, and SE-0031
<https://github.com/apple/swift-evolution/blob/master/proposals/0031-adjusting-inout-declarations.md> moved
`inout` declarations to the type, leaving `let`
as the last remaining exception to SE-0001. Removing it reverts SE-0001
to a clear implementation
without special cases.

You might also mention `let` in its current use is redundant since its
inclusion does not and
cannot modify the behavior of the declaration it decorates. It is rarely
if ever used and in the
circumstances when added produces no positive contribution to the
language since the behavior
is identical to its absence.

In the Impact on Existing Code section, you suggest "The `let` keword
would have to be deleted if
placed before a function parameter." I'd recommend mentioning the migrator
specifically and
adding that if not migrated, the let will be be now be interpreted as an
external label.

-- E, who probably thought about this one a little too hard