Do you use particular conventions for naming complementary variables?

language-agnostic, naming-conventions, variable-names

Solution

Like with all kinds of code style conventions, consistency is what you should strive for. I would have the development team agree on "standard" pairs of prefixes for common scenarios like "source/destination" or "from/to" and then stick with them for the whole project. As long as every developer is aware of what is meant with a particular prefix in the codebase, it is easier to avoid misunderstandings. Exceptions to the rule should be clarified in the documentation if the variable is part of a public API, or in comments within the code, if it's visibility is restricted to a single class or method.

Problem

I often find myself trying to come up with good names for complementary pairs of variables; where two variables denote opposing concepts, two participants in some sort of duologue, and so on. This might be better explained by a counter-example - I maintain an app that prints two graphics as part of a print advertisement. They're stored in the database as `TopLogo` and `LowerLogo`, which I have to stop and double-check every time I use them because I'm expecting `top` to complement `bottom`, and `lower` should complement `upper`. There's some obvious examples that I think work well: `client / server` `source / target` for copying/moving data or files from one variable to another `minimum / maximum` but there's some concepts that just don't lend themselves to such neat naming schemes. For example, when paging through records, does 'last' mean 'final' or 'previous' ? I recently saw some code that used `firstPage`, `previousPage`, `nextPage` and `finalPage` to avoid the ambiuous `lastPage` completely, which I thought was very beat, hence this question. Do you have any particularly neat variable name pairs you'd care to share with us? (Bonus points if they're the same length, which makes the code so much neater in monospaced fonts.)

Original source