On 16/06/2024 16:24, Andreas Hennings wrote:
For a function call, the namespace is usually only visible in the
imports list at the top of the file.
This is one of those interesting cases where the language itself is
flexible, but people are used to a specific style: a use statement can
import any level of namespace, to provide as much or as little context
as needed in a particular piece of code.
namespace Acme\Artistry\Color {
function fromRgb($red, $green, $blue) { /*...*/ }
}
namespace My\Own\Application {
use Acme\Artistry\Color;
// ...
$color = Color\fromRgb(1,2,3);
// ...
}
Maybe that's rare in practice, but it's always tricky to judge how much
the language should account for such habits - see also "every class
needs a new file", and my pet hate "deprecation notices get promoted to
errors".
The class name that is part of a static method call hints at an object
type, whereas for a namespace fragment it may not be really clear what
it describes.
In a static factory call, like `Color::fromRgb($red, $green, $blue)`,
I would argue that having the class name as part of the call improves
DX.
This example seems slightly off: if the static method is on the class it
is a factory for, that class clearly isn't completely static.
Presumably what we're actually talking about is something like
"ColorFactory::fromRgb(...)" - or maybe
"GraphicsFactory::colorFromRgb(...)", where you might well want to
abbreviate to "colorFromRgb(...)".
Your points are generally well made, I just wanted to point out there
are some nuances in that particular area.
Regards,
--
Rowan Tommins
[IMSoP]