[swift-evolution] [Proposal] Scoped resources (like C# using statement)

Trent Nadeau tanadeau at gmail.com
Wed Dec 30 11:11:47 CST 2015


Based on the discussion here, I'm withdrawing this proposal.

I created it because of a section in the Error Handling Rationale and
Proposal document (
https://github.com/apple/swift/blob/master/docs/ErrorHandlingRationale.rst)
about `using`:

Swift should consider providing a using statement which acquires a
resource, holds it for a fixed period of time, optionally binds it to a
name, and then releases it whenever the controlled statement exits.

using has many similarities to defer. It does not subsume defer, which is
useful for many ad-hoc and tokenless clean-ups. But it is convenient for
the common pattern of a type-directed clean-up.

We do not expect this feature to be necessary in the first release.

However, it looks like there isn't enough need to warrant a language
change, at least for now. Is the Rationale doc a living document? If so, it
should perhaps be updated to mention that `using` needs a strong use case
given the current language features.

Thanks to everyone involved in this discussion.
<https://github.com/apple/swift/blob/master/docs/ErrorHandlingRationale.rst#c-and-objective-c-interoperation>

On Wed, Dec 30, 2015 at 6:12 AM, Tino Heth <2th at gmx.de> wrote:

> It is an appealing idea on first sight, but it makes the language more
> complex, and I don't think scoped resources are versatile enough to back
> justify their inclusion.
>
> The defer feature which is already mentioned in the proposal is very
> similar — and I expect that will not only be the case for the effect, but
> also for the usefulness:
> I rarely use defer… I still like the concept, but I guess our ecosystem
> just has little need for it.
>
> Tino




-- 
Trent Nadeau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151230/785eff74/attachment.html>


More information about the swift-evolution mailing list