[Code style] Require explicitly specified types for public properties#926
Conversation
|
@swift-ci please test |
|
I'm not morally opposed to the change, but I do have two questions:
|
Re: 1. This is meant to be proactive. I agree, the inferred types of literal values like -public var maximumValueDepth = 10
+public var maximumValueDepth = _defaultContentLimitIf the type of this hypothetical Re: 2, I don't want to stop using type inference for all properties. I think it's very useful and valid to continue using it for less-than-public decls, I just want to protect external compatibility. I think considering this "two coding styles" is overstating the impact; we have a precedent for applying special rules to Yes, I do mean |
|
@swift-ci please test |
To bikeshed a bit, what if we made the rule "any exported property that is not initialized with a literal value must have an explicit type"? Then |
|
@swift-ci please test |
This is all subjective, it's code style after all, but I worry that has too much nuance. The expression could be an array or dictionary literal, for example, and if so its complete type would be inferred from its elements, so it could still run into his problem if the types of those elements change. I think "if it's public, declare the type explicitly" is simpler to remember and apply consistently. |
|
Last commit was just documentation, and the previous commit passed CI. Merging. |
This amends the code style guidelines for the project to require an explicit type for all properties whose access level is
publicor greater, and adjusts the code accordingly.Motivation:
See the explanation in the code style document for rationale. This topic recently came up in a PR discussion.
Checklist: