According to our KWStyle file, a template parameter name must begin with either T
, N
, or V
, if I understand correctly:
<InternalVariables>m_[A-Z]</InternalVariables> -->
<SemicolonSpace>1</SemicolonSpace>
<EndOfFileNewLine>1</EndOfFileNewLine>
<Tabs>1</Tabs>
<Spaces>3</Spaces>
<Comments>/**, *, */,true</Comments>
<Namespace>itk</Namespace>
<NameOfClass>[NameOfClass],itk</NameOfClass>
<IfNDefDefine>[NameOfClass]_[Extension]</IfNDefDefine>
<EmptyLines>2</EmptyLines>
<Template>([TNV]|D|unsigned int|int|bool|QMatrix|B[12]|typename|class|U|R|InputImage|Arguments|Function|vecLength|Output)</Template>
<Operator>1,1</Operator>
<Header>Utilities/KWStyle/ITKHeader.h,false,true</Header>
</Description>
T
is for type parameters, obviously. But which prefix is preferred for non-type parameters? N
(for N on-type, or N umeric) or V
(for V alue)?
I see both NDimension
and VDimension
in the ITK repo. No big deal, of course. I’m just wondering if there’s a preference anyway.
dzenanz
(Dženan Zukić)
February 7, 2022, 4:26pm
2
I thought that V
is preferred (VDimension
), but I don’t know. Maybe someone from history of that file could answer?
In existing code, NDimensions?
is found 1638 times and VDimensions?
is found 1718 times. People seem to be fairly split on this. Strangely, VDimension
is seldom plural but NDimensions
is seldom singular.
cd git/ITK
find . -type f | egrep '\.(h|c)(xx|pp|)$' | fgrep -v ThirdParty | \
xargs egrep '[^A-Za-z_]NDimensions?[^A-Za-z_]' | wc -l
find . -type f | egrep '\.(h|c)(xx|pp|)$' | fgrep -v ThirdParty | \
xargs egrep '[^A-Za-z_]VDimensions?[^A-Za-z_]' | wc -l
Lee_Newberg:
In existing code, NDimensions?
is found 1638 times and VDimensions?
is found 1718 times. People seem to be fairly split on this. Strangely, VDimension
is seldom plural but NDimensions
is seldom singular.
Thanks for the statistics, @Lee_Newberg
Strictly speaking one might say that an N -dimensional image has N dimensions (plural). But as itk::ImageBase::ImageDimension
is singular, I got used to it, eventually
I think I mostly use the N
as prefix for non-type template parameters, but I wouldn’t mind switching to V
, if that would be preferred.
My case-insensitive string search of the ITK Software Guide (April 2021) shows 10 instances of unsigned int v
… as template parameters, but 0 for unsigned int n
… as template parameters.
More counting: there are 102 files that would need to be modified to change N
template parameters to V
template parameters across the board.
cd git/ITK
find . -type f | egrep '\.(h|c)(pp|xx)?$' | fgrep -v ThirdParty | \
xargs egrep -l '<(.*, )*(unsigned )?int N[A-Za-z_]*(, .*)*>' | wc -l
There are 39 distinct changes involved:
cd git/ITK
find . -type f | egrep '\.(h|c)(pp|xx)?$' | fgrep -v ThirdParty | \
xargs egrep -o '<(.*, )*(unsigned )?int N[A-Za-z_]*(, .*)*>' | \
cut -d : -f 2 | sort | uniq -c | fgrep --color=always ' N'
I made a pull request to change N
prefix to V
and to change Dimensions
to Dimension
: https://github.com/InsightSoftwareConsortium/ITK/pull/3171
2 Likes
Great job, @Lee_Newberg
Personally I still like the N
for N on-type (N umeric) parameters but you convinced me that there is a majority for V
.