Proposal SE-0009 Reconsideration

As a colorblind developer, this isn’t really an issue. The vast majority of colorblind people can discern colors. As long as the IDE allows you to customize which colors it displays, you can find a palette that will work with your eyes (for my type of colorblindness, for instance, I have difficulty differentiating blue and purple, so I wouldn’t use both in my syntax highlighting color scheme). As long as color isn’t the only thing differentiating on-screen elements, adding colors to syntax highlighting is beneficial even to us colorblind developers. :)

I believe in eclipse you can choose the font, which inludes setting its color.

···

On May 23, 2016, at 6:43 PM, Jeff Kelley <slaunchaman@gmail.com> wrote:

Jeff Kelley

SlaunchaMan@gmail.com | @SlaunchaMan | jeffkelley.org

Check out Developing for Apple Watch, Second Edition, now in print!

On May 23, 2016, at 12:24 PM, Krystof Vasa via swift-evolution <swift-evolution@swift.org> wrote:

The problem can also be easily mitigated by having the IDE use a different color to display a variable based on where it was defined (eclipse come to mind as an example). This is something the brain naturally notices without paying any conscious attention.

Tell that to the colorblind :)

-- E

The problem can also be easily mitigated by having the IDE use a different color to display a variable based on where it was defined (eclipse come to mind as an example). This is something the brain naturally notices without paying any conscious attention.

Tell that to the colorblind :)

Dunno about other IDEs, but Xcode's syntax highlighting can change the size, typeface (bold, italic, etc), and even the font. You can make instance variables show up as 24pt comic sans, if you want. You can’t do polkadot, though… apparently that’s going too far.

Issue is SourceKit may not have the scope of an identifier (was not there last time I looked), just the fact that it was an identifier (i looked a while ago mind you)

···

On May 23, 2016, at 7:26 PM, David Sweeris <davesweeris@mac.com> wrote:
On May 23, 2016, at 11:24, Krystof Vasa via swift-evolution <swift-evolution@swift.org> wrote:

- Dave Sweeris

Unfortunately, doing this can trigger a longstanding Xcode bug that
makes it very difficult to edit any file that's substantially longer
than the height of your window.

···

On Mon, May 23, 2016 at 12:26 PM, David Sweeris via swift-evolution <swift-evolution@swift.org> wrote:

Dunno about other IDEs, but Xcode's syntax highlighting can change the size, typeface (bold, italic, etc), and even the font. You can make instance variables show up as 24pt comic sans, if you want. You can’t do polkadot, though… apparently that’s going too far.

IMO it's weird to rely on XCode features when we discuss some features of the language. Not always Swift code is edited in XCode, not always in IDE that supports different colors for different kind of variables, not always you have IDE at all and you can have just editor with simple(it will not parse/compile Swift code/project) coloring for base language constructions.

As for this proposal. I don't believe(based on community and core team response) the situation with implicit 'self.' could be changed. So let's use lints and other tools to achieve the target of warning for implicit 'self.'. I suggest to move forward the idea of warning(and 'fix') for shadowing of variables in general and property and local variable in particular.

···

On 23.05.2016 21:41, Charles Srstka via swift-evolution wrote:

Plus, I might end up having to use a different source editor sometimes,
particularly when I’m doing a large refactor and Xcode is stuck in its
“SourceKitService crash every time two characters are typed” thing. I’d
really rather have things differentiable in the language itself rather than
relying on external crutches.

As another colorblind developer, I have trouble paying attention to the syntax highlighting. I didn’t even notice that member variables were colored until someone mentioned it on this list.

···

On May 23, 2016, at 9:43 AM, Jeff Kelley via swift-evolution <swift-evolution@swift.org> wrote:

As a colorblind developer, this isn’t really an issue. The vast majority of colorblind people can discern colors. As long as the IDE allows you to customize which colors it displays, you can find a palette that will work with your eyes (for my type of colorblindness, for instance, I have difficulty differentiating blue and purple, so I wouldn’t use both in my syntax highlighting color scheme). As long as color isn’t the only thing differentiating on-screen elements, adding colors to syntax highlighting is beneficial even to us colorblind developers. :)

Jeff Kelley

SlaunchaMan@gmail.com <mailto:SlaunchaMan@gmail.com> | @SlaunchaMan <https://twitter.com/SlaunchaMan&gt; | jeffkelley.org <http://jeffkelley.org/&gt;

Check out Developing for Apple Watch, Second Edition <https://pragprog.com/titles/jkwatch2/developing-for-apple-watch-second-edition&gt;, now in print!

On May 23, 2016, at 12:24 PM, Krystof Vasa via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

The problem can also be easily mitigated by having the IDE use a different color to display a variable based on where it was defined (eclipse come to mind as an example). This is something the brain naturally notices without paying any conscious attention.

Tell that to the colorblind :)

-- E

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

If the design team is very serious about not integrating optional warnings, then I don’t think it is a huge bother to implement think in linters like SwiftLint is doing.

I'm fine with the way SE-0009 was decided but I think the review left one consideration for linters unexplored: How to be explicit about what's captured by a closure if the coding style enforced by a linter involves using `self.` everywhere?

There were (are) basically two reasons for keeping `self.` implicit the way it is:

Reason 1. It keeps noise level down. E.g. computed properties often read better this way:

    var area: Double {
      return width * height
      // rather than: 'self.width * self.height'
    }

Reason 2. It makes the capturing of `self` explicit, because `self.` is only required in escaping closures and thus the capturing expressions require thinking when writing code and also stand out when reading code.

I think those are good reasons. But then, the language rules don't really favour the other coding style where the `self.` prefix is used throughout, even if it *can* be enforced by a linter:

Example 1. There's no other way (but using the `self.` prefix) to indicate that `self` should be retained by a closure:

    self.prepareWork()
    queue.async { [self] in
    // ^
    // error: Expected 'weak', 'unowned', or no
    // specifier in capture list
      self.doTheWork()
    }

Example 2. There's currently no way to mark when an escaping closure is intended to **not** capture any other references but those explicitly listed:

    queue.async { [bar] in
      if bar.isAdjustable {
        baz.adjust()
      }
    }
    // Meant 'bar', but compiler didn't alert!

So I think it would be a good idea to adjust the capture list syntax a bit:

Suggestion 1. Allow capture lists to explicitly state that they capture `self` strongly by spelling it out with no weak/unowned specifier, i.e. `[self]`.

Suggestion 2. Add a succinct way to indicate that the capture list is *comprehensive*, i.e. that implicitly capturing other variables from the local scope is an error. (Capturing variables from the file scope should be allowed though, I reckon.) The syntax for this could be e.g. postfixing the capture list brackets with the exclamation mark `!`:

    queue.async { [service]! in
      service.handleTask(self.task)
    // ^
    // error: Implicit capture of 'self' in closure
    }
    queue.async { [service, self]! in
      service.execute(self.task) // ok
    }
    queue.async { [service, task = self.task]! in
      service.execute(task) // also ok; didn't capture 'self'
    }
    queue.async { [bar]! in
      if bar.isAdjustable {
        baz.adjust()
    // ^
    // error: Implicit capture of 'baz' in closure
      }
    }

With these two changes, the coding style choice of what to use the `self.` prefix for would be better supported both ways, and no optional warnings would be needed. A linter could then require capturing `self` explicitly where it's used inside an escaping block. Myself, I wouldn't use comprehensive capture lists all the time but there have been a few cases where it would've been useful to prevent mistakenly capturing anything that could create a retain cycle.

Any thoughts? Would an idea like this help any of the people who started this mailing list thread—that is, with the aid of a respectively configured linter of course?

+1. I like both ideas (and don't like mandating style). One other thing that might be nice is a plugin mechanism for the build system that provides a standard interface for linters / style checkers and allows them to emit style "warnings" (ideally integrated with Xcode).

···

Sent from my iPad

On May 22, 2016, at 11:33 AM, Pyry Jahkola via swift-evolution <swift-evolution@swift.org> wrote:

On 22 May 2016, David Hart wrote:

— Pyry

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