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

STYLE: Replace T var; var = x with T var = x for arithmetic types #4932

Conversation

N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Nov 5, 2024

Following C++ Core Guidelines, Oct 3, 2024, "Always initialize an object"

Using Notepad++, Replace in Files, doing:

Find what: ^( [ ]+)([a-z][a-z ]*[a-z])([ ]+)(\w+);[\r\n]+\1\4\ =
Replace with: $1$2$3$4 =
Filters: itk*.*
Directory: D:\src\ITK\Modules
[v] Match case
(*) Regular expression

Excluded delete statements, even if they would match the regular expression (as in delete var; var = x).


The regular expression worked well in almost all cases. Almost... but here is an example where it went wrong, accidentally:

delete m_GlobalSingletonIndex;
m_GlobalSingletonIndex = nullptr;

Would be reduced to one line of code:

  delete m_GlobalSingletonIndex = nullptr;

Such accidental cases were manually excluded.

@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:Segmentation Issues affecting the Segmentation module type:Style Style changes: no logic impact (indentation, comments, naming) area:Numerics Issues affecting the Numerics module labels Nov 5, 2024
Following C++ Core Guidelines, Oct 3, 2024, "Always initialize an object",
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-always

Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)([a-z][a-z ]*[a-z])([ ]+)(\w+);[\r\n]+\1\4\ =
    Replace with: $1$2$3$4 =
    Filters: itk*.*
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Excluded `delete` statements, even if they would match the regular expression
(as in `delete var; var = x`).
@N-Dekker N-Dekker force-pushed the Replace-declaration-assignment-of-scalars branch from 1666742 to 5d0df7a Compare November 5, 2024 15:06
@github-actions github-actions bot added the area:Registration Issues affecting the Registration module label Nov 5, 2024
@N-Dekker N-Dekker changed the title STYLE: Replace T var; var = x with T var = x for scalars in tests STYLE: Replace T var; var = x with T var = x for arithmetic types Nov 5, 2024
@dzenanz
Copy link
Member

dzenanz commented Nov 5, 2024

Is this "ready for review"? If so, I think it can be merged.

@N-Dekker N-Dekker marked this pull request as ready for review November 5, 2024 23:41
@dzenanz dzenanz merged commit 5b121f4 into InsightSoftwareConsortium:master Nov 6, 2024
15 checks passed
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Nov 6, 2024
Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)([^ ].*\*)([ ]+)(\w+);[\r\n]+\1\4\ =
    Replace with: $1$2$3$4 =
    Filters: itk*.*
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Excluded  an unrelated case from "itkMINCImageIO.cxx" (`_sep = -_sep`), which
accidentally matched the regular expression.

- Follow-up to pull request InsightSoftwareConsortium#4932
commit 5b121f4 "STYLE: Replace `T var; var = x`
with `T var = x` for arithmetic types"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Nov 7, 2024
Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)([^ ].*\*)([ ]+)(\w+);[\r\n]+\1\4\ =
    Replace with: $1$2$3$4 =
    Filters: itk*.*
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Manually excluded an unrelated case from "itkMINCImageIO.cxx" (`_sep = -_sep`),
which accidentally matched the regular expression.

- Follow-up to pull request InsightSoftwareConsortium#4932
commit 5b121f4 "STYLE: Replace `T var; var = x`
with `T var = x` for arithmetic types"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Nov 7, 2024
Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)([^ ].*\*)([ ]+)(\w+);[\r\n]+\1\4\ =
    Replace with: $1$2$3$4 =
    Filters: itk*.*
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Manually excluded an unrelated case from "itkMINCImageIO.cxx" (`_sep = -_sep`),
which accidentally matched the regular expression.

- Follow-up to pull request InsightSoftwareConsortium#4932
commit 5b121f4 "STYLE: Replace `T var; var = x`
with `T var = x` for arithmetic types"
hjmjohnson pushed a commit that referenced this pull request Nov 7, 2024
Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)([^ ].*\*)([ ]+)(\w+);[\r\n]+\1\4\ =
    Replace with: $1$2$3$4 =
    Filters: itk*.*
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Manually excluded an unrelated case from "itkMINCImageIO.cxx" (`_sep = -_sep`),
which accidentally matched the regular expression.

- Follow-up to pull request #4932
commit 5b121f4 "STYLE: Replace `T var; var = x`
with `T var = x` for arithmetic types"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Nov 7, 2024
For Standard Library types that have a non-trivial default-constructor and a
non-trivial assignment operator, `T var = x` is typically slightly faster than
`T var; var = x`. Otherwise it's just a matter of style.

Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)(std::[^ ]*)([ ]+)(\w+);[\r\n]+\1\4\ =
    Replace with: $1$2$3$4 =
    Filters: itk*.*
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Follow-up to pull request InsightSoftwareConsortium#4932
commit 5b121f4
"STYLE: Replace `T var; var = x` with `T var = x` for arithmetic types"
hjmjohnson pushed a commit that referenced this pull request Nov 9, 2024
For Standard Library types that have a non-trivial default-constructor and a
non-trivial assignment operator, `T var = x` is typically slightly faster than
`T var; var = x`. Otherwise it's just a matter of style.

Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)(std::[^ ]*)([ ]+)(\w+);[\r\n]+\1\4\ =
    Replace with: $1$2$3$4 =
    Filters: itk*.*
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Follow-up to pull request #4932
commit 5b121f4
"STYLE: Replace `T var; var = x` with `T var = x` for arithmetic types"
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:Numerics Issues affecting the Numerics 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.

3 participants