On 2025-03-14 16:04, Jorg Sowa wrote:
Hello Juris, There is some uncertainty for me on how this approach
would work with namespaces.
Let's get this example:
https://3v4l.org/bI1Rj
I would expect to get the error message that I forgot to insert `use
Stringable;`.
But with your idea everything is fine. I don't like such ambiguity and
I worry it may bring some confusion to developers.
Kind regards, Jorg
Hi Jorg,
You are correct. We can't really distinguish whether an interface is
absent because the dependency is absent or because the name was
mistyped.
In practice I would not expect this to be a big issue. Adding a
?OptionalInterface would be a deliberate action when your objects needs
to pass a specific type check. In case of a typo the type check will
fail and the object will be rejected by the consumer.
I admit that it's not as nice as a compile-time error, but my point is
that the typo would still be easy to notice as it would break the whole
purpose of that interface implementation.
BR,
Juris