I have the following JavaScript code:

function tokensOnSameLine(node1, node2) {
    return node1.line == node2.line;

What would the preferred name for this function be? I've considered the following:

  • isTokensOnSameLine - sounds awkward but it matches the is convention for predicates.
  • areTokensOnSameLine - sounds good, seems reasonably clear.
  • tokensOnSameLine - okay, doesn't seem as obvious that it returns a boolean.

closed as primarily opinion-based by gnat, Blrfl, Robert Harvey, Bart van Ingen Schenau, user22815 Sep 27 '16 at 0:05

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.


When naming a function, consider how it appears to the reader when they come across it in code.

For example;

if (tokensOnSameLine(node1, node2)) { ... }
if (isTokensOnSameLine(node1, node2)) { ... }
if (areTokensOnSameLine(node1, node2)) { ... }

Given that, I'd probably go with tokensAreOnSameLine

if (tokensAreOnSameLine(node1, node2)) { ... }

Not the answer you're looking for? Browse other questions tagged or ask your own question.