Re: [PATCH 02/12] Convert starts_with() to skip_prefix() for option parsing

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 02/12] Convert starts_with() to skip_prefix() for option parsing

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:59:30

Duy Nguyen [off-list ref] writes:
On Sat, Dec 21, 2013 at 4:31 AM, Junio C Hamano [off-list ref] wrote:
quoted
Jeff King [off-list ref] writes:
quoted
  /* here we care if we saw the prefix, as above */
  if (parse_prefix(foo, prefix, &the_rest))
      ...

  /*
   * and here we do not care, and just want to optionally strip the
   * prefix, and take the full value otherwise; we just have to ignore
   * the return value in this case.
   */
  parse_prefix(foo, prefix, &foo);
Sounds fine.  I recall earlier somebody wanting to have a good name
for this thing, and I think foo_gently is *not* it (the name is
about adding a variant that does not die outright to foo that checks
and dies if condition is not right).

        starts_with(foo, prefix);
        strip_prefix(foo, prefix, &foo);

perhaps?
I still need consensus on the name here guys, parse_prefix.
remove_prefix or strip_prefix? If no other opinions i'll go with
strip_prefix (Jeff's comment before parse_prefix() also uses "strip")
Yup, that comment is where I took "strip" from.  When you name your
thing as "X", using too generic a word "X", and then need to explain
what "X" does using a bit more specific word "Y", you are often
better off naming it after "Y".

Re: [PATCH 02/12] Convert starts_with() to skip_prefix() for option parsing

From: Jeff King <hidden>
Date: 2016-06-15 22:59:31

On Thu, Dec 26, 2013 at 11:27:10AM -0800, Junio C Hamano wrote:
quoted
I still need consensus on the name here guys, parse_prefix.
remove_prefix or strip_prefix? If no other opinions i'll go with
strip_prefix (Jeff's comment before parse_prefix() also uses "strip")
Yup, that comment is where I took "strip" from.  When you name your
thing as "X", using too generic a word "X", and then need to explain
what "X" does using a bit more specific word "Y", you are often
better off naming it after "Y".
FWIW, the reason I shied away from "strip" is that I did not want to
imply that the function mutates the string. But since nobody else seems
concerned with that, I think "strip" is fine.

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help