rubocop / rubocop/ruby-style-guide

bitwise vs. logical operators for boolean arithmetic

Open
#300 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Approved New Rule
Dominant language
No language data
Stars
16.5k
Forks
3.3k
PR merge metrics
No merged PRs in 30d

Description

| and || both work for boolean arithmetic, e.g. in

some_flag = false
some_array.each do |element|
    some_flag ||= do_something(element)
end

||= could be interchanged with |=. Similarly with & and &&. However, traditionally the single character operators | and & are used for bitwise arithmetic, whereas the double character operators || and && are used for boolean arithmetic. I can't think of a good reason for breaking from this tradition, whereas adhering to tradition follows the Principle of Least Surprise, therefore I'm considering submitting a pull request to add this guideline. However I'd welcome other opinions before I do so.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with issue #300 and review its six comments to understand whether consensus exists on a boolean-operator guideline. The issue body is the only entry point mentioned; done would require an agreed guideline and a clear decision recorded in the style guide.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.