Skip to content

Comments

STYLE: Simplify bool assignments by removing if and else#5819

Open
N-Dekker wants to merge 1 commit intoInsightSoftwareConsortium:mainfrom
N-Dekker:Simplify-assignment-to-bool
Open

STYLE: Simplify bool assignments by removing if and else#5819
N-Dekker wants to merge 1 commit intoInsightSoftwareConsortium:mainfrom
N-Dekker:Simplify-assignment-to-bool

Conversation

@N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented 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.

@github-actions github-actions bot added type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module type:Style Style changes: no logic impact (indentation, comments, naming) labels Feb 21, 2026
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

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

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.

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.
@N-Dekker N-Dekker force-pushed the Simplify-assignment-to-bool branch from 67cae79 to 2a11738 Compare February 21, 2026 20:06
this->m_UpdatePoints = false;
}
// If number of points is greater than zero, update points
this->m_UpdatePoints = this->m_NumberOfPoints > 0;
Copy link
Contributor Author

@N-Dekker N-Dekker Feb 21, 2026

Choose a reason for hiding this comment

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

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?

@N-Dekker N-Dekker marked this pull request as ready for review February 21, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module type:Style Style changes: no logic impact (indentation, comments, naming) type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants