Skip to content

Explicit requires/abstract keyword? #50

@LeaVerou

Description

@LeaVerou

A point of confusion around the current protocol syntax has been the lack of clear distinction between required and provided members. Required members look just like data properties with no initializer.

Compare:

protocol ToString {
  tag; // required

  toString() { /* ... */ } // provided
}

Additionally, as a side effect, there is no way to provide data properties — only to require them.

It seems far cleaner to explicitly denote this with a keyword, especially since in the majority of cases there is only one of these, so clarity trumps conciseness.

abstract would be more externally consistent with the same concept in other languages, requires is more human-friendly and internally consistent with the constructor API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs bikesheddingConsensus on the general idea but exact syntax still needs bikeshedding

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions