Re: [RFC] Scalar Type Hints
| From: | Andrea Faulds | Date: | Fri, 02 Jan 2015 14:06:20 +0000 |
| Subject: | Re: [RFC] Scalar Type Hints | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80095@lists.php.net to get a copy of this message | ||
Hey Jordi,
> On 2 Jan 2015, at 14:01, Jordi Boggiano <j.boggiano@seld.be> wrote:
>
> And I, on the other hand, disagree.
>
> Looking at it from an OSS maintainer perspective, introducing strict hints in code would be a
> huge BC break as I don't know how people use my code, nor if they validate/coerce their user
> input early or not. If I suddenly declare something as int and someone used to pass '5',
> they get an error. That would make adoption quite hard in OSS IMO if you don't want to bother
> people.
>
> With weak typing on the other hand, I get to remove tons of @param annotations which would be
> amazing, and I get additional safeties that *new* mis-uses (like passing an object in an arg
> expecting a string, which at the moment could not be type hinted) will be caught early in the
> future.
> Existing mis-uses probably don't exist much since they'd likely fail further down in
> the code execution already, but in case they don't they'd be caught too and that's a
> good thing since it makes people look at their buggy code.
> As for valid uses of the code, like the '5' above, it keeps working just fine because
> it is fine. It's not my call as a library author to decide whether the users of the lib should
> cast user inputs to ints or validate them or do nothing at all.
This is an excellent point which had never occurred to me before! Yes, weakly-typed hints like these
are far less likely to break existing code. I should probably mention that in the RFC.
Thanks!
--
Andrea Faulds
http://ajf.me/