-
Notifications
You must be signed in to change notification settings - Fork 330
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
static var
to static let
#2642
static var
to static let
#2642
Conversation
@@ -4834,7 +4834,7 @@ | |||
); | |||
mainGroup = B657A8DD1CA646EB00121384; | |||
packageReferences = ( | |||
427692E12B98B82500F24321 /* XCLocalSwiftPackageReference "Sources/PushServer/SharedPush" */, | |||
427692E12B98B82500F24321 /* XCLocalSwiftPackageReference "SharedPush" */, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got these changes just by running the project 🤷
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2642 +/- ##
==========================================
+ Coverage 27.54% 28.53% +0.98%
==========================================
Files 311 335 +24
Lines 31699 23624 -8075
==========================================
- Hits 8733 6741 -1992
+ Misses 22966 16883 -6083 ☔ View full report in Codecov by Sentry. |
@zacwest I see some var becoming let inside structs, thats what I also default using even though struct behavior already assures it would be immutable, I know you have an opinion about this, wanna jump in? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the most part the changes seem good. I don't think the 'static var…' to 'static let…' cases are a problem.
Keep in mind: this project uses the 'World' pattern from Pointfree, so a lot of mutability is actually meant to be in Current
rather than elsewhere, and that's the point where things should be overridden. So for example, static let shared xyz = …
should actually generally be in Current rather than a singleton on the type. Makes testing easier.
public var serverIdentifier: Identifier<Server> | ||
public var settingsKey: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that cases like this - where it's a data type - shouldn't force the non-static members to be let
- that's already done by the mutability state of the struct. It's not in and of itself wrong to copy a struct and mutate the value for some reason, as long as the values are valid state changes -- which the type can guard if it wants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is no real impact now, I will merge this PR as-is, we can always change it to var on demand of course when needed to actually do something with the struct.
Thank you! |
Summary
static let
plays nicely with modern Swift concurrency (async/await)static let
makes it impossible to mutate the values - causing undefined behavior in some cases