Re: [RFC][Discuss] Arrow Functions
| From: | ilija dot tovilo at me dot com | Date: | Sat, 04 Feb 2017 15:40:05 +0000 |
| Subject: | Re: [RFC][Discuss] Arrow Functions | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98179@lists.php.net to get a copy of this message | ||
Hey Stephen
> You don't *have to* specify types at all. If you want to use PHP without
> verifying/requiring types, thats your prerogative, but given the recent improvements to allow scalar
> type hinting, I think it’s a mistake to say that *any* use of type hints is “not
> recommended”..
Sure you don’t but then you loose all the benefits of specifying types. We want typing but only if
we don’t have to specify types all over the place. I really dislike having to add PHPDocs
everywhere just to get some proper autocompletions.
> I'm not sure if you've mixed up your terms of if I'm too tired but I don't
> understand what you mean here. The short arrow function *is* the callee, and that’s where you’re
> suggesting we shouldn’t use type hints.
Sorry, that was confusing. I was thinking of a situation like this one:
```Swift
func fetchUsers(callback: ([User]) -> Void) {
...
}
```
So, the callee (
fetchUsers) defines what the provided closure must look like.
The caller, on the other hand, doesn’t have to specify that again as you’re just repeating
yourself.
```Swift
fetchUsers { user in
// user is inferred to be a User object
}
```
So I don’t think the burden of providing typing information should be on the caller providing the
closure.
> The whole issue with that is that using a pipe character could make things much less
> clear/readable if the already established use of pipe for “type unions” (currently used in
> multi-catch) were to be implemented for general type hint usage.
>
> Note: I’m not saying it’s not possible, but it’s *much* less readable, and any
> “solution” just adds more characters, which is apparently the only reason to not use
> function($foo) => $foo in the first place.
But again, that’s personal preference. I like short a precise and think it’s more readable. Not
everyone’s the same.
> For most people readability isn't just about the number of characters.
A lot of the time it is. Brains are very good at recognising patterns, they don’t need large
keywords for that.
As for me, I think it just adds clutter to the actual logic that I’m interested in.