-
Notifications
You must be signed in to change notification settings - Fork 63
Color type is now a class
instead of struct
#56
Comments
class
instead of struct
class
instead of struct
+1 should be a struct |
Even with nullable structs, the code won’t be clean. You still need to check if it is default value. So the nullable struct is even uglier. |
That's only if we decide to use a
Then my translation to a native color looks something like
Where |
I also agree Color should be a struct... in fact, it should be a readonly struct, which will provide additional performance benefits. Also, by being a struct, Color could be casted to Vector4 in memory, opening the door for fast, bulk color operations: var pixelRow = new Color[256];
var vectorRow = MemoryMashall.Cast<Color,Vector4>(pixelRow); |
Wouldn't that require most internal methods to take What advantage does IMHO, it either stays a struct with Color.Default, or it becomes a class. |
This will cause a lot of micro allocations... as well as unexpected behaviors. Not to mention that it just instinctively feels unnatural 😛 Without knowing the reasoning behind why this was done, this seems like a poor decision to me. |
I have been back and forth on this one, but it is still a large breaking change that will affect users. Maybe. I am not sure exactly how this affects all the code when recompiled, but it is different.
This will matter though when there are new null ref exceptions popping up, but hopefully tooling can aid with that.
Most frameworks are structs - except for iOS - and this may be unexpected.
@jonlipsky did mention that he noticed some perf improvements with TouchDraw, but this might need a check on say Android with the GC. It may be that it is fine and the GC is OK and that copying structs is more expensive.
@Clancey mentions a nicer reading:
This is true, but it is also the same with
Color?
as a nullable.This also relates to #57 where there is no longer a
Default
"color" and null is used.Relates to parent issue: #58
The text was updated successfully, but these errors were encountered: