When creating an immutable struct with a reasonable number of fields and an inner constructor, I find that aligning the arguments to
new() with the order of the struct fields to be quite tedious and error prone (especially if adjacent fields have the same type, or I add / reorder types). With a mutable struct, I tend to do the following:
ret = new() ret.x = x ret.y = y ret.z = z ... return ret
Which is much safer and easier to maintain.
Does anyone have a nice approach to this? It seems like
new() doesn’t support kwargs, but it would be cool if it did. I wonder if a macro could be written that would allow
new() to take kwargs?