Re: [PATCH v2 05/10] log-tree: use ref_namespaces instead of if/else-if
- From
Derrick Stolee <derrickstolee@github.com>
- Date
- Aug 4, 2022, 20:17 UTC
- Message-ID
- <94705746-809a-48ee-2aae-6f2878222f95@github.com>
- In-Reply-To
- <xmqq8ro36h5i.fsf@gitster.g>
On 8/4/2022 1:40 PM, Junio C Hamano wrote:
Show 40 quoted lines
> Derrick Stolee <derrickstolee@github.com> writes:
>
>> My current workaround is to define the size of the array in the
>> header file:
>>
>> ---
>>
>> enum ref_namespace {
>> NAMESPACE_HEAD,
>> NAMESPACE_BRANCHES,
>> NAMESPACE_TAGS,
>> NAMESPACE_REMOTE_REFS,
>> NAMESPACE_STASH,
>> NAMESPACE_REPLACE,
>> NAMESPACE_NOTES,
>> NAMESPACE_PREFETCH,
>> NAMESPACE_REWRITTEN,
>>
>> /* Must be last */
>> NAMESPACE__COUNT
>> };
>>
>> /* See refs.c for the contents of this array. */
>> extern struct ref_namespace_info ref_namespaces[NAMESPACE__COUNT];
>
> Because there is no reason why we want to keep the size of the array
> opaque in this particular case, it may even be preferrable over the
> original ref_namespace[] array of unspecified size. Nice.
>
> BTW, I prefer to name my arrays with a singular noun, when the
> predominant use of it in the code that is an API customer is to name
> an individual element and use it.
>
> In this case, many API users do things like
>
> ref_namespace[NAMESPACE_NOTES}.ref = ...;
>
> so a singular name would be more appropriate. thing[4] that means
> the fourth thing feels more intuitive than things[4], at least to
> me.This makes sense to me.
Show 9 quoted lines
> On the other hand, when API customers mostly pass the whole thing > around as an almost opaque collection to the API function, then a > plural name is more appropriate. The reason why I focus on API > customers is because API implementation of course has to go in to > each individual element of the array and work on it at some level, > and "individual access means singular name" rule would become non > workable. The names are mostly to help API customers, so if an > array is perceived by them as mostly a collection of things, then > naming it in plural would make it more natural.
Understood. I think this array does not seem to fit this second case, so I will change it to be singular.
Thanks, -Stolee