[swift-evolution] Properties on Default Protocol Implementations

Trent Nadeau tanadeau at gmail.com
Mon Jan 11 19:48:36 CST 2016


+1 for being explicit given there are, at a minimum, costs to size of
conforming types.

When it comes to visibility to only extensions, that could be more general
that just for protocols. That could also be useful for structs and classes.

For example,

class Foo {
    /// Extensions should log all commands
    // Treated like private everywhere but extensions.
    // It would be an exported symbol but with qualifiers restricting usage
    private public(extension) func logCommand(message: String) { ... }
}

// Can be in another file in same or different module
extension Foo {
    func doStuff() {
        logCommand("Doing stuff now")
        // ...
    }
}

let f = Foo()
f.logCommand("blah") // error anywhere but same file

On Mon, Jan 11, 2016 at 8:27 PM, Matthew Johnson <matthew at anandabits.com>
wrote:

>
> > On Jan 11, 2016, at 7:25 PM, Chris Lattner via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> >
> >> On Jan 11, 2016, at 3:46 PM, Trent Nadeau <tanadeau at gmail.com> wrote:
> >>
> >> Syntactically, would PwS be special like class-only protocols are now
> or would it be automatic by having stored property declarations within the
> protocol?
> >
> > Up for debate.  An automatic approach brings hesitation to me, because I
> don’t want it to be the difference between:
> >
> > protocol P {
> >  var x : Int { get }
> > }
> >
> > and:
> >
> > protocol P {
> >  var x : Int
> > }
> >
> > Did I want a PwS there, or did I just forget {get/set}?
> >
> > Marking the protocol with an attribute or declmodifier would solve that.
>
> +1.  This is something that deserves to be pretty explicit.
>
> Another point that I think needs to be discussed is whether the protocol
> storage is just a default that can be overridden or whether it should be
> protocol-specific.  Or should the protocol author be able to choose.  For
> example, can a protocol have private storage that is not visible outside
> the implementation of default or extension methods?  All things that need
> to be considered IMO.
>
> Matthew
>
> >
> > -Chris
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
>
>


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


More information about the swift-evolution mailing list