open to voting: which is a better name for the rec...
# thinking-together
e
open to voting: which is a better name for the record structure holding a 2d point with fields x, y, and a record structure holding a 3D point (x y z).? Since record names by convention in my language always begin with a_ to give clue as to the name kind, the two logical alternatives are: a_point, a_point3, or the two records could be called a_xy, a_xyz? which do you think is better? a_xy is shorter, but not that much faster than a word like point which happens to have the letters in adjacent fingers for the first 4 letters, which is very fast to type...
i
I like how thi.ng handles this. You have explicit vec2 and vec3 when you want to use performance-optimized functions to manipulate them. But you can also just use arbitrarily long arrays of numbers, and treat them as 2d or 3d or 4d (etc) vecs using functions that work in arbitrary dimensions when that's more convenient. So I'd say go with a_point2 and a_point3 when you have an explicit number of dimensions, and a_point when you want to be unspecific. Also, saying a_xy and a_xyz means you're assuming these are cartesian coordinates. Often, in cases where you're doing work in 2-space or 3-space, you're also doing work in color space (rgb) or texture space (ts) or normal space (uvw). By keeping your linear algebra library generic, and not baking in the assumption that you're only ever working with cartesian coords, you save yourself some pain when it comes time to use these points (or vectors) in different ways. Lastly, it's worth thinking about whether you're someday going to have matrices (where your vectors might be column or row matrices), or use homogenous coordinates (where a 3d point or vector in space is represented by 4 values, where the 4th represents whether it's a point or a vector), or a Clifford algebra (where you have a bivector instead of a cross product). In these cases, sticking with terms like "point" and "vector" is more useful than using "xyz" to establish the name, since not all things that have an x, y, and z are the same. Summary: Go with "point".
👍 1
d
In this kind of circumstance I look to see if there is a de-facto name for the concept that is already in widespread use. For these types, I use the names
vec2
and
vec3
, copied from GLSL. Several of my C++ library dependencies also use these names. (This assumes that 3D point and 3D vector are represented by the same type, which might not be true for your system.)