Remove apostrophe (“Old package separator”) as package separator

Preamble

Author:  Nicolás Mendoza <mendoza@pvv.ntnu.no>
Sponsor:
ID:      0015
Status:  Draft

Abstract

Remove support for ’ (apostrophe) as package namespace separator.

Motivation

From perldoc perlmod > The old package delimiter was a single quote, but double colon is now the preferred delimiter, in part because it’s more readable to humans, and in part because it’s more readable to emacs macros. It also makes C++ programmers feel like they know what’s going on–as opposed to using the single quote as separator, which was there to make Ada programmers feel like they knew what was going on. Because the old-fashioned syntax is still supported for backwards compatibility, if you try to use a string like "This is $owner's house", you’ll be accessing $owner::s; that is, the $s variable in package owner, which is probably not what you meant. Use braces to disambiguate, as in "This is ${owner}'s house".

Rationale

Alternatives

There are a few alternatives on how to disable this feature and changing the meaning of '

String interpolation of identifiers:

Identifiers elsewhere (variables, function declarations etc.)

Discussion

All of the above may be turned on or off using compiler flags, pragmas or extending warning::syntax

The current patch that I made some years ago is mostly like: 1 + b but cold turkey removing as much as possible without any flags or switches.

I think 2 + a would be an interesting approach to keep backwards-compatibility somewhat.

Both 1 and 2 changes interpolation behaviour, but we have been warning about it since 5.28: https://github.com/Perl/perl5/commit/2cb35ee012cfe486aa75a422e7bb3cb18ff51336

1w, 2w, 3 and 4 requires to keep around tick_warn in toke.c

c requires adding new code to warn correctly and keeping around ident parsing code:

$ perl -wlE 'sub foo'"'"'bar { "lol"; }; print foo'"'"'bar();'
lol

Specification

The feature should be rolled out in two steps, in two consecutive Perl stable releases

  1. Add warning code to apostrophe usage in identifiers (outside of string interpolation) (alternative 4) (as has been done for string interpolation already (alternative c)) [6]

  2. Syntax error when using apostrophe as part of identifiers outside strings (alternative b), treat apostrophes inside strings as not a part of a variable when interpolating (alternative 1)

Backwards Compatibility

This change will break backwards compatibility in two stable releases

Known core / dual-life modules utilizing apostrophe as separator

The following issues are slowly being sorted out independently of this PPC.

The following issues might need to synchronize with the perl releases by checking versions or feature flags

References

Conditions to test

…

Moreover, the need to parse it as a package separator sometimes affects its use as a string delimiter.

  sub foo { say $_[0] }
  foo"hi"; # works
  foo'hi'; # doesn't work

  foox"hi"; # String found where operator expected
  foo'"hi"; # Bad name after foo' (huh?)

It's not that hot as a synonym for :​: either​:

  sub foo' {} # Illegal declaration of subroutine main​::foo
  sub foo​:: {} # OK

  sub 'foo { say $_[0] }
  'foo 5; # Can't find string terminator "'"
  :​:foo 5; # OK

Copyright (C) 2022, Nicolas Mendoza

This document and code and documentation within it may be used, redistributed and/or modified under the same terms as Perl itself.