Skip to content

STYLE: Use macros to Set/Get ivars in Common operators#2568

Closed
jhlegarreta wants to merge 2 commits intoInsightSoftwareConsortium:mainfrom
jhlegarreta:UseMacrosToSetGetMemberVariablesInCommonOperators
Closed

STYLE: Use macros to Set/Get ivars in Common operators#2568
jhlegarreta wants to merge 2 commits intoInsightSoftwareConsortium:mainfrom
jhlegarreta:UseMacrosToSetGetMemberVariablesInCommonOperators

Conversation

@jhlegarreta
Copy link
Copy Markdown
Member

Use macros to Set/Get ivars in Common operators.

Take advantage of the commit to leave the documentation of the ivars only
in their corresponding Set/Get methods, as dictated by the ITK SW Guide.

PR Checklist

@github-actions github-actions Bot added area:Core Issues affecting the Core module type:Style Style changes: no logic impact (indentation, comments, naming) labels Jun 2, 2021
Comment thread Modules/Core/Common/include/itkLaplacianOperator.h
@jhlegarreta jhlegarreta marked this pull request as draft June 2, 2021 03:26
@jhlegarreta
Copy link
Copy Markdown
Member Author

Not sure about what the errors imply:
https://open.cdash.org/viewBuildError.php?buildid=7260537

Suggestions are welcome.

Comment thread Modules/Core/Common/include/itkNeighborhoodOperator.h Outdated
@jhlegarreta jhlegarreta force-pushed the UseMacrosToSetGetMemberVariablesInCommonOperators branch from 949d6fc to 5f3afd4 Compare October 2, 2021 23:19
@jhlegarreta
Copy link
Copy Markdown
Member Author

Push forced to see the error reports back and see where we were at this level.

@jhlegarreta jhlegarreta force-pushed the UseMacrosToSetGetMemberVariablesInCommonOperators branch 2 times, most recently from 8a85994 to 7945ba4 Compare October 3, 2021 12:52
@N-Dekker
Copy link
Copy Markdown
Contributor

N-Dekker commented Oct 3, 2021

I'm sorry but I still don't like to have a virtual keyword added to those Get and Set member functions. Especially when they were originally non-virtual, and when they worked just fine without a virtual keyword. The only reason for adding virtual to an existing member function should be that some user actually needs to override it.

C++ Core Guidelines C.132: Don’t make a function virtual without reason says on this topic:

Redundant virtual increases run-time and object-code size. A virtual function can be overridden and is thus open to mistakes in a derived class...

We already spent a lot of time in the last few years, removing virtual from the ITK code base, and we're still not finished. Removal of virtual might break legacy user code, even while it is an improvement to new user code, which is why Bradley (@blowekamp) introduced a ITK_ITERATOR_VIRTUAL macro, for legacy support.

#if defined(ITKV4_COMPATIBILITY)
# define ITK_ITERATOR_VIRTUAL virtual
# define ITK_ITERATOR_OVERRIDE override
# define ITK_ITERATOR_FINAL
#elif !defined(ITK_LEGACY_REMOVE)
# define ITK_ITERATOR_VIRTUAL virtual
# define ITK_ITERATOR_OVERRIDE override
# define ITK_ITERATOR_FINAL final
#else
# define ITK_ITERATOR_VIRTUAL
# define ITK_ITERATOR_OVERRIDE
# define ITK_ITERATOR_FINAL
#endif

So please only make a member function virtual when it is actually needed!

@jhlegarreta
Copy link
Copy Markdown
Member Author

Thanks for the comment @N-Dekker . Then, as pointed in this comment of yours I'll mark it to status:Blocked until the proposed itkGetConstNonVirtualMacro gets added to the ITK code base.

@jhlegarreta jhlegarreta added the status:Blocked Blocked by some other issue which needs to be resolved first or by some other cause label Oct 3, 2021
@jhlegarreta jhlegarreta force-pushed the UseMacrosToSetGetMemberVariablesInCommonOperators branch from 7945ba4 to b342c89 Compare October 7, 2021 01:56
@jhlegarreta
Copy link
Copy Markdown
Member Author

10fce06 might go somehow unnoticed inside the PR and unless one takes a look at the commit history, but did not want to push a PR that added code that was not exercised. Also, I am not sure if all these would get extensive use with time. Open to suggestions.

virtual type Get##name() const { return this->m_##name; } \
ITK_MACROEND_NOOP_STATEMENT

/** Get built-in type. Creates a non-virtual member Get"name"() (e.g., GetVisibility());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Niels' PR is more comprehensive, so I would wait with this PR until #2785 is resolved. Then rebase this on top of that, which would make this PR somewhat smaller.

@stale
Copy link
Copy Markdown

stale Bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@stale stale Bot added the status:Use_Milestone_Backlog Use "Backlog" milestone instead of label for issues without a fixed deadline label Apr 16, 2022
@hjmjohnson
Copy link
Copy Markdown
Member

@jhlegarreta Is this still something that needs to be worked on? If so, could you please rebase and make a game plan for what needs to be done?

@stale stale Bot removed the status:Use_Milestone_Backlog Use "Backlog" milestone instead of label for issues without a fixed deadline label Aug 3, 2022
@jhlegarreta
Copy link
Copy Markdown
Member Author

@jhlegarreta Is this still something that needs to be worked on? If so, could you please rebase and make a game plan for what needs to be done?

Thanks for the heads-up Hans. Still on my ToDo list; have not had the time too look at my ITK-related ToDo list in a while. I do think this still deserves having a go. Not sure when I'll be able to take it up, though.

Also, wisest might be to wait until what is mentioned here is resolved/done: #2568 (comment)

Introduce non-virtual variants for the getter and boolean macros.

Use macros to Set/Get ivars in `Common` operators.

Take advantage of the commit to leave the documentation of the ivars only
in their corresponding Set/Get methods, as dictated by the ITK SW Guide.
 Fix typo in `itkGetConstReferenceMacro` macro documentation.
@hjmjohnson hjmjohnson force-pushed the UseMacrosToSetGetMemberVariablesInCommonOperators branch from b342c89 to 925ea3f Compare November 11, 2024 14:57
@hjmjohnson
Copy link
Copy Markdown
Member

@jhlegarreta I rebased on top of master. Is there more work that needs to be done to this PR? My reading is that all the issues have been dealt with.

@hjmjohnson hjmjohnson marked this pull request as ready for review November 11, 2024 14:58
thewtex
thewtex previously approved these changes Nov 11, 2024
@thewtex thewtex dismissed their stale review November 11, 2024 20:11

CI identifies spelling of "overridden"

@jhlegarreta
Copy link
Copy Markdown
Member Author

@N-Dekker expressed concerns about this, but going over the files I do not see any of these members being virtual, and inspecting the commits I do not see where they were being declared as virtual. Sorry @hjmjohnson. @N-Dekker do you think that we should still wait till you have time to resolve #2785 to merge this?

@hjmjohnson
Copy link
Copy Markdown
Member

Per the request to consolidate the scattered virtual / override / final design conversation around ITK Get/Set macros, I've opened #6232 (Master tracking — virtual / override / final semantics on Get/Set macros for ITK 6.x) as a single venue.

It pulls in the 2018 Discourse #814 precedent (the same final-as-stress-test technique and the @phcerdan / @N-Dekker 18–24% HoughTransform performance gain), the 2026-05-07 final-keyword audit (17 base methods overridden across 19 files in upstream ITK), and a draft additive itkVirtualSetMacro family on hjmjohnson:macro-optionally-virtual @ ffc70ed0b9. Surfaces 7 binary/short-list questions — Q1 (default-emit virtual?) is the load-bearing one this PR is blocked on.

Suggest holding further design comments on this thread until #6232 has a maintainer-quorum answer on Q1; otherwise the conversation re-fragments. This thread can stay open as the implementation venue once direction is settled.

@jhlegarreta
Copy link
Copy Markdown
Member Author

Closing after offline discussion with @hjmjohnson so that work can make progress without this being a roadblock.

@jhlegarreta jhlegarreta closed this May 8, 2026
@jhlegarreta jhlegarreta deleted the UseMacrosToSetGetMemberVariablesInCommonOperators branch May 8, 2026 07:03
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 status:Blocked Blocked by some other issue which needs to be resolved first or by some other cause type:Style Style changes: no logic impact (indentation, comments, naming)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants