[swift-evolution] [Review] SE-0024 "Optional Value Setter `??=`"
johnlinvc at gmail.com
Thu Feb 18 11:13:12 CST 2016
> What is your evaluation of the proposal?
-1 for this. Although the proposal was initially intended for property usage, I think the most wide spread usage will be on local variables. And this will encourage use usage of var instead of let.
var foo = optionalOutput()
let foo = optionalOutput() ?? bar
The proposed ??= may create many unnecessary var usage just because they want to use the ??= shorthand.
> Is the problem being addressed significant enough to warrant a change to Swift?
No, It can be implemented as a extension if needed.
We already got default value for property, default parameter value for functions, and ?? for local variable usage.
> Does this proposal fit well with the feel and direction of Swift?
No. It’ll encourage unnecessary usage of var.
> If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
The ||= operator in ruby. But the reason why ||= is popular is that ruby has no support for keyword argument before ruby 2.0. For example:
using ||= is the de factor way to set value to options[:bar]
but after ruby 2.0 following method is preferred
def foo(bar: “default”)
which eliminates the need of ||= operator
> How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
Read though the origin thread, read the proposal, read some of the reviews.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution