Looking at Zak's code, one idea from the past returned to my head - simple UDT initialization.
Lets take a classic case of UDT for vector:
Type Vector3D
x As Single
y As Single
z As Single
End Type
Dim myVector As Vector3D
Now, we can initialize the variable in two ways (leaving aside hacks ):
Way #1
myVector.x = 1
myVector.y = 2
myVector.z = 3
Way #2
With myVector
.x = 1
.y = 2
.z = 3
End With
Both are easy to understand, but also quite lenghty.
In past years I suggested to make possible something like:
Eros had good note, that this way of initialization is potentially dangerous, as it heavily depends on order of definition of UDT members. If you, for example during code cleanup, rearrange the order of UDT members, it immediately makes code damaged.
This time, I have slightly modded proposal, what about this syntax:
myVector.x,y,z = (1, 2, 3)
This way:
- You get shorter form, still clear
- Possibility of member mismatch is low, as you explicitly specify which members you want to initialize (in this case x, y, z in order as written)
- It would allow arbitrary stunts, such as filling only the members listed -> myVector.x,y = (1, 2) ' -- Leaves z untouched
The brackets might seem redundant, but would be useful for initializing arrays of UDTs:
Dim myVectors(3) As Vector3D
myVectors().x,y,z = (1, 2, 3), (4, 5, 6), (7, 8, 9)
Only problem I see now is performance - for sure this won't be fast, as parser has to check type for each member in the sequence, to get the value. But from my side this is something I could live with, as the comfort it provides and the selfdocumenting factor seem to be the thing I would use this for.
I would be curious about your opinion on this proposal. I did not posted this in the Support as new Suggestion issue, as I wanted to discuss it first with others.
Do you see any weak points in this approach (like my original old proposal indeed had?). Would you like to see something like this implemented?
Thanks,
Petr
Bookmarks