Xojo has this great feature. You can write sets of methods that can act like LValues. That is – ones that can have a value assigned to them. Or ones that occur on the LEFT of an assignment operator.
dim i as integer
i = 9 // <<< i is an LValue
What can I do with assigns ?
Well one of the things you can do is make methods behave like properties – regular or computed ones. So we can do something simple like
Class myClass
Sub foo(assigns value as integer)
// now do whatever we want with value
End Sub
End Class
dim c as new myClass
c.foo = 9
This is nice but you can get the exact same effect with a public property or a computed property. So no real big deal here. You could have
Class myClass
Public foo as integer
End Class
dim c as new myClass
c.foo = 9
OR something like
Class myClass
ComputedProperty foo
// now do whatever we want with value
End ComputedProperty
End Class
dim c as new myClass
c.foo = 9
You really cant tell which form was used. And thats actually a nice trick that not many other languages have.
But, since we can write ANY kind of method that uses Assigns as the last parameter we can do things that are not possible with public properties or computed properties.
So we could write a method that, given an integer and string key gets assigned a value that gets stored in a database.
Sub newPrice(partID as integer, partName as string, assigns newPrice as double)
and then use this elsewhere like
newPrice(123, "washer") = 49.95
Public properties and computed properties are usually where I start when writing code, and I’ll transition from a public property to a computed one and then to a get / set pair of methods as needs are revised.
Fortunately Xojo makes this transition easy because each of those can be swapped for the other without any impact on the rest of your code when they have the same signature. FOr instance, without examining the code you have no idea whether the following uses a public property, computed property, or setter method with assigns
dim c as new myClass
c.someProperty = 100