In my opinion you should avoid computed properties whenever possible. It is exactly for the reasons that you lay out. If you see code like
let session = manager.urlSession
Would expect to get a brand new one session? No you wouldn't. That's clearly an unexpected side-effect. You would expect to always get the same.
Computed properties are evil exactly for those side-effects. But Juniors like to play with these shiny toys. …sigh…
So my rule of thumb is: If it has a side-effect make it a func with a name that clearly indicates said side-effect.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In my opinion you should avoid computed properties whenever possible. It is exactly for the reasons that you lay out. If you see code like
let session = manager.urlSession
Would expect to get a brand new one session? No you wouldn't. That's clearly an unexpected side-effect. You would expect to always get the same.
Computed properties are evil exactly for those side-effects. But Juniors like to play with these shiny toys. …sigh…
So my rule of thumb is: If it has a side-effect make it a func with a name that clearly indicates said side-effect.