Vote up!

4

What's a better name: tag1 or tag_1 ? Should it be tag-1 or tag_1 ?

Or the same question can be asked as: what's a better name: tag1 or tag-1? Depending on if underscores are disallowed, or dashes are disallowed.

While we are on the topic of dashes vs underscores, check out when to capitalize HTML classes, and when to keep ids in Pascal Case.

The answer is, in my opinion, that tag-1 is preferable to tag1. That is so because, when you're rushing to write code, tag-1 with a little more space between the two tokens is slightly more readable. 

Of course, another question is: are they really two tokens, or one? To this, each programmer should answer specifically in each particular case. (A similar question is: would tag1-1 make sense in this context?) If it really is one token and not two, then perhaps they should not be separated by a dash. In fact, this is why I always write "lineitem" as a single word: it isn't two things (a line and an item), it is one thing, one token. Same for things like userset.

Previously, at one point I had to create many names such as tag1, tag2, ... as parts of a devops task. It is then I discovered that I made fewer mistakes if I added a readable separator, and kept the name slightly lengthier: tag_1. Which is what I recommend in the manner of the naming convention. 

Please login or register to post a comment.