When initializing user-define objects or structs, I find that he positional argument approach isn’t very clean. For example, let us say that we first start with
mutable struct MyPoint
x::Float64
z::Float64
end
Then as we continue to work, we find that we need a new field “y”
mutable struct MyPoint
x::Float64
y::Float64
z::Float64
end
If we use the constructor method of MyPoint(x,y,z), we then have to change the code whenever there is an assignment to make sure z is not assigned to y. A cheap workaround I’ve used is the following
mutable struct MyPoint
x::Float64
z::Float64
MyPoint(T) = new(T.x, T.z)
end
This allows you to assign the point using a Named Tuple like this
MyPoint((x=1,z=2))
My question is that, would it break anything if we made the default behaviour of struct construction something like
MyPoint(x=1, z=2)
We already have that behavior for Named Tuples, is there something that inhibits us from making user defined structs behave this way too?