Re: [RFC] Return Type Declarations pre-vote follow-up
Hi!
> Our view is that this code was *already* wrong. The type annotations
> don't make it more or less wrong. What they do let you do is enforce,
Of course it is wrong. The whole point of having strict typing is to
catch wrong code. If everybody would write only right code, we wouldn't
need any type checks - everything would be ok anyway (not correct for
some compiled languages as there types also tell the compiler how to
convert values to bits, but true for languages like PHP).
> once the annotation is in place, that it's correct moving forward for
> the places that are annotated. (And if you want to go fix up and
The whole point is that it won't be correct. In your model, when you use
typed function, essentially you know nothing about its return type, as
somebody could have overridden it with function returning anything. So
the only thing typing is useful for in your model is to document our
wishes about types. We already have that with @returns.
> your entire hierarchy all at once -- gradual conversion of existing
> code was an important feature when we were adding the Hack type
> system onto PHP.
My opinion is that we should not add features that do not make sense
conceptually. I have my issues with strict typing in php in general,
which I voiced at length here on the list already, but at least I can
see some internal logic in the concept, even though I still think it's
not the best fit for dynamic languages (neither Python nor Ruby nor
Javascript, to take three most popular ones, have it). But at least,
repeating, internal logic of knowing the variable type past the check is
there. What you are proposing is essentially documentation-only - you
can never know when you call a method what you are actually getting,
unless you explicitly check the object type for exact match (which
current strict typing syntax doesn't even allow). This is lacking even
internal logic, so I don't see how it makes sense to have such concept
in PHP.
> typechecker, or even by a human. The type "static" tends to be what
> you want. But this isn't a huge deal -- "self" as proposed isn't
> *wrong*.
That depends on the method - I can see cases for both. Consider this:
class Toy {
static function ToyFactory($toy_class): self {
return new $toy_class;
}}
The one with static would have different semantics than the one with self.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Thread (15 messages)