Re: [PATCH 00/86] replace prefixcmp() with has_prefix()
- From
Jeff King <peff@peff.net>
- Date
- Nov 12, 2013, 20:14 UTC
- Message-ID
- <20131112201405.GA23418@sigill.intra.peff.net>
- In-Reply-To
- <xmqqy54timsm.fsf@gitster.dls.corp.google.com>
On Tue, Nov 12, 2013 at 08:53:45AM -0800, Junio C Hamano wrote:
Show 9 quoted lines
> Even though we already added has_suffix() for tail matches, it is > not too late to rethink, as it is not in 'master' yet. > > One thing I noticed is that it is probably misnamed, or at least in > a way that invites confusion. Can people tell which one of these is > correct without looking at existing callsites? > > has_suffix(filename, "txt"); > has_suffix(filename, ".txt");
To me, it is obviously the latter. My name for "thing at the end of a file after the dot" is "extension", not "suffix".
I thought that was universal, but if there are people who find it confusing, it is worth changing. After all, the point is to make the code more readable.
> The semantics of the function we have is the latter and is better > called endswith(), I suspect. And the corresponding function to > check for head matches should probably be called beginswith().
Those are OK to me. "has_suffix" would be my first choice, but if it is confusing to others, your suggestions are fine.
-Peff