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

how to tersely name instance methods in classes (was Re: [PATCH 1/3]get rid of huge swathes of repetitive code in) POSIX.pm

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
August 31, 2011 07:55
Subject:
how to tersely name instance methods in classes (was Re: [PATCH 1/3]get rid of huge swathes of repetitive code in) POSIX.pm
Message ID:
20110831145533.GG23881@plum.flirble.org
On Sun, Jan 30, 2011 at 11:01:57PM +0100, Aristotle Pagaltzis wrote:
> ---
>  ext/POSIX/lib/POSIX.pm  |  437 +++++++++++------------------------------------
>  ext/POSIX/lib/POSIX.pod |    7 -
>  ext/POSIX/t/posix.t     |    2 +-
>  3 files changed, 104 insertions(+), 342 deletions(-)

I rather like the code culling this achieves. I've (mostly) applied it on
the branch smoke-me/POSIX, along with commits that add some tests for the
various exception messages.

> +    clearerr    => 'IO::Handle->clearerr',

> +    fclose      => 'IO::Handle->close',
> +    fdopen      => 'IO::Handle->new_from_fd',
> +    feof        => 'IO::Handle->eof',
> +    ferror      => 'IO::Handle->error',
> +    fflush      => 'IO::Handle->flush',
> +    fgetc       => 'IO::Handle->getc',
> +    fgetpos     => 'IO::Seekable->getpos',
> +    fgets       => 'IO::Handle->gets',
> +    fileno      => 'IO::Handle->fileno',
> +    fopen       => 'IO::File->open',

I specifically didn't apply the changes such as the above, because I'm not
yet convinced that error messages such as

    Use method IO::Handle->close() instead at -e line 1

are actually good enough. It's not a class method taking zero parameters.
I agree that the current message:

    Use method IO::Handle::close() instead at -e line 1

is also not good enough, but to my (C infested) mind that *can* be read both
as "function taking zero parameters" and "name of a subroutine, parameters
unknown", and my (Perl infested) mind knows that methods are just subroutines.
Maybe the error message should be:

    Use method close() on an IO::Handle object instead at -e line 1

Whatever is decided, your refactoring makes it much easier to change it.
Thanks.

Nicholas Clark

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