[swift-evolution] [Review] SE-0073: Marking closures as executing exactly once

Nicola Salmoria nicola.salmoria at gmail.com
Wed May 4 07:49:51 CDT 2016


> * What is your evaluation of the proposal?

-1. The proposed change seems to require a somewhat complex implementation
in the compiler, and I fail to see clear benefits in the change.

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

Frankly, I don't think the motivating example in the proposal is strong
enough. If the only purpose is to simplify certain imperative constructs, I
think there are better, functional-style, solutions.

The example related to autoreleasepool is particularly significant:

// Current Swift:
var x: Int = 0 // `var` declaration, with some irrelevant value
autoreleasepool {
    x = 1
}

// Should SE-0061 be accepted:
let x = autoreleasepool {
    return 1
}

// Should this proposal be accepted:
let x: Int
let y: String
autoreleasepool {
    x = 1
    y = "foo"
}

I would argue that of these three examples, the second is the clearest and
most readable; the last one, which should support the proposal, could simply
be rewritten as

let (x, y) = autoreleasepool {
    return (1, "foo")
}

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

While it does build on the delayed initialization of let variables, which is
a peculiar feature of Swift, I don't think it fits the overall trend of
favoring functional constructs and discouraging reliance on side effects.

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

I've never seen this kind of feature.

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

A quick reading.

--
Nicola




More information about the swift-evolution mailing list