develooper Front page | perl.perl5.porters | Postings from July 2018

Re: Allowing require to return false

Thread Previous | Thread Next
Tomasz Konojacki
July 26, 2018 00:16
Re: Allowing require to return false
Message ID:
On Wed, 25 Jul 2018 09:56:12 -0400
David Farrell <> wrote:

> Hi P5P folks,
> A feature of Perl I really don't like is requiring modules to return a true
> value. Here's why:
>    - It feels gross appending a "1;" to every module I write
>    - All Perl can do is croak with a generic error message that isn't very
>    useful: " did not return a true value".
>    - If a module encounters an init error should die with a meaningful
>    error message instead
>    - I don't think any other language has copied this feature ....
>    including Perl 6
>    - I would guess the only time any of us see this message is when we've
>    forgotten to append "1;" to a new module
>    - Removing it would not affect the vast majority (all?) of modules
> I'm a Perl source code newbie but I wrote about a couple of implementations
> here:
> I can imagine a few ways to do it:
>    1. Remove the feature altogether - this would be breaking change if any
>    modules use this feature
>    2. Make it a feature - this would be safer but I doubt anyone would use
>    the feature
>    3. Deprecate the error and remove it in a future version
> Frustratingly, I don't know if any of these are worth pursuing - I wonder
> if anyone would write modules that didn't return a true value as they
> wouldn't work on past versions of Perl. If we assume Perl is going to be
> used for another 25 years, then maybe it's worth it.
> What does everyone else think?
> Thanks in advance,
> David

Personally, I'd *love* to see this enhancement in perl. Having to put
'1;' at the end of module certainly puts off newcomers and does not
provide any real benefits.

However, I don't think returning false value when require succeeds is a
good idea. For modules without a positive return value, IMHO it should
be hardcoded to 1. It's a minor problem, but people sometimes write if
require(...). Of course, currently this would simply throw an exception,
so there is no breakage, but I think that, for consistency, require()
should always return a true value on success.

I'm sure someone will prove me wrong, but I believe implementing this
change would *not* introduce significant breakage, and thus, it
shouldn't require feature flag. I'm struggling to imagine how
real-life code relying on current require() behaviour would look like.

I'm almost certain that this change would cause *much* less trouble than
many of bugfixes introduced in recent major releases.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About