Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify boolean comparison #103

Merged
merged 5 commits into from
Dec 21, 2020
Merged

Clarify boolean comparison #103

merged 5 commits into from
Dec 21, 2020

Conversation

rikhuijzer
Copy link
Contributor

@rikhuijzer rikhuijzer commented Dec 20, 2020

This is a bit confusing for readers (or, at least to me):

if x != false
  f()
end
if x == true
  g()
end

@codecov
Copy link

codecov bot commented Dec 20, 2020

Codecov Report

Merging #103 (be09028) into master (36128a7) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #103      +/-   ##
==========================================
+ Coverage   82.75%   82.76%   +0.01%     
==========================================
  Files          12       12              
  Lines        1461     1462       +1     
==========================================
+ Hits         1209     1210       +1     
  Misses        252      252              
Impacted Files Coverage Δ
src/scanner.jl 83.42% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 36128a7...be09028. Read the comment docs.

@rikhuijzer rikhuijzer changed the title Omit comparisons with boolean constant Clarify boolean comparison Dec 20, 2020
@rikhuijzer
Copy link
Contributor Author

Hmm, chomping == true is not logically equivalent to !isnothing(chomping) because when chomping is false, then the former is false and the latter is true. I'll just put it back.

@kescobo
Copy link
Collaborator

kescobo commented Dec 20, 2020

I can see how that would be confusing, thanks for doing this! If I can presume on your time a bit more, I think it would be worth adding a comment above that said of operations saying # chomping may be Nothing or Bool, and then (1) change the following conditional to if chomping (since this is logically identical to if chomping == true and (possibly) nest it inside of the other conditional (possibly with short-circuit notation chomping && push!(...)

@rikhuijzer
Copy link
Contributor Author

You're welcome. I think it is cool to see that even 8 years old code can be changed (8 years according to git blame). According to Lehman, these changes are necessary: "[T]he quality of an E-type system [software performing a real-world activity] will appear to be declining unless it is rigorously maintained and adapted to operational environment changes".

I have tried to use chomping && push!(...) but this failed when chomping === nothing. So, instead I split the cases up and I think it is now much clearer. Let me know if you don't agree.

Copy link
Collaborator

@kescobo kescobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right. The way you have it now bothers some "don't repeat code" aesthetic, but I agree that it's probably clearest this way, and simple enough that it's not likely to cause problems.

@kescobo
Copy link
Collaborator

kescobo commented Dec 21, 2020

Not sure why travis is still trying to fire after we moved to github CI - everything is passing here.

@kescobo kescobo merged commit bf95078 into JuliaData:master Dec 21, 2020
@rikhuijzer rikhuijzer deleted the patch-2 branch December 21, 2020 15:30
@rikhuijzer
Copy link
Contributor Author

Oh right. The way you have it now bothers some "don't repeat code" aesthetic, but I agree that it's probably clearest this way, and simple enough that it's not likely to cause problems.

Agreed about the DRY. Anyway, thanks for merging 👍 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants