With apologies, this is essentially the same question as I attempted to frame in Refactoring technique?, but I finally think I've got enough of a handle on the problem to ask the right question; but not yet the solution.
(Please excuse (or ignore) the presence of JavaScript code in the following; the question pertains to all languages, and I'm bored with mocking up Perl substitutes.)
In the code I'm refactoring I've (mechanically) abstracted out three recurrent conditions, without (previously) understanding what it was they really tested:
var condX = ( ( this.Parent.Fi < 90 ) || ( this.Parent.Fi >= 270 ) + ); var condY = ( this.Parent.Fi >= 180 ); var condZ = ( this.Parent.Th <= 0 );
Obviously, condX, condY & condZ are not great names. I've finally worked out what it is that they control. (For those coming to this fresh, the code constructs 3 reference grids around a graph (chart) that is rotatable in all 3 dimensions.)
First off; those names were my "best guess" before I'd tied them down, and are not right.
And ditto for terms like X-axis/horizontal and Y-axis/vertical, etc.
But when things can be rotated in all dimensions, left can become right; up, down; back, front, min, max; so naming things in code that can be called with stuff in any state of rotation becomes a nightmare.
Often, you can get around this problem by naming variables in terms of the model view: that is, pretending you are standing on the 'floor' of the bounding box and rotate with it (without gravity messing things up) and name them in terms relative to that viewpoint.
But equally often, and as is the case of the conditionals above, the ordinates being represented are relative to the viewer's perspective; ie. world coordinates. That is, the decision of what faces to draw is determined in terms of which faces are 'behind' the model, thus not obscuring the model (graph) from the viewer.
And that I think is the key. Whatever the orientation, the faces to be draw are the three of the six that are 'furthest' from the viewer; but even with that insight, I'm still stuck for how to name them. And as each of those conditions is reused 4 times each, I think they definitely do need to be named.
So to the question: what would you name them?
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |