AB naming

At our team we have a lot of names for pair of interacting objects.

To be more clear let's take users. In messenger it's sender and receiver, in diary it's viewer and viewed, in profile it's visitor and visited and so on.

This goes worse when one have to name variable or argument for current user. It can be current, active, simply user or something else.

And this goes even worse when one dev has named an argument currentUser and other dev now have to choose a name for 'another' user. So in some places of code we have currentUser and receiverUser, activeUser and visitedUser or even currentUser and user.

These names are extremely confusing. And even more confusing for developers whose native language is not English.

To solve this problem I propose so called "AB naming".

A→B action

So actually we have some action from one object to another. Let's name the first object A and the second one — B, action from A to B. The scheme is super simple: A→B. Keep it in mind and you'll never ever be confused by names: userA performs an action against userB. Does it really matter who is 'current'?

Why this is so natural?

AB naming looks very natural (at least for me). And here are two main reasons.

  • A is the first letter, B — the second. In our brain A always goes first, 1 always looks more privileged. So this is natural for our language, our way of thinking.

  • Math in school. I don't know much about math education in other countries, but in Russia we have lots of excercises started with "From the point A to the point B...", all that segments AB and so on.

Here is how google search by pictures looks like with query "from a to b"

And there is even transport search engine called fromAtoB.com.


Of course, this rule have to be accepted by (or at least announced to) your team. But trust me, once you go this way, you'll never come back ;)

Posted on
Tagged in naming

PHP developer at Wamba.com

comments powered by Disqus