Name a predicate function that takes multiple objects [closed]

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.

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)) { ... }

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *