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

Re: Allowing require to return false

Thread Previous | Thread Next
From:
Smylers
Date:
July 26, 2018 10:51
Subject:
Re: Allowing require to return false
Message ID:
164d626d9ec.118428301153832.6608226526745322401@stripey.com
David Farrell writes:

> A feature of Perl I really don't like is requiring modules to return a
> true value. ...
>
> Make it a feature - this would be safer but I doubt anyone would use
> the feature

A built-in (and reliable) feature for this would be an improvement on
the true module on Cpan; existing users of that module would benefit
from switching, which is a bigger group than ‘no-one’:
https://metacpan.org/pod/true

Obviously it's more work to enable the feature in each module than
simply to put the ‘1’ at the end. But it's useful for a toolbox or syntax
collector module to include it, as one of several things it enables or
imports to the using module.

And OO frameworks such as Moo or Moose may be interested in enabling
that feature for their users (like they do with strict and warnings).

Moreover, as a feature, it can be included in a version feature bundle.
So somebody starting their module with, say:

  use v5.30;

would automatically get this feature for free (along with strict, say,
better Unicode support, the // operator, and so on).

> I wonder if anyone would write modules that didn't return a true value
> as they wouldn't work on past versions of Perl.

Most public modules on Cpan avoid using new features that aren't
essential. Shortly after Perl v5.6 came out, it was irritating to
encounter modules that failed to work on earlier versions simply because
they had ‘use warnings’ in them.

However, any module which needs to use a recent version of Perl _for
some other reason_ would be free to make use of this as well, and omit
the trailing 1.

And, over time (several years), as users upgrade it becomes more
reasonable to rely on higher Perl version numbers. For instance, it's no
longer controversial for a Cpan module to use warnings — and probably
hasn't been for over a decade. There will come a point where sufficient
time and Perl releases have passed that public modules could reasonably
use this feature.

But, much sooner than that, private modules can do so. Many
organizations standardize on the Perl version they use internally. Once
an organization has upgraded to v5.30 everywhere, they could freely stop
putting pointless ‘1’s at the end of their modules.

> What does everyone else think?

The requirement for trailing ‘1’s are an awkward quirk, and we're better
off without it. Yes, it may be a while in the future before anybody
could feel the benefit, but changing the future is still better than not
changing the future (and considerably easier than changing the past).

That somebody was sufficiently bothered by this to write the true module
is evidence of interest; there must be many more who felt similarly but
weren't in a position to do something like that.

Smylers

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