On Wed, Jan 29, 2020 at 3:12 PM Claude Pache <claude.pache@gmail.com> wrote:
>
>
> Le 29 janv. 2020 à 19:42, Bishop Bettini <bishop@php.net> a écrit :
>
> Cons... have to enumerate everything, potentially lots of work to do that
> to update old code to use; edge cases I'm not thinking about.
>
>
> Not only it is much work (although it could be partially automated), but
> it does not make much sense.
>
> I’ve taken a random file (~650 LoC) in the codebase I’m working on. With
> `declare(strict_qualify=1)`, I would have to add:
>
> use function
> array_filter
> , array_flip
> , array_key_exists
> , array_keys
> , array_push
> , array_unshift
> , compact
> , ctype_digit
> , idate
> , in_array
> , is_int
> , is_string
> , ksort
> , ob_get_clean
> , ob_start
> , preg_match
> , sprintf
> , strlen
> , strncmp
> , substr_count
> , trim
> , usort;
>
A fair critique. Under the "goad use of wildcard import" pro, the quick way:
use \{*};
Any unqualified name is locked to the global namespace.
> I don’t see a clear advantage in declaring more than 20 global functions
> in each and every of the hundreds of files of the codebase—where it is
> evident that they are all global function (no, I don’t have a namespaced
> version of `is_int()`). Also, I think that there are better ways to
> discover if my colleague introduced surreptitiously a `system()` call in
> the codebase.
>
Well, first, it's faster as Tyson described in the RFC: those are opcoded
and bypass the namespace lookup.
Second, and I find this the best reason, that enumeration tells me quite a
bit about what that code does. I don't need to see the code to know that
it's compute oriented, doesn't touch resources (eg files), and is doing
what PHP does best: string and array manipulation. It also shows me that
code's doing output buffer manipulation, which seems out of place and
suggests that should be refactored out.
IOW, it's a really nice abstract / summary of what the code's doing. And
that's some very good insight.
> Some time ago, I’ve tried the alternative approach in two files: adding a
> backslash before each and every global function (carefully avoiding
> non-functions such as `isset()`, `empty()` and `list()`). Well, it reminded
> me of the good old days when I used TeX intensively, but objectively, it
> didn’t make the code more clear or more secure (I’ve not tested its
> velocity, though).
>
I agree: qualifying the name at the usage site doesn't add much value, IMO.
It's frankly more noise than anything else.