[swift-evolution] What about a VBA style with Statement?

L Mihalkovic laurent.mihalkovic at gmail.com
Thu Apr 14 13:23:36 CDT 2016

> On Apr 14, 2016, at 7:39 PM, Vladimir.S via swift-evolution <swift-evolution at swift.org> wrote:
> Can't agree with you.
> As you see from this topic, many of us use the "with" feature by
> using workarounds/hacks.
> Those, who don't use such "with" feature - can
> produce even more bugging code(copy-paste,wrong editor's code completion
> suggestion).
> So, I think this is "good" feature, not just cool/nice
> looking. It will help us to write code with less bugs, without workarounds/hacks.
> Do you want to stop good feature, that is helping us to produce good code, because someone can use it "wrong"? Well, don't think this is right.

that is a bit of an extreme simplification of what I was saying, but I do believe that programming has become a modern day blue-colar job where IMHO the majority of programmers display a lot of creativity when it comes to perverting good ideas. In that context, I think that it makes sense to rescue code from the programmers writing it. I have seen a lot of bad VBA code written using WITH blocks. 

I just realized that my problem with this thread is the reference to VBA. The concept of method cascades described in: https://gist.github.com/erica/6794d48d917e2084d6ed <https://gist.github.com/erica/6794d48d917e2084d6ed> is partially interesting to me.

IMHO a solution allowing the following

WITH self {


	// a lot of code
	// and 700 lines of code later


is barking up the wrong tree, because for as grotesque as this code is, if it can be done, it will be done… a lot .. because it is easy to do. And code like the following is IMHO taking the same slippery slope

          sharedName = newValue      // myInstance.sharedName = newValue (3)
          _.sharedName = newValue    // the locally scoped newValue (2)
          _._.sharedName = newValue  // I don't actually propose this, but (1)

The following code however looks like a real productivity improvement (provided NOTHING else can be added between the chained invocations)

with let task = NSTask() {
    launchPath = "/usr/bin/mdfind"
    arguments = ["kMDItemDisplayName == *.playground"]
    standardOutput = pipe


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160414/ba3c6abc/attachment.html>

More information about the swift-evolution mailing list