On Wed, Jun 22, 2016 at 7:44 PM, Rowan Collins <rowan.coll...@gmail.com> wrote: > > Out of curiosity, do these languages perform the type analysis at > compilation, or at run-time? I'm trying to collate some examples of how > other languages have approached the problem.
In Typescript, the type-hints are evaluated at compile-time only - there is no run-time footprint at all, which is why they're actually called "type annotations" in Typescript; they're just annotations serving as directives for the compiler. With Dart, you have a choice - you can actually toggle whether or no type-checks should be performed at run-time. It's probably the best of those two references, if you're looking for inspiration for PHP. In PHP, every type-check is performed at run-time, and type-hints are reflected - that's extremely important, and something Hack got horribly wrong, as the type-hints they introduced are merely annotations, with no run-time footprint, checked only by a static analyzer that runs in the background; completely inconsistent with type-checks in PHP. >> PHP feels crippled on this point - it's gradually-typed, >> but inconsistently so, and inconsistency is the worst kind of evil you >> can have in any programming language. > > I absolutely agree, we need a plan for how to introduce a consistent gradual > typing system. But this RFC is not that plan. Maybe it's imperfect in it's current state, but it sounds to me like it's pretty close? The only serious issue I've had to point at, is the inconsistency regarding references - but honestly, there are very (very) few reasons to use references in the first place; there is usually a much better solution with much less "wtf". (if I had to choose, honestly, I'd say deprecate references.) >> The learning curve for new users isn't increased by the introduction > > Except that this proposal doesn't actually make the language consistently > type-checked. It adds a few more special cases where you can use type hints, > with slightly different behaviour. That's not quite true. With the addition of property type-hints, the public surface through which you interact with objects would consistently support type-hints - so at least that makes object interactions and class design a lot more predictable. Yes, references are problem. Yes, type-hinted variables are a problem. But at least we're finally there as far as objects, which in PHP is probably the most important thing, as that's almost exclusively the means by which we share code. >> and then in addition they need to go and learn about >> php-doc and offline inspection tools and IDEs and so forth. > > Interestingly, this is the direction that Hack and Python have both > apparently chosen to enshrine - the syntax is baked into the language, but > not actually enforced by the standard compiler or run-time in any way. > Indeed, "gradual typing" as defined by Jeremy Siek only really makes sense > in the context of static analysis. Quoting Jeremy Siek: "Gradual typing allows software developers to choose either type paradigm as appropriate, from within a single language" - to me, that's the important thing about gradually-typed languages. Having worked with both Typescript and Dart, I can honestly say that I never missed run-time type-checks in Typescript, but on the other hand, I loved having reflection in Dart - I think it's not terribly important which approach a language takes, as long as it's consistent. PHP being a reflected and run-time type-checked language already, there is not much of a choice here; especially being a reflected language, having type-features that are available only in the context of static analysis, such as in Hack, would be highly problematic. I worked with Hack, briefly, and returned to PHP, one of the reasons being, things like generics and property type-hints did not support reflection, which meant that e.g. a reflection-based dependency injection container cannot grow to support and exploit those aspects of the language, which demonstrates why it's so important to be consistent: in Typescript, I would not have started writing a reflection-based DI container, because the language is not reflected, but in Hack, being a continuation of PHP, I would have naturally expected to continue in that direction. > Taking lots of little steps "towards" a goal that we've never even properly > defined is exactly what leads to *inconsistency* in the language. I don't disagree with that, and I think that's a large part of PHP's problems. But, on the other hand, we started down the road to gradual typing when we started adding type-hints - whether we knew what we were doing at the time or not, the next logical step down that road is property type-hints, which will at least clear up the number one biggest inconsistency as far as object and class design goes. > I think a number of people are not "anti-type-hints", they just don't agree > with this particular implementation. Very possible, and they may be right - but I really hope these people are doing something to help solve the problem, rather than simply killing the idea and offering no alternative. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php