Stas,

> For non-interchangeable types it is already strict by definition. I
> > don't see a problem with type hints that make life easier on both the
> > caller (by generating better error messages) and the callee (by having
> > to write less boilerplate type verification code).
>
> It doesn't make the life of the caller easier. On the contrary, it makes
> each call into a minefield - will it blow up with a system-level error
> when you call it?


Well, I'm not so sure that I agree there. If you're passing an incompatible
type, it's an application level error, not a runtime level one. And
additionally, it enables better defensive programming where code ensures
what's passed is what it needs (and the language helps enforce that).
Similar to design-by-contract...


> Added bonus of this one is that there's no sure way to
> check for it - at least for callable we had is_callable, here we just
> have to add boilerplate code for every call.


I don't think you need boilerplate for every call. Either you create what
you're going to pass to said function call, or you type-hint it properly on
that method. The onus is on the creator of the variable, not the consumer.

Additionally, we could add other is_* functions for these agregate type
hints. is_iterable(), etc...


> And good luck making them
> handle it in an unified way - since it's not library code, then probably
> will do each different thing, and about 50% of places will forget it or
> not know downstream inserted this surprise into the execution stream.


How would downstream affect you? I would understand upstream, but I don't
get that point... Could you elaborate further?


> > You may have a point on the ad-hoc nature of it and that we need to do
> > it once and for all in a more organized fashion, but the basic premise
> > looks ok to me.
>
> I think the basic premise (PHP needs more strict typing that it is
> completely unable to properly handle and that leads to runtime errors
> that had no choice but blow up the whole app) is wrong, but ad-hoc
> implementation of it by just dragging random pieces into the type system
> is even more wrong.
>

It's a Recoverable error, so no, it doesn't have no choice but to blow up
the whole ap. You can install an error handler and recover from them. The
point being that it pushes the call-time checks used by defensive
programming into the language instead of as requiring a lot of copy-paste
to validate arguments...


> Note that no other dynamic language is doing such things. I wonder why.
>

Well, that's an odd point, because almost all of the other dyanmic typed
languages (at least of the popular ones) are object oriented at core. So
this sort of type hinting can be done by `assert($obj instanceof Foo)`.
With PHP, given the first-class primitives, this is not as straight
forward. I'm not saying that we shouldn't take cues from other languages,
but to implement or not based on what other languages do is a bit odd,
given that PHP is unique in a lot of ways from those other languages...

Just my $0.02 at least...

Anthony

Reply via email to