> On 23 Aug 2024, at 17:29, Rowan Tommins [IMSoP] <imsop....@rwec.co.uk> wrote:
>
> On Fri, 23 Aug 2024, at 10:58, Stephen Reay wrote:
>> Making relative function names do the opposite of relative class names
>> sounds like a great way to permanently kill any prospects of
>> encouraging developers to use regular namespaced functions in place of
>> static classes as "bag of functions", which is what we keep hearing we
>> should use - most notably on a recent RFC to embody the concept of a
>> static class.
>
> That's why I brought up the point about making it easy to explicitly say
> "relative to current", just as you can explicitly say "relative to global"
> with a single "\".
>
> It's also worth remembering that this whole discussion has no effect on using
> functions that are defined in a *different* namespace. The below code might
> benefit from function autoloading, but would not be helped, hurt, or changed
> in any way by any of the proposals in this thread:
>
> namespace Acme\Foo\Controller;
>
> use function Acme\StringUtils\better_strlen;
> use Acme\StandardUtils as Std;
>
> $foo = Std\generate_something();
> $len = better_strlen($foo);
> \Acme\Debug\out($len);
>
>
>
> Regards,
> --
> Rowan Tommins
> [IMSoP]
>
I understand what you are proposing, and I understand that it doesn't affect
using *other* namespaces.
But let's be realistic here: if adopted this would mean developers have to
understand and internalise two concepts of how relative-local (or unqualified
if you prefer that term) symbol names work, that are completely opposite to
each other, essentially forever, unless you expect yet another flop to follow
this flip?
This change would also break existing code that does "the right thing", and has
the potential to arbitrarily break perfectly valid userland code *any time a
new global function is added*, forever.
And the reason for all this was...
> prefixing all calls with `\`, or adding a `use function` at the top of every
> file is annoying and noisy.
For all the handwringing this list does over backwards compatibility breaks, it
absolutely astounds me that there is even consideration of such a massive BC
break, with the added bonus of guaranteed future BC breaks, to save typing one
character per function call (or realistically, configuring your IDE/code linter
to do it for you).
This whole discussion is predicated on "people don't use functions much so its
not a big BC break" literally at the same time as not one but two different
discussions about an RFC for function autoloading, specifically because we're
constantly being told that static classes are "wrong" and namespaced functions
are "right".
> Sorry to reply to the same message twice, but as a concrete example, consider
> this code:
I realise you replied to me twice, but for the sake of clarity let me be
perfectly clear:
I understand absolutely what you are proposing.
I'm saying it's a ridiculous idea (the whole concept, not just your specific
"solution") to propose that such a core facet of the language be changed,
because some people both "want the absolute best performance" but also "don't
like a leading backslash". Hidden BC breaks *forever* to gain 2-4% performance
benefit without typing "\". If you told me my calendar is wrong and today is
actually April 1st I would 100% believe you based the contents of this thread.
Cheers
Stephen