Which initial is preferred for a non-type template parameter, N or V (`NDimension` or `VDimension`)?

According to our KWStyle file, a template parameter name must begin with either T, N, or V, if I understand correctly:

T is for type parameters, obviously. But which prefix is preferred for non-type parameters? N (for Non-type, or Numeric) or V (for Value)?

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.

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

Thanks for the statistics, @Lee_Newberg :+1:

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 :smiley:

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 Non-type (Numeric) parameters but you convinced me that there is a majority for V.