NFC: Remove Vector::From and replace it with aggregate initializati…#1703
Conversation
|
Overall I think this improves readability. This is a C++11 feature. |
rpavlik
left a comment
There was a problem hiding this comment.
Seems reasonable enough to me. If it's too noisy in the blame, can always use git blame ignore refs file thingie. As long as it actually worked (I know there are some slight differences between using this and calling a constructor with 3 params, e.g. fewer (or no?) implicit conversions happen, etc.), it looks nice to me. Less visual noise
…on {}
...in all places where it is possible.
The 34 remaining places either initialize a vector from handles or call a method of
the resulting vector object. For example `Vector::From(x, y, z).WithMagnitude(1.0)`
|
I think this change is fine. For example: Vector v = {}; // {0, 0, 0} Why not: Vector v = {0, 0, 0}; ? |
…ation ... and making the `ARC_LINE_LEN_RATIO ARC_LINE_DIFFERENCE` case similar to `EQ_LEN_PT_LINE_D` below it.
81782ee to
ad540f0
Compare
To minimize the difference and make review easier ;-) Otherwise the "right thing" to do is just |
It works - in the sense - opens, loads a few simple models, saves... Hopefully it does not hide some monster :-)
This is the reason I did it as well. |
@vespakoen After thinking more about your question I think that, while having the So I added two more commits:
And of course all of this should be squashed into one commit if we decide to merge it. Edit:This is easy to review even as a single change (in the "Files changed" tab). I went through everything one more time and noticed one more inconsistency (which I introduced in these change series): When declaring a
I do realize that the two are subtly different in semantics in the language. Which one do you guys/gals prefer? |
97d9588 to
c4ceeb5
Compare
I'm a fan of explicit, so of those two I prefer the = {}; I'm also kind of a fan of = {0, 0, 0} although that bothers me because it's an implicit conversion to double ;-) And using 0.0 would be way too verbose. |
Indeed the first time I started doing this I started changing all constants to |
|
I do like to use aggregate initialisation where possible. But I think it depends on the specific use case, and in some cases that I can see (such as in the case of EDIT: aside from the places where an empty initialisation list is passed to a function, which makes it less clear that the argument is a zero vector, another thing that I think could be improved with this change is the inconsistency wrt variable initialisation with the zero vector. In some places an assignment is used, whereas in others a direct initialisation syntax is used, and I think it would be best to use a single style throughout the code. As for muddying the history... while this argument has some merit, I don't think it should be used to block changes that modernise the code, as it would just lead to either stagnation or inconsistency when new code is introduced, which I think is even worse (also, judging from the the little history that I've seen, whitequark did accept rpavlik's ranged-for iteration changes, which also touched basically every source file, and for the most part were non functional, so I think at some point such a change might have been accepted as well 😃) |
I considered that as well. For the same reason I left the {0, 0, 0} in places where matrixes are initialized. I shall change the |
…of {}
In addition unify `Vector` variable initialization style.
|
Added on more commit: When passing a zero vector as a parameter use {0, 0, 0} instead of {} So shall we {squash and) merge this? |
Yes |
…on {}
...in all places where it is possible.
The 34 remaining places either initialize a vector from handles or call a method of the resulting vector object. For example
Vector::From(x, y, z).WithMagnitude(1.0)Explanation
Now that 3.2. is released and we have some time to potentially break things here is my "intrusive change".
[sorry for the massive spam]
@jwesthues @phkahler @rpavlik @vespakoen @ppd, this is something that has been bothering me for a while. It is the typical change that @whitequark would not have accepted - because it touches many, many files and "muddies" the history. So please consider this just a proposal and let's discuss it.
It is an "almost NonFunctionalChange" except that constants are replaced with
VERY_POSITIVEandVERY_NEGATIVEin a few places - an the values may not be exactly the same.@iscgar too, take a look at this - you seem to be the right type of person to give an opinion on it :-)