Re: Re: [RFC] Importing namespaced functions

From: Date: Fri, 09 Aug 2013 21:43:25 +0000
Subject: Re: Re: [RFC] Importing namespaced functions
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hey Leigh,

I disagree that it suggests evaluation, but it could easily be a personal
interpretation thing.  In my interpretation, when looking at use
statements, I know nothing is being evaluated.  Symbols are being imported
into the namespace.  How likely is it that baz returns something that can
be imported as a symbol?   Would that even make sense as a feature,
importing the results of an evaluated function? Actually, given those two
questions, I can see how it would cause confusion if your initial
interpretation is that it is being evaluated.

For me, the parenthesis make it easier to read when scanning code.  When
scanning use statements, I'm not scanning the keywords, I'm scanning the
included names.  It's easier to look for parenthesis to denote functions,
it makes them stand out from the class names more. As in this example below:

use foo\bar\baz as baz;
use bar\foo\baz() as baz;
use bar\baz as bbaz;
use baz\foo\bar as bar;
use foo\bar() as bar;
use baz\bar as bbar;

Where as with "use function" I'd have to check back to the beginning of the
phrase to determine whether I was looking at a class name or function.

use foo\bar\baz as baz;
use function bar\foo\baz as baz;
use bar\baz as bbaz;
use baz\foo\bar as bar;
use function foo\bar as bar;
use baz\bar as bbar;

I think the difference mostly comes down to personal preference, and would
be somewhat alleviated by syntax highlighting.

Also, I have no knowledge of the PHP parser, so I have no idea how easy or
hard this would be to implement.

Daniel




On Fri, Aug 9, 2013 at 1:16 PM, Leigh <[email protected]> wrote:

>
> On Aug 8, 2013 9:31 PM, "Daniel Bingham" <[email protected]>
> wrote:
> >
> > Hey Igor,
> >
> > I love the RFC, but how about:
> >
> > use bar\baz() as baz;
> >
> > As an alternative to "use function".  Still new syntax, but a little less
> > wordy.
>
> The parenthesis add the feeling that it should be evaluated imho, I.e. the
> result of that function should be used as baz. That could possibly lead to
> confusion. I know you're suggesting as an additional syntax not
> alternative, but I don't get good vibes from it.
>
> Also might not even be possible due to how the parser handles parenthesis,
> but I'd have to look over the parser grammar to be sure.
>
> But another +1 from me on the RFC as a whole. Now its there I can't
> believe it took so long.
>


Thread (37 messages)

« previous php.internals (#68471) next »