rubocop / rubocop/ruby-style-guide
"if not" vs "unless"
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 16.5k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
Maybe a question more than an issue: I've gravitated toward using if not in certain circumstances, and I've figured out why:
In situations where I expect the condition to be false, and the code will normally run, I use unless:
unless name.empty?
puts "Hello #{name}"
end
However, whenever I expect the condition to be true, and the code will not normally run, I use if not:
if not name == 'Paul'
STDERR.puts "Unauthorized!"
end
Most people would probably use unless across the board, but in the latter example I'd find that difficult to understand at a glance, simply because the words "if" and "unless" have this semantic meaning associated with them. I'm interested in thoughts on this. This isn't something I particularly planned, so it's really not an attempt to over-complicate: I fell into this pattern of use because of my brain finding it easier to grok the keywords this way, and I eventually realised what I was doing. Thoughts?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with issue #329 and read its 29-comment discussion to understand the competing interpretations of if not and unless. Since the issue is framed as a question rather than a requested edit, completion would require an agreed style-guide position and a clearly identified documentation change.
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
- Needs clarification
- Newbie friendliness
- 18/100