STYLE: Simplify bool assignments by removing if and else#5819
Open
N-Dekker wants to merge 1 commit intoInsightSoftwareConsortium:mainfrom
Open
STYLE: Simplify bool assignments by removing if and else#5819N-Dekker wants to merge 1 commit intoInsightSoftwareConsortium:mainfrom
bool assignments by removing if and else#5819N-Dekker wants to merge 1 commit intoInsightSoftwareConsortium:mainfrom
Conversation
dzenanz
reviewed
Feb 21, 2026
Replaced code like `if (x) b = true; else b = false;` with `b = x;`
Using Notepad++, Replace in Files, doing:
Find what: ^([ ]+ )if \((.+)\)\r\n\1{\r\n\1 (.+) = true;\r\n\1}\r\n\1else\r\n\1{\r\n\1 \3 = false;\r\n\1}
Replace with: $1$3 = $2;
Filters: itk*.*
[v] Match case
(*) Regular expression
Improved code readability by ensuring that the expression at the right hand side
of each assignment is a Boolean expression, rather than an integer expression.
67cae79 to
2a11738
Compare
N-Dekker
commented
Feb 21, 2026
| this->m_UpdatePoints = false; | ||
| } | ||
| // If number of points is greater than zero, update points | ||
| this->m_UpdatePoints = this->m_NumberOfPoints > 0; |
Contributor
Author
There was a problem hiding this comment.
8-fold reduction in number of lines. But it takes a little bit more time to comprehend what happens. I wonder whether that tradeoff is worth it.
@dzenanz I think it's worth it 😇 With my latest force-push I improved the readability by ensuring that the right hand side of the assignment is a Boolean expression, so that it no longer relies on implicit integer-to-bool conversion. Does this make the PR more acceptable to you?
I think it's quite clear to any C++ programmer that this->m_NumberOfPoints > 0 is a bool expression, right?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaced code like
if (x) b = true; else b = false;withb = x;Using Notepad++, Replace in Files, doing:
Improved code readability by ensuring that the expression at the right hand side of each assignment is a Boolean expression, rather than an integer expression.