develooper Front page | perl.perl5.porters | Postings from February 2011

Re: [PATCH 1/3] get rid of huge swathes of repetitive code in POSIX.pm

Thread Previous | Thread Next
From:
John Imrie
Date:
February 1, 2011 11:09
Subject:
Re: [PATCH 1/3] get rid of huge swathes of repetitive code in POSIX.pm
Message ID:
4D485A62.6040605@virginmedia.com
On 01/02/2011 15:56, Aristotle Pagaltzis wrote:
> * John Imrie<j.imrie@virginmedia.com>  [2011-01-31 20:35]:
>> On 31/01/2011 10:20, Aristotle Pagaltzis wrote:
>>> * Dagfinn Ilmari Mannsåker<ilmari@ilmari.org>   [2011-01-31 10:45]:
>>>> Aristotle Pagaltzis<pagaltzis@gmx.de>   writes:
>>>>
>>>>> +    if (my $how = $replacement{$func}) {
>>>>> +	croak "Unimplemented: POSIX::$func() is C-specific, stopped" if not defined $how;
>>>>> +	croak "Unimplemented: POSIX::$func() $$_" if ref $how;
>>>>> +	croak "Use method $_() instead of POSIX::$func()" if $how =~ /->/;
>>>>> +	croak "Unimplemented: POSIX::$func() is C-specific, use $_ instead";
>>>>> +    }
>>>> s/\$_/\$how/g ?
>>> woops, good catch. Thanks for the feedback. It’ll be fixed when
>>> I send the patches to perlbug.
>> Isn't this a good candidate for a given/when construct?
>>
>> given ($replacement{$func}) {
>>      when (! defined) { croak "Unimplemented: POSIX::$func() is
>> C-specific, stopped"; }
>>      when (ref)       { croak "Unimplemented: POSIX::$func() $$_"; }
>>      when (/->/)      { croak "Use method $_() instead of POSIX::$func()"; }
>>      default          { croak "Unimplemented: POSIX::$func() is
>> C-specific, use $_ instead"; }
>> }
> I’m not sure.
>
> I don’t find the code significantly clearer either way and
> I didn’t want to modernise without a clear win in readability.
>
> I do like that it makes naming the value unnecessary, though.
>
> Does anyone have a strong opinion about this suggestion?
>
> Regards,
A bit more research and I discovered that I could have written

when (undef) { croak "Unimplemented: POSIX::$func() is
C-specific, stopped"; }

instead of

when (! defined) { croak "Unimplemented: POSIX::$func() is
C-specific, stopped"; }

John

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About