Computed properties

Hello,

I just discovered the existance of Computed Properties.
There are some interesting possibillities whith these properties.

Is there a reason why I should not use all my properties as computed properties.
Perhaps slowing down the program ?
Or are there other disadvantages ?

Regards
Etienne

That’s a lot of extra work for no gain if all you’re doing is storing and retrieving a value. While I haven’t tested, I’d expect it to be slower too, although I doubt you’d notice it unless your app’s speed is critical.

There is one exception. Xojo currently has no way to break if a property value changes but you can fake that by using a computed property and setting a breakpoint in its Set.

BTW, note that you don’t have to add code to a computed property’s Set and Get. Rather, by using only one, you can create a read-only or write-only property.

You do have to have a “GET”, but not a “SET”
Computed properties cannot have parameters (ie. Arrays etc)
for those you would use Overloaded Functions

But for the most part you would use these

  • where you wanted a READ ONLY varaible (
  • A variable that would be allowed to be SET only under certain circumstances, or to provide an EVENT when changed

You can set just the Set, Dave, you don’t have to have a Get. Try it.

And this is one of the problems with working in multiple disciplines at the same time :slight_smile:

SWIFT is what doesn’t allow SET only “Variable with a setter must also have a getter”

This is indeed a very nice way to look for property changes.

Question : I changed a property to a computed property → Ok
But how can I return this property to normal again ?

I think these are good suggestions when using Computed Properties.

Thanks for all the replys

Regards
Etienne

You can’t revert a computed property directly. Delete it and add back a regular property with the same name or, if there is a shadow property, rename that and set its scope.