Perl 7: A Modest Proposal
Tags: perl, perl7
Published: 2021-02-08 02:02:57

My previous two blog posts ([Perl 7: A Risk-Benefit Analysis](http://blogs.perl.org/users/grinnz/2020/07/perl-7-a-risk-benefit-analysis.html) and [Perl 7 By Default](http://blogs.perl.org/users/grinnz/2020/08/perl-7-by-default.html)) explored the reasons that a Perl 7 with incompatible interpreter defaults would be a mistake. Subsequently, Perl experienced a [crisis of governance authority](https://perl7faq.grinnz.com/#what-happened-to-the-announced-plans-for-perl-7) as several core developers also expressed this view. So I will not be further discussing the idea of changing defaults in Perl major versions. But, as I had stated in conclusion:

> I believe making good use of a new major version is extremely important to portraying the continued and forward development of Perl to the wider programming community. A major version with major features can be a significant boon to jumpstart the stagnating perception of Perl and bring it in line with the reality of its development.

So then, what should we do? I have some suggestions.

## Stable signatures

The widely lauded [signatures feature](https://perldoc.perl.org/feature#The-'signatures'-feature) is currently still experimental to facilitate experimentation with [several more important features](https://www.nntp.perl.org/group/perl.perl5.porters/2019/11/msg256677.html) that are needed for it to be considered feature-complete. However, at this point the basic design is well tested and stabilized, and has been unchanged for the requisite [two stable releases](https://perldoc.perl.org/perlpolicy#experimental). I propose that in Perl 7, the signatures feature be declared stable as-is, added to the `:7.0` feature bundle, and these further additions to be developed as a separate initiative. The new additions could trigger distinct experimental warnings until stabilized, or be added under one or more new experimental features as appropriate. (Stabilization of the signatures feature has now been [proposed](https://github.com/Perl/perl5/issues/18537) by Paul Evans.)

## Remove misfeatures

The [indirect](https://perldoc.perl.org/feature#The-'indirect'-feature), [multidimensional](https://github.com/Perl/perl5/pull/17808), and [bareword_filehandles](https://github.com/Perl/perl5/pull/18073) features being added in Perl 5.34 (well, indirect is already in Perl 5.32) are "negative" features; the behavior has existed in Perl for quite a while, but the presence of the named features allow disabling them lexically. These misfeatures are not considered best practice and lead to confusing issues, and the ability to disable them, or at least complain loudly upon encountering their use, has been available from CPAN modules for some time; a modern feature bundle should disrecommend their use. I propose removing these three features from the `:7.0` feature bundle.

## Apply warnings

Since `v5.12` or `5.012`, the [use VERSION](https://perldoc.perl.org/functions/use) keyword has enabled `strict` alongside the appropriate feature bundle. I propose that Perl 7 finally has `use VERSION` enable both the recommend `strict` and `warnings` pragmas when a version of 7 or higher is requested.

## Apply utf8

The [utf8 pragma](https://perldoc.perl.org/utf8) declares that the current source file is encoded in UTF-8 rather than the native single-byte encoding (usually ISO-8859-1). (This is unrelated to functions in that namespace such as `utf8::decode` as well as other UTF-8 related behavior like that provided by the [open pragma](https://perldoc.perl.org/open).) Zefram [previously proposed](https://www.nntp.perl.org/group/perl.perl5.porters/2017/10/msg246838.html) that this pragma be gradually made default and thus a no-op, to better match the expectations of modern programming. Along with and in anticipation of this step, I propose that Perl 7 has `use v7` also do the equivalent of `use utf8`.

## All Together

* Declare 'signatures' feature stable as is
* Add 'signatures' feature to :7.0 feature bundle
* Remove 'indirect', 'multidimensional', and 'bareword_filehandles' negative features from :7.0 feature bundle
* Apply effect of 'use warnings' with 'use v7' or higher
* Apply effect of 'use utf8' with 'use v7' or higher

Instead of this (note: `use v5.32` already includes `strict`):

```perl
use v5.32;
use warnings;
use utf8;
use experimental 'signatures';
no feature qw(indirect multidimensional bareword_filehandles);
```

New, modern code will simply be able to write:

```perl
use v7;
```

And instead of this:

```shell
$ perl -Mstrict -Mwarnings -Mutf8 -Mexperimental=signatures
    -M-feature=indirect,multidimensional,bareword_filehandles
    -E'sub dumphex ($str) { printf "%vX", $str } dumphex "☃"'
```

Modern oneliners will be able to get the same effect from:

```shell
$ perl -M7 -E'sub dumphex ($str) { printf "%vX", $str } dumphex "☃"'
```

## Looking to the Future

We must consider not only what Perl 7 should be, but what Perl should be beyond this milestone. Following from the above proposal for what Perl 7 and `use v7` could entail, this naturally leads to a flexible, powerful, and considerate method of promoting stable features and a modern programming environment.

Past [feature bundles](https://perldoc.perl.org/feature#FEATURE-BUNDLES) have been changed rather rarely but at seemingly random versions which are difficult to recall even for the most attentive Perl hacker. Since the introduction of feature bundles in Perl 5.10, they have only changed in 5.12, 5.16, 5.24, and 5.28. Thus my final proposal is that we no longer change feature bundles in arbitrary releases, but only in (true) major versions, which provide significantly more memorable junction points and opportunity for advertisement of these important features.

There are several features currently in the experimental, design, or CPAN prototyping phase that portend to further improve the modern Perl experience, many of which Paul Evans discussed in his [FOSDEM 2021 talk](https://video.fosdem.org/2021/D.perl/perl_in_2025.mp4):

* [isa](https://perldoc.perl.org/feature#The-'isa'-feature)
* [signatures improvements](https://www.nntp.perl.org/group/perl.perl5.porters/2019/11/msg256677.html)
* [try/catch](https://github.com/Perl/perl5/issues/18504)
* [match/case](https://www.nntp.perl.org/group/perl.perl5.porters/2020/06/msg257494.html)
* [Cor OO](https://github.com/Ovid/Cor/wiki)

Any of these features which are not stable and ready for inclusion in a `v7` feature bundle, as well as any that are built in the meantime, can be revisited for `v8`. Each successive major version bundle can continue to promote the best practices of Perl features and help users evolve their usage of modern Perl with a clear, simple declaration. And most importantly, each major version including 7 can be scheduled once a sufficiently exciting new modern feature set is stable and ready to `use`.

Perl 7 is dead. Long live Perl 7.

[*Reddit comments*](https://www.reddit.com/r/perl/comments/lfvtbi/perl_7_a_modest_proposal/)