[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] Searching a symbol in code [Was: master c88b192 5/8: Rename member
From: |
Greg Chicares |
Subject: |
[lmi] Searching a symbol in code [Was: master c88b192 5/8: Rename member variables] |
Date: |
Sun, 29 Apr 2018 22:16:44 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
On 2018-04-28 16:53, Vadim Zeitlin wrote:
> On Fri, 27 Apr 2018 10:52:49 -0400 (EDT) Greg Chicares <address@hidden> wrote:
[...]
> GC> commit c88b192094b96f66e0ba97af2f22cf8fdab45d05
[...]
> GC> - :header_(header)
> GC> - ,width_(width)
> GC> + :col_header_(header)
> GC> + ,col_width_(width)
>
> Is it really such a good idea to use column_info::col_width_ as the full
> field name?
No, certainly not in the long term--it's nasty.
> I think column_info::width_ was perfectly unambiguous already
'width_' (variable) was already unambiguous, yes--but...
'width' (accessor) would have been ambiguous in the next commit (f6c8fa6c).
For now, I'm still trying to achieve a full understanding of this code,
and searching for '\<width\>' finds too many commentary lines.
Maybe after I've understood it we can make these names less nasty.
Here are a few random thoughts that occur to me:
- I've seen others use a prefix 'the_' in situations like this, but I
think the_width() is even worse than col_width().
- We could of course use 'get_' and 'set_' prefixes. That's probably
better than a fragment of the name of the owning class ('col_').
- However, I try to avoid 'get_' and 'set_' because they're generally
too verbose--ideally, no prefix would be needed:
int length() | length(int) | int length_ // ideal
int get_length() | set_length(int) | int length_ // not ideal
> and while I understand the argument about not using common words as
> identifiers to enhance grepability, I also think it shouldn't be overblown
> and lead us to conclude that we should use unique but cryptic or unique but
> overlong names everywhere: for better or worse, grep can't be used to
> explore C++ code structure in any case, so making it easier to use it
> shouldn't be the main goal.
Then let me describe exactly how I'm exploring this code, and maybe you
can show me a better way. In vim, I just move the cursor to 'column' and
press '*', then use 'n' and 'N'. I don't really want to type a complex
regex to indicate 'except after //'. What more powerful method am I
missing?
> But if we do it like this, then I think either the variables should use
> column_ prefix or the class renamed to col_info because using both prefixes
> in immediate vicinity of each other is just a recipe for cognitive
> dissonance.
Yes, I got stuck on this today:
for(std::size_t col = 0; col < column; ++col)
{
x += all_columns().at(col).col_width();
}
and it just made me think of "колоколоколокола".