Boost logo

Boost :

From: Jason Kraftcheck (kraftche_at_[hidden])
Date: 2006-11-10 12:13:30


Jason Hise wrote:

>>> There are two usability features that my implementation provides which
>>> yours does not. The first is being able to index a vector by name
>>> (_x, _y, _z, _w). This is easily implemented using a properly scoped
>>> enum. I used leading underscores for my component names as a
>>> convention to indicate that they were property names, though
>>> admittedly this naming convention could be debated.
>>>
>>> vector <float, 3> up;
>>> up[_x] = 0;
>>> up[_y] = 1;
>>> up[_z] = 0;
>>>
>> I've never found such a convention very useful. It is a trivial thing to add if
>> others do.
>
> I think it falls into the same category as not using magic numbers.
> To give another example, if you use a vector to store a color, being
> able to refer to the components as r, g, b, and a channels instead of
> by number improves readability. But perhaps enumerating these
> constants is better left to client code.
>

I also think that this is best left to the client code. The concept of a
mathematical vector should be kept separate from any domain-specific meaning
(Cartesian vector, color space, etc.) Also, I think its best not to pollute the
namespace with constants that are so likely conflict with other names.

- jason


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk