git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] contrib/diff-highlight: multibyte characters diff

From
Jeff King <peff@peff.net>
Date
Feb 13, 2014, 01:37 UTC
Message-ID
<20140213013751.GA11355@sigill.intra.peff.net>
In-Reply-To
<20140213011753.GD4582@vauxhall.crustytoothpaste.net>
On Thu, Feb 13, 2014 at 01:17:54AM +0000, brian m. carlson wrote:
Show 18 quoted lines
> On Wed, Feb 12, 2014 at 06:27:40PM -0500, Jeff King wrote:
> > On Wed, Feb 12, 2014 at 11:10:49PM +0000, Thomas Adam wrote:
> > 
> > > On 12 February 2014 20:59, Jeff King <peff@peff.net> wrote:
> > > > +sub decode {
> > > > +       my $orig = shift;
> > > > +       my $decoded = eval { decode_utf8($orig, Encode::FB_CROAK) };
> > > > +       return defined $decoded ?
> > > 
> > > I'd still advocate checking $@ here, rather than the defined $decoded check.
> > 
> > I don't mind changing it, but for my edification, what is the advantage?
> 
> The documentation for decode_utf8 isn't clear, but I don't know if it
> can ever return undef.  What, for example, does it return if $orig is
> not defined?  That's the benefit: it's immediately clear to the user
> that you're interested in whether it threw an exception, rather than
> whether it produced a given value.

I'd argue that I am more interested in whether it returned a value. Let us imagine for a moment that decode_utf8 could return undef without throwing an exception. What should the function return in such a case?

I think the only sensible thing is the original (and to indicate that the result was not converted).

-Peff
Previous: brian m. carlsonNext: Yoshihiro Sugi
Message 7 of 8 in “contrib/diff-highlight: multibyte characters diff”
  1. contrib/diff-highlight: multibyte characters diffYoshihiro Sugi, Feb 11, 2014
  2. Junio C HamanoFeb 11, 2014
  3. Jeff KingFeb 12, 2014
  4. Thomas AdamFeb 12, 2014
  5. Jeff KingFeb 12, 2014
  6. brian m. carlsonFeb 13, 2014
  7. Jeff KingFeb 13, 2014
  8. Yoshihiro SugiFeb 13, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.