[Review] SE-0024 "Optional Value Setter `??=`"


(Douglas Gregor) #1

Hello Swift community,

The review of SE-0024 "Optional Value Setter `??=`" begins now and runs through February 18, 2016. The proposal is available here:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

https://lists.swift.org/mailman/listinfo/swift-evolution
or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:

Proposal link:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reply text

Other replies
<https://github.com/apple/swift-evolution#what-goes-into-a-review-1>What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

What is your evaluation of the proposal?
Is the problem being addressed significant enough to warrant a change to Swift?
Does this proposal fit well with the feel and direction of Swift?
If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
More information about the Swift evolution process is available at

https://github.com/apple/swift-evolution/blob/master/process.md
Thank you,

Doug Gregor

Review Manager


(David Owens II) #2

• What is your evaluation of the proposal?

+1. I'm always up for removing duplicated code.

• Is the problem being addressed significant enough to warrant a change to Swift?

Yes. It pairs well with the other operator/assignment operators (e.g. *=, +=, etc...).

• Does this proposal fit well with the feel and direction of Swift?

Yes.

• If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

Seems fairly identical to other languages that allow this.

• How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

I read the review and a few of the replies in conversation thread.

-David

···

On Feb 12, 2016, at 9:15 PM, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:

Hello Swift community,

The review of SE-0024 "Optional Value Setter `??=`" begins now and runs through February 18, 2016. The proposal is available here:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

https://lists.swift.org/mailman/listinfo/swift-evolution
or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:

Proposal link:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reply text

Other replies
<https://github.com/apple/swift-evolution#what-goes-into-a-review-1>What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

What is your evaluation of the proposal?
Is the problem being addressed significant enough to warrant a change to Swift?
Does this proposal fit well with the feel and direction of Swift?
If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
More information about the Swift evolution process is available at

https://github.com/apple/swift-evolution/blob/master/process.md
Thank you,

Doug Gregor

Review Manager

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


(Haravikk) #3

What is your evaluation of the proposal?

I’m in favour of it, for some reason I encounter cases like these a lot, so a simplified operator would be great.

Is the problem being addressed significant enough to warrant a change to Swift?

It’s not exactly a major problem, but clean code is always good and it should be a fairly simple feature.

Does this proposal fit well with the feel and direction of Swift?

Yes.

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Quick reading, but the proposal is self-explanatory.

···

On 13 Feb 2016, at 05:15, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:


(Joseph Lord) #4

-0.2

What is your evaluation of the proposal?

There is nothing particularly wrong with this proposal but I think we should have a reasonably high bar on adding operators. Each one is nice and reasonable but if you add them all you get a large language and there is more for a beginner to learn and for all of us to remember when reading code.

Is the problem being addressed significant enough to warrant a change to Swift?

No. I don't think it is. I believe (though I haven't tried it) that it is implementable as a user defined operator for those that really wanted it. There have only been a few occasions where I have had the situation to use this operator (not none but not enough).

Does this proposal fit well with the feel and direction of Swift?

Syntactically it is fine but I do think it encourages use of optionals where they may not be necessary. It also adds to the language/standard library surface area without sufficient benefit.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

Yes but Ruby has less support for constants and all variables are nilable and I found I used it a lot there where in Swift I would be setting a constant non-optional by using nil coalescing originally rather than making a sequence of attempts to set the value. I don't miss it in Swift.

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Quick read of proposal.

Joseph


(Radek Pietruszewski) #5

+0.5

I am generally for this proposal, because I don’t see why not — there are cases where this is useful, and it’s symmetric with other X/X= operator pairs, so it’s not like it’s a completely new thing.

However, I don’t think the operator is _as_ useful in Swift as it is in other languages.

In Ruby, for example, it’s extremely common to use `||=` (an equivalent of ??=, more or less) to modify function arguments, e.g. assign default values if nil was passed. But you can’t do that in Swift since SE-0003 removed the ability to mark a parameter as `var`.

So you can’t do that

  arg ??= default

and you have to do

  let arg = arg ?? default

Except you wouldn’t want the earlier version anyway, because `arg` would continue to be an optional. A notion not relevant in a dynamically typed language, but in Swift, it matters.

And I see other cases like this. A proposal to add `??=` to Swift was one of the first Swift radars I filed, because it was just something I was really used to. But with time I realized there are actually relatively few cases where this is useful. And that’s all because of Swift’s characteristics: it’s statically typed, it pushes you to use constants and not variables where possible, optionality is explicit, and avoided when not necessary.

Still, I searched through my code and found _a few_ instances of `??=` (my own implementation), almost all used for dealing with dictionaries (and a dictionary-like structure in a library called SwiftyUserDefaults) — and having this operator definitely improved the clarity of those places.

What is your evaluation of the proposal?

All in all, I’m for.

Is the problem being addressed significant enough to warrant a change to Swift?

I’d say yes, because it’s simple to implement, and carries little risk AFAICT. Still, it’s not as significant an improvement as many of the other proposals.

Does this proposal fit well with the feel and direction of Swift?

Again, ??= is only useful in _some_ cases, and in many other cases you want to avoid optionality and mutability. So it’s not necessarily something we want to encourage a lot, but I don’t see real risk in people trying to damage their Swift code just so they can use ??=. And OTOH having nice tools for dealing with optionality when it’s necessary is a very Swifty thing to do, so overall, yes.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

Mostly dynamically typed languages with ||=, Ruby in particular. Also my own implementation of ??= in my projects and https://github.com/radex/swiftyuserdefaults

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

A quick reading of the proposal.

Best,
— Radek

···

On 13 Feb 2016, at 06:15, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:

Hello Swift community,

The review of SE-0024 "Optional Value Setter `??=`" begins now and runs through February 18, 2016. The proposal is available here:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

https://lists.swift.org/mailman/listinfo/swift-evolution
or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:

Proposal link:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reply text

Other replies
<https://github.com/apple/swift-evolution#what-goes-into-a-review-1>What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

What is your evaluation of the proposal?
Is the problem being addressed significant enough to warrant a change to Swift?
Does this proposal fit well with the feel and direction of Swift?
If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
More information about the Swift evolution process is available at

https://github.com/apple/swift-evolution/blob/master/process.md
Thank you,

Doug Gregor

Review Manager

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


(Brent Royal-Gordon) #6

  • What is your evaluation of the proposal?

A soft +1.

I am worried about the attractive nuisance quality of this proposal; users may be tempted to leave variables optional and mutable even though they could be non-optional constants. But there are good, solid use cases for it, like working with properties or subscripts that are always optional, and I think this will be genuinely useful there.

A warning with a fix-it *might* be warranted when this operator is used with a local variable that is not mutated again later in the function, but that could be overkill.

  • Is the problem being addressed significant enough to warrant a change to Swift?

It's a minor problem. If the proposed solution did some sort of serious violence to the language, I might say it's not significant. But this is a purely additive change that has no impact on the rest of the language, so I would say the problem is significant enough to warrant such a low-impact solution.

  • Does this proposal fit well with the feel and direction of Swift?

Yes. It flows naturally from other patterns in our operators.

  • If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

I implemented the Perl 5 version of this operator, `//=`. Perl's looser typing (any value can be `undef`) made it more useful there, but that doesn't mean it won't be useful in Swift too.

  • How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

I read the proposal and the rest of this thread, and of course as previously mentioned I have some experience in these matters.

···

--
Brent Royal-Gordon
Architechies


(Patrick Gili) #7

Hello Swift community,

The review of SE-0024 "Optional Value Setter `??=`" begins now and runs through February 18, 2016. The proposal is available here:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

https://lists.swift.org/mailman/listinfo/swift-evolution
or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:

Proposal link:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reply text

Other replies
<https://github.com/apple/swift-evolution#what-goes-into-a-review-1>What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

What is your evaluation of the proposal?

I like this proposal, as it eliminate redundant code.

Is the problem being addressed significant enough to warrant a change to Swift?

I think any code redundancy represents a problems that needs to be addressed, and hence the answer to the question is "yes".

Does this proposal fit well with the feel and direction of Swift?

Yes.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

Ruby has a similar operator, which I have always found extremely handy, especially when initializing from configuration files.

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

I read the proposal thoroughly. It didn't need in-depth study, given my familiarity with Ruby.

···

On Feb 13, 2016, at 12:15 AM, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:

More information about the Swift evolution process is available at

https://github.com/apple/swift-evolution/blob/master/process.md
Thank you,

Doug Gregor

Review Manager

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


(David Waite) #8

What is your evaluation of the proposal?

-1, on the basis of use being a potential anti-pattern, and the spec focusing on the benefit of a terser syntax over possible uses.

If there are additional uses outside the proposal, this evaluation may change.

Is the problem being addressed significant enough to warrant a change to Swift?

Not as described.

“??” is described as the nil coalescing operator. It is defined as the following function:

public func ??<T>(optional: T?, @autoclosure defaultValue: () throws -> T) rethrows -> T
The purpose of the nil coalescing operator is defined as follows by the Swift Programming Language book

“The nil coalescing operator (a ?? b) unwraps an optional a if it contains a value, or returns a default value b if a is nil. The expression a is always of an optional type. The expression b must match the type that is stored inside a.”

This operator has thus two core properties:
1. it allows another mechanism to deal with nil values, by specifying an alternate value to use in the nil case
2. as either the value or the alternate is non-nil, it casts off optionality

This operator does not do the second. It allows you to apply a value in the nil case, but the resulting value is still an optional. As such, I fear the usefulness of the “??=“ operator is greatly diminished.

Note also that unlike other operators with inout equivalents like addition, the type of the left-hand input and the output are not the same in “??” due to the missing safe casting off of optionality.

Does this proposal fit well with the feel and direction of Swift?

The example given by the proposal is as follows:

really.long.lvalue[expression] = really.long.lvalue[expression] ?? ""

In this case, you are setting a default value of “” to an optional target within a long expression.

However, it is unclear why the original expression allowed nil, or why setting this value to “” is an improvement.

To counter, some existing usage:

let userDefaults = NSUserDefaults.standardUserDefaults()
let repeatCount = userDefaults.valueForKey("repeatCount") as? Int ?? 4
for attempt in 0..<repeatCount {
    // ...
}

The for loop only works because repeatCount is non-optional. Assigning the value back into the expression would mutate the original value, but would still require one to cast off the optionality of the value.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

As mentioned, Ruby has a similar behavior. Other than the “false” and “nil” literal values, everything evaluates as true. The || and && operators preserve the values of the lhs and rhs arguments.

1 && 2 # is 2
1 || 2 # is 1
nil || 2 # is 2

As such, ||= can be used for such a default assignment system.

However, ruby does not have optionality. All libraries must take into account the possibility of sending nil in for a value. As such, it is not influenced by the limitations of this proposal.

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

In-between a reading and a study.

-DW


(Tino) #9

-1

For me, the meaning of the operator isn't intuitive (it isn't hard to explain or understand, though).
So far, I did not miss "??=", and I think there are already some features marked for removal which are more valuable.

On the other hand, adding a new operator doesn't destroy anything, and it's only a tiny change, so the only real argument is keeping language and stdlib small.
Imho it would be a good idea to ask some developers that haven't read the proposal about their interpretation of "??=" to check how confusing it is.


(David Sweeris) #10

-1, because in my mind, "x ??= y" kinda looks like "y is assigned to x iff y isn't nil", or, if you associate the ?? part with the lhs, "y is assigned to x if x is nil", neither of which is what the proposed operator means. In fact, the 2nd case is the *opposite* of what ??= means in this proposal.

To be clear, it's the syntax that I'm opposed to, not the concept.

- Dave Sweeris

···

On Feb 12, 2016, at 23:15, Douglas Gregor <dgregor@apple.com> wrote:

Hello Swift community,

The review of SE-0024 "Optional Value Setter `??=`" begins now and runs through February 18, 2016. The proposal is available here:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

https://lists.swift.org/mailman/listinfo/swift-evolution
or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:

Proposal link:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reply text

Other replies
What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

What is your evaluation of the proposal?
Is the problem being addressed significant enough to warrant a change to Swift?
Does this proposal fit well with the feel and direction of Swift?
If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
More information about the Swift evolution process is available at

https://github.com/apple/swift-evolution/blob/master/process.md
Thank you,

Doug Gregor

Review Manager

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


(Joe Groff) #11

I'm not sure this is the best design for Swift. In other languages where I've used similar features, particularly Perl and Ruby, the "set a dictionary key to a default value" was by far the most common use. Particularly in Ruby, with its reference-semantics containers, it's useful to pass down 'foo[x] ||= []' as an expression into a function or method that would then populate the array:

def populate(array)
  array << [1,2,3]
end

hash = {}

populate(hash["foo"] ||= [])

Though ugly, that's a handy bit of expressivity you don't get with the proposed '??=' design. Even if '??=' returned the result, it wouldn't be able to return it as an lvalue.

I think a more expressive alternative approach to this problem would be to extend Dictionary with a `subscript(_:orDefault:)` member:

extension Dictionary {
  subscript(key: Key, orDefault value: Value) -> Value {
    get {
      return self[key] ?? value
    }
    set {
      self[key] = newValue
    }
  }
}

For the common use case of providing a default value for a dictionary key, this has several advantages. It can be used as an lvalue, as in `populate(&hash["foo", orDefault: []])`. It also avoids storing to the dictionary if the defaulted value is only read. (I think in the fullness of time, the default value probably belongs as a type parameter, e.g. `DefaultDictionary<Key: String, Value: [String], Default: []>`, but we're a ways away from that today.) It's true that this feature is dictionary-centric, whereas `??=` applies generally to any optional, but as others have noted, I'm not sure that generality is a *feature* we want to encourage.

-Joe

···

On Feb 12, 2016, at 9:15 PM, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:

Hello Swift community,

The review of SE-0024 "Optional Value Setter `??=`" begins now and runs through February 18, 2016. The proposal is available here:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

https://lists.swift.org/mailman/listinfo/swift-evolution
or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:

Proposal link:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reply text

Other replies
<https://github.com/apple/swift-evolution#what-goes-into-a-review-1>What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

What is your evaluation of the proposal?
Is the problem being addressed significant enough to warrant a change to Swift?
Does this proposal fit well with the feel and direction of Swift?
If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
More information about the Swift evolution process is available at

https://github.com/apple/swift-evolution/blob/master/process.md
Thank you,

Doug Gregor

Review Manager

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


(Rob Mayoff) #12

The review of SE-0024 "Optional Value Setter `??=`" begins now and runs
through February 18, 2016. The proposal is available here:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md

   - What is your evaluation of the proposal?

I like it.

   - Is the problem being addressed significant enough to warrant a
   change to Swift?

Yes. It's not a huge problem, but the solution is small.

   - Does this proposal fit well with the feel and direction of Swift?

Yes.

   - If you have used other languages or libraries with a similar
   feature, how do you feel that this proposal compares to those?

Seems just right. I've used ||= in perl and ${var:=value} in sh.

   - How much effort did you put into your review? A glance, a quick
   reading, or an in-depth study?

I read the entire original discussion on the list, and I spent about two
minutes reading the proposal.


(Guillaume Lessard) #13

For: https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md

• What is your evaluation of the proposal?

Negative.

The intent is interesting, but the ?? operator is simply not a good candidate for a mutating variant, as its left-hand operand and its result are of different types. The arithmetic operators generalize well to mutating variants, as lhs and result are of the same types.

• Is the problem being addressed significant enough to warrant a change to Swift?

The proposed ??= operator seems like a counterpart to flatMap for the .None path.
I’ve seen this called `recover` in a number of places:

extension Optional {
  public func recover(@noescape transform: () -> Optional) -> Optional {
    switch self {
    case .Some: return self
    case .None: return transform()
    }
  }
}

• Does this proposal fit well with the feel and direction of Swift?

No.

• How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

I looked at all the places I have used the ?? operator, and considered my intent; in every case I wanted to get out of Optionality, not keep it going.

Cheers,
Guillaume Lessard


(Adrian Kashivskyy) #14

What is your evaluation of the proposal?

I'm -1 on this.

Is the problem being addressed significant enough to warrant a change to Swift?

In my opinion it's not and I even consider it an anti-pattern, like the previous debaters noticed.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

I used a ||= operator in Ruby and I think in the Ruby's world of brevity it fits there well.

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

I thought it over many times.

Regards,
Adrian Kashivskyy
Senior iOS Developer at Netguru

···

Wiadomość napisana przez Douglas Gregor via swift-evolution <swift-evolution@swift.org> w dniu 13.02.2016, o godz. 06:15:

Hello Swift community,

The review of SE-0024 "Optional Value Setter `??=`" begins now and runs through February 18, 2016. The proposal is available here:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

https://lists.swift.org/mailman/listinfo/swift-evolution
or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:

Proposal link:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
Reply text

Other replies
<https://github.com/apple/swift-evolution#what-goes-into-a-review-1>What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

What is your evaluation of the proposal?
Is the problem being addressed significant enough to warrant a change to Swift?
Does this proposal fit well with the feel and direction of Swift?
If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
More information about the Swift evolution process is available at

https://github.com/apple/swift-evolution/blob/master/process.md
Thank you,

Doug Gregor

Review Manager

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


(Sune Foldager) #15

What is your evaluation of the proposal?

I’m -1. My main objection is the same as others have brought up, namely that, contrary to ??, it keeps us in “optional land”. That is, a ??= b ~> a = a ?? b, so a must be optional.

Is the problem being addressed significant enough to warrant a change to Swift?

I don’t think so. In Python, where ||= works, I do use that from time to time because it’s “idiomatic”, but I don’t really think it’s very obvious what it does. In Swift, my programming style is a bit different, and I don’t find myself needing it. Especially due to the way it keeps optional (which is obviously not an issue in Python).

Does this proposal fit well with the feel and direction of Swift?

I don’t know, but I don’t think it’s a very important addition and can lead to confusion instead.

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Read the responses. Thought about my own use, and looked at some Python and Swift code.

-Sune

···

On 13 Feb 2016, at 06:15, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:


(Matt Whiteside) #16

What is your evaluation of the proposal?

+1. It seems like this operator will be occasionally useful, and won’t be in anyone’s way if they don’t need it.

Is the problem being addressed significant enough to warrant a change to Swift?

Yes.

Does this proposal fit well with the feel and direction of Swift?

More or less. I don’t think the meaning will be obvious to a beginner, but neither are most operators, so it still seems fine.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

I have used the equivalent in ruby, and it came in handy.

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

A quick read.

Matt


#17

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
What is your evaluation of the proposal?

Fits among the other assignment operators. Contrary to some beliefs, the nil/optional coalescing operator can still return an optional:

strongOptional = strongOptional ?? weakOptional

So the ??= assignment is well suited (for the form resulting in optional):

strongOptional ??= weakOptional

It may not be the best option for dictionary as some pointed out, but it can be use outside dictionary as well, allowing one to break long chain of nil/optional coalescing.

strongOptional = strongOptional ?? weakOptional ?? weakerOptional ?? weakestOptional

In some possible used case:

currentSetting = currentSetting ?? userDefault ?? systemDefault ?? builtinDefault
currentSetting ??= userDefault
currentSetting ??= systemDefault
currentSetting ??= builtinDefault

Is the problem being addressed significant enough to warrant a change to Swift?

Not really a problem, just a "why is this missing" state. The change also seem of minimal churn and be of low risk.

Does this proposal fit well with the feel and direction of Swift?

It’s just an assignment operator among others which are similar in shape, its not evolution and as such have no direction.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

Nope

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Been following the thread

Dany

···

Le 13 févr. 2016 à 00:15, Douglas Gregor via swift-evolution <swift-evolution@swift.org> a écrit :


(Lily Ballard) #18

* What is your evaluation of the proposal?

-1. If we were to have this operator, then I think `??=` is a good
choice for it. But I don't think we need this operator. As others have
pointed out, a lot of the use-cases from other languages don't actually
work in Swift, and having the operator encourages people to write anti-
patterns in order to use it, such as making a value into a mutable
Optional when it really should be an immutable non-optional value.

* Is the problem being addressed significant enough to warrant a
   change to Swift?

No. The need for this sort of operator is much rarer in Swift than it is
in languages that do have an equivalent (like Ruby).

Anecdotally, I've written a lot of Swift code at this point, and I've
never wanted this. I have on rare occasion wanted a local "lazy"
variable, but in those rare instances, the desire was to move the
initialization out of the main body of the function and up to the
declaration, which `??=` doesn't help with.

* Does this proposal fit well with the feel and direction of Swift?

The choice of operator I think is reasonable, given the existing `??`
operator, but encouraging the use of Optionals for local variables that
will end up with a guaranteed-non-Optional value does not.

* If you have used other languages or libraries with a similar
   feature, how do you feel that this proposal compares to those?

The only languages that I know of with a similar operator also return
the rhs value from the assignment expression, and that's not something
Swift would do. So this is less useful than the operator in those
languages.

* How much effort did you put into your review? A glance, a quick
   reading, or an in-depth study?

A quick reading.

-Kevin Ballard

···

On Fri, Feb 12, 2016, at 09:15 PM, Douglas Gregor wrote:


(Tal Atlas) #19

I think that overall this is a good operator that eventually should get in.
At this point though the wins that this would bring are probably not worth
the added complexity to the language.

As Joe said the primary use case for the hammer operator `||=` in ruby is
not even covered by this operator, so it’s use would be far more limited
than in those languages.

-Tal

···

On Sat, Feb 13, 2016 at 12:15 AM, Douglas Gregor via swift-evolution < swift-evolution@swift.org> wrote:

Hello Swift community,

The review of SE-0024 "Optional Value Setter `??=`" begins now and runs
through February 18, 2016. The proposal is available here:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md

Reviews are an important part of the Swift evolution process. All reviews
should be sent to the swift-evolution mailing list at

https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the
review manager. When replying, please try to keep the proposal link at the
top of the message:

Proposal link:

https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md

Reply text

Other replies

<https://github.com/apple/swift-evolution#what-goes-into-a-review-1>What
goes into a review?

The goal of the review process is to improve the proposal under review
through constructive criticism and, eventually, determine the direction of
Swift. When writing your review, here are some questions you might want to
answer in your review:

   - What is your evaluation of the proposal?
   - Is the problem being addressed significant enough to warrant a
   change to Swift?
   - Does this proposal fit well with the feel and direction of Swift?
   - If you have used other languages or libraries with a similar
   feature, how do you feel that this proposal compares to those?
   - How much effort did you put into your review? A glance, a quick
   reading, or an in-depth study?

More information about the Swift evolution process is available at

https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

Doug Gregor

Review Manager

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


(Paul Ossenbruggen) #20

What is your evaluation of the proposal?
+1 this is seems like a natural addition similar to += or other operators which assign and perform an action.

Is the problem being addressed significant enough to warrant a change to Swift?
Yes.

Does this proposal fit well with the feel and direction of Swift?
Yes.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
Not found in other languages.

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
Read proposal and thread.