Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always default optionalsDefaultNil to false, despite Swift 5 #7

Open
gohanlon opened this issue Nov 14, 2023 · 0 comments
Open

Always default optionalsDefaultNil to false, despite Swift 5 #7

gohanlon opened this issue Nov 14, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@gohanlon
Copy link
Owner

gohanlon commented Nov 14, 2023

Description

Swift provides non-public initializers that default optionals to nil. A design tenet of MemberwiseInit has been to strive to be a pure superset of Swift's memberwise initializer, and this approach has largely served it well.

However, I'm convinced that MemberwiseInit should deviate from Swift 5 and always default _optionalsDefaultNil to false, regardless of access level.

Swift's behavior is:

  • complex and often not familiar to developers,
  • lamented by (at least one of) its designers,
  • different for Int? and Optional<Int> (defaulted nil and not defaulted, respectively),
  • hasn't been changeable due to Swift's source compatibility principles, but could be “corrected” in Swift 6. [Update: Swift 6 didn't change this behavior.]

MemberwiseInit can offer a more straightforward approach: Optionals should not default to nil unless explicitly specified by the developer.

This has been debated at length on the forums:

@gohanlon gohanlon added the enhancement New feature or request label Nov 14, 2023
@gohanlon gohanlon self-assigned this May 7, 2024
@gohanlon gohanlon changed the title Always set optionalsDefaultNil to false, despite Swift 5 Always default optionalsDefaultNil to false, despite Swift 5 Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant