Naming of rows() and cols() functions
yongqli opened this issue · comments
This might seem like a nitpick, but I strongly prefer the name nrows()
over rows()
. I think of rows
as referring to the rows objects themselves rather than the count, which is a property they possess. (num_rows()
would work for me as well.) Is there any hope of adding nrows()
to BaseMatrix
as an alias to rows()
?
You're not the first person to suggest this which means we should give it some serious thought!
If I'm understanding correctly, your suggestion is to:
- Change current
rows()
tonrows()
. - Change current
cols()
toncols()
. - Change current
row_iter()
torows()
. - Change current
col_iter()
tocols()
.
I think @tafia suggested the same a while ago.
How do others feel about this?
I think this is down to different conventions. For example, Eigen uses rows()
/cols()
, while Armadillo uses n_rows()
.
I think in any case, it's better to choose a convention and stick to it than to start adding alias functions, which may give precedent for adding other aliases, and suddenly the various traits are bloated with way too many functions.
Personally I prefer rows
as it's what I'm used to from Eigen
, but from a somewhat more objective angle, nrows
doesn't work very well with autocomplete. That is, I think it should start with the word row
(i.e. row_count
, rows
or similar) so that you can easily navigate the API when you're not familiar with it.
I do however oppose renaming row_iter
to rows
, as I think it's not clear at all that rows
is an iterator, and I think being explicit about this is a good idea.
I think removing ambiguity in names is a good idea in any case. Actually, the more I think about it, the more I like row_count()
. It's more verbose, of course, but its purpose is clear as crystal and it's autocomplete-friendly.
I also wanted to make clear that although I prefer row_iter
over rows
for returning an iterator over the rows, I'm not very strongly opposed to this change, so if there is concensus on that I don't mind. There's already diag
which returns an iterator, so it wouldn't be unprecedented.