@inthehands I think the bigger issue/question is that properties are supposed to be idempotent. That's what makes it a property to me.
Conversation
Notices
-
Embed this notice
Helge Heß (helge@mastodon.social)'s status on Friday, 20-Sep-2024 07:19:47 JST Helge Heß -
Embed this notice
Paul Cantrell (inthehands@hachyderm.io)'s status on Friday, 20-Sep-2024 07:19:46 JST Paul Cantrell @helge
Wow, that’s an interpretation of the word that’s new to me! -
Embed this notice
Helge Heß (helge@mastodon.social)'s status on Friday, 20-Sep-2024 07:28:51 JST Helge Heß @inthehands Interesting. A property to me should have no meaningful side effects. I've seen people doing KVC properties and wondering when they run into issues because a property setter also set like 10 other unrelated things.
-
Embed this notice
Paul Cantrell (inthehands@hachyderm.io)'s status on Friday, 20-Sep-2024 07:28:51 JST Paul Cantrell @helge
Does this mean that “to change a property” or “set a property” is ill-defined in your lexicon? -
Embed this notice
Helge Heß (helge@mastodon.social)'s status on Friday, 20-Sep-2024 07:36:18 JST Helge Heß @inthehands No, the operation should just be idempotent, i.e. have no side effects. Like this:
```
final class Mehr {
var _x = 0
var y = 0var x: Int {
set {
_x = newValue
y += 1
}
get { _x }
}
}
```
I wouldn't consider `x` a "property" here because calling it 10 times will have side effects unrelated to it. This would be fine:
```
final class Meer {
var _x = 0var x: Int {
set { _x = newValue * 2 }
get { _x / 2 }
}
}
``` -
Embed this notice
Paul Cantrell (inthehands@hachyderm.io)'s status on Friday, 20-Sep-2024 07:36:18 JST Paul Cantrell @helge
Ah, no side effects •other than the property state itself• — yes, agreed! -
Embed this notice
Helge Heß (helge@mastodon.social)'s status on Friday, 20-Sep-2024 07:39:49 JST Helge Heß @inthehands Essentially this:
```
thing.a = 5
thing.a = 5
thing.a = 5
```
should modify nothing but `a`. But those could also be composed values, the key thing is that you can assign as often as you want w/o side effects.
That's what makes a property to me, not whether it is computed or stored. -
Embed this notice
Paul Cantrell (inthehands@hachyderm.io)'s status on Friday, 20-Sep-2024 07:39:49 JST Paul Cantrell @helge
Yeah, then in that case, I think our personal definitions are very close.
-
Embed this notice