Re: Better types without runtime checking
| From: | Yasuo Ohgaki | Date: | Tue, 12 Jun 2018 22:42:08 +0000 |
| Subject: | Re: Better types without runtime checking | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102241@lists.php.net to get a copy of this message | ||
On Mon, Jun 11, 2018 at 11:32 PM, Rowan Collins <rowan.collins@gmail.com>
wrote:
> Hi Rasmus,
>
> While I agree with your general point regarding consistency, I just want to
> take issue with sentence:
>
> On 11 June 2018 at 15:12, Rasmus Schultz <rasmus@mindplay.dk> wrote:
>
> > Hack made some very regrettable decisions in this area, and ultimately
> > those features were useful at design-time only, for IDE-support - but
> > we have php-doc for that purpose, and in my opinion, adding those
> > features before (or unless) we're willing/able to also make them work
> > consistently with the language, does more harm than good.
>
>
>
> As far as I know, every other language which has added type annotations to
> a dynamically typed language has done so either using an offline tool
> (treating them like compiler warnings), or as a debug-only run-time flag
> (treating them like assertions). The creator of "gradual typing", which is
> explicitly the basis of Python's type annotations, and at least implicitly
> used by many other languages, specifically stated that it was intended to
> be checked at compile-time, not run-time [1]:
>
Making "type hint" a "true type hint" is useful with DbC as well as static
analysis tools.
Perhaps,
declare(strict_types=-1); // -1 indicates assert() type check. i.e. asset
is disabled, no type checks.
How it should behave with object would be debatable.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net