Single Static Assignment

Or “write once”

This is a form that LLVM uses for its IR when compiling. It makes certain kinds of analysis much easier to perform as its simpler to determine how variables are affected long term and what their life times are.

And Rust uses it for EVERYTHING – you literally have to tell Rust that a variable should be “mut” or mutable.

Now you might think “OMG this makes things SO difficult”.

But in reality it actually makes things easier especially in multi threaded code because you cannot from one thread modify something in a way that could cause side effects in other threads.

And the really nice thing is that Rust actually can tell at compile time that your code is thread safe – this is really pretty cool and the more I learn about Rust the more I like some of the design decisions they made when creating the language.

This style is much harder to use in Xojo. You’d have to make every property that is exposed a computed property that you can assign once. And this is a bit of work to do. But it is possible. Again doing this could help eliminate certain kinds of bugs. Those that come from side effects because in one place you alter a property and yet it shouldn’t be or wasn’t expected to be.

Certainly computed properties can help as it makes it possible to put code in the setter so you can see when a property is modified. This is handy as heck and something I use a lot to try & make sure I don’t have weird side effects. Or when I do I can convert the simple property to a computed one and then put break points in the setter & getter.*

While SSA form has certain qualities that work well in languages & tools designed around this form, using it in Xojo _might_ be more pain than its worth.

Why ?

Suppose you create a custom subclass of a control and want to use SSA. If you have added properties on your subclass they may get initialized when the window is opened. Should your SSA property be accepting that value and no others ? Or should it only accept the first value it is assigned from code ?

Determining which case you’re dealing with is possible (see but now you have a lot of extra code in every property you want to be this kind.

In total I’m not sure that th effort is worth it for every property. But for a handful it might be.

  • That you can switch a simple property to a computed on or method get / set pair and NOT have to change other code is actually one of the things I appreciate about Xojo.