Re: [PATCH 00/86] replace prefixcmp() with has_prefix()
- From
Christian Couder <chriscool@tuxfamily.org>
- Date
- Nov 12, 2013, 20:43 UTC
- Message-ID
- <20131112.214357.1022923291448967795.chriscool@tuxfamily.org>
- In-Reply-To
- <xmqqy54timsm.fsf@gitster.dls.corp.google.com>
From: Junio C Hamano <gitster@pobox.com>
Show 14 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"); > > 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().
I don't know if has_suffix() is confusing for a native speaker.
After a look at some languages, Python has "startwith()" and "endswith()", and Java has "startWith()" and "endsWith()".
So I agree that it is a good name. But while we are at it, why not "ends_with()" and "begins_with()"? To me using an underscore seems more consistent with what we are doing in Git.
Thanks, Christian.