On 11/08/2022 10:03, Alex Wells wrote:
You could argue the problem is that all of these are single-liners, so here are 
the same examples, but multiline formatted:


When people talk about avoiding one-liners, they're not just talking about whitespace, but other refactoring. For example, introducing intermediate variables:

$fileNameComponents = explode('_', $file->getName() );
$slicedComponents = array_slice($fileNameComponents, 4);
// (most likely there's a better variable name, which would explain *why* we're ignoring those components)
$className = Str::studly( implode('_', $slicedComponents) );

Or adding additional helper functions:

$fileNameComponents = explode('_', $file->getName() );
$slicedComponents = array_slice($fileNameComponents, 4);
$className = Str::studlyFromArray( $slicedComponents );

Or even, since "Str::studly" probably calls explode() internally anyway:

$className = Str::studlyWithSlice( $file->getName(), 4 );


>> On 11 Aug 2022, at 07:36, Paul Crovella <paul.crove...@gmail.com> wrote:
>>
>> An extension method would shift a single argument from inside parentheses to the left of the function name. It just moves it. I don't see any impact here.
>
> It doesn’t move it, it removes it. You’re technically not passing that value as an argument anymore anywhere in your code, your value becomes the implicit > expression you’re working with. That becomes even more obvious when multiple method calls are chained and don’t need to pass it into every function call.

I think what Paul means is that "$foo->bar($baz)" and "bar($foo, $baz)" have the same "words" - the "$foo" is there in both cases, just in different positions. The same is true of nesting vs chaining: "$foo->bar()->baz()" has the same "words" as "baz( bar( $foo ) )",  just in a different order.

I do agree that the left-to-right order is nicer to read than the nested version, but that's largely opinion - it's not actually any shorter.


Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to