STYLE: Replace T var; var.Fill(x) with auto var = MakeFilled<T>(x)#5024
Conversation
581dcca to
c26c6f3
Compare
|
Builds upon #5023 |
|
Thanks Hans! Sorry, I overlooked the Examples when doing similar code clean-ups on ITK! I'm glad to see you do this follow-up. 👍 As I remarked in-line, I would prefer So I would suggest running the regex of pull request #4897 before adding the |
|
In general, I would suggest:
As I wrote at #4887 (comment) |
3e6e8ac to
32192c5
Compare
Another run to replaced code of the form
T var;
var.Fill(0);
with `T var{};`
Using Notepad++, Replace in Files, doing:
Find what: ^( [ ]+[^ ].* )(\w+);[\r\n]+ [ ]+\2\.Fill\(0\);
Replace with: $1$2{};
Filters: itk*Test*.cxx
[v] Match case
(*) Regular expression
The empty initializer list `{}` effectively zero-fills those variables.
Prefer Filled over MakeFilled for initializing Size<T> and Index<T> types Replace in Files, doing: Find what: ^( [ ]+)(SizeType)[ ]+(\w+);[\r\n]+\1\3\.Fill\( Replace with: $1auto $3 = $2::Filled\(
This involved moving variable initialization to the smallest possible scope. The more locally scoped variables allow for future automated code refactorings.
Identified code style improvements based on manually reviewing use of .Fill for assignment of values when initialization could have been used.
32192c5 to
6746ae4
Compare
|
Re: #5024 (comment) @N-Dekker Can this be put into the SWG and an ITK Example be added to the SphinxExamples repository? |
|
@jhlegarreta Thanks, I can have a look at how to clearly put that guideline from #5024 (comment) into the SWG:
By the way, the most important guideline should of course just be: initialize, initialize, initialize, as soon as possible! The choice between |
|
The dahsboard has started complaining about one or some of the changes introduced in this PR: |
|
I just tracked this down, but I see @jhlegarreta beat me to it. :) @hjmjohnson you able to fix? |
|
I made a PR for it: #5053. |
Suggested by Jon Haitz Legarreta Gorroño at InsightSoftwareConsortium/ITK#5024 (comment)
Suggested by Jon Haitz Legarreta Gorroño at InsightSoftwareConsortium/ITK#5024 (comment)
Replace in Files, doing:
Find what: ^( [ ]+)([^ ].*)[ ]+(\w+);[\r\n]+\1\3.Fill(
Replace with: $1auto $3 = MakeFilled<$2>(
Simplify the creation of containers with initial
values.
PR Checklist