Re: [PATCH] contrib/diff-highlight: multibyte characters diff
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Feb 13, 2014, 01:17 UTC
- Message-ID
- <20140213011753.GD4582@vauxhall.crustytoothpaste.net>
- In-Reply-To
- <20140212232740.GA11098@sigill.intra.peff.net>
On Wed, Feb 12, 2014 at 06:27:40PM -0500, Jeff King wrote:
Show 11 quoted lines
> 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.
That said, $DAYJOB is a Perl shop, and I would certainly not reject this code in review, and depending on the situation, I might even write something like this. I personally think it's fine.
-- brian m. carlson / brian with sandals: Houston, Texas, US +1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187