[Swift 4] Cross-cutting concerns and patterns

(Jon Hull) #1

I am curious if we could find a way/place to talk about larger cross-cutting syntax issues that may inform the design of several proposals. In other words, this might be a good time to explicitly look at the forest (vs. the trees) and brainstorm about the wider picture (which can later be referenced for more specific issues).

Here are a few examples of those types of concerns:

• How to order structures which aren’t defined together, without tightly coupling them. This most obvious example of this are operators and order of operation, but there are other potential features which could draw on similar solutions. For example, I proposed a feature a while back where we could have factory-style methods which were fully extensible, but it required a defined ordering of subclasses factory methods being called. This may also affect the design of mix-ins and other advanced features.

• How to disambiguate which implementation is called when it is ambiguous. Again, this will affect the design of mix-ins, but it may also allow things like calling a specific ancestor class’s implementation or calling the default implementation of a protocol from an implementor. I believe 'structure.P::method’ and 'structure.method using P’ were two potential syntax ideas put forward.

• Renaming of an occurrence of something in a specific context. This was talked about with regards to importing (and renaming certain methods within a file/module to avoid conflicts). It also came up when talking about conflicting protocols. For example, you might be able to say ‘var x:Int implements P.y’ to say that this declaration implements the protocol P’s requirement ‘var x:Int' even though it has a different name.

(and many more)

It makes sense to me to consider these very different use-cases together for at least a moment to see if any obvious general syntax shakes loose that wasn’t apparent when considering each separate use-case/proposal in isolation. I also think there are probably issues where we might say “this syntax is unprecedented in Swift… but we have 10 very different use-cases that it makes sense for, so let’s bring it in”.

In general, I think it would provide better guide posts for proposals (as things like the generics manifesto have).

Thoughts? What is the best approach to figure out what these cross-cutting concerns might be?