On 2024-07-28 15:54, Mike Schinkel wrote:


Many (all?) of the functions the Go team adds could have been written in 
"userland" but they represent such common use-cases that the Go team decided to 
make them easy and obvious. They even soft deprecate functions and structs that are not 
ideal and replace them with ones with better names and better signatures. If Go had 
started with the string and array functions PHP has today they would almost certainly 
replaced them by now, ~15 years into Go's tenure.

It is a shame that PHP's culture is so hostile towards adding functionality 
that could also be added in userland, especially when that functionality would 
simplify and standardize algorithms that are non-obvious and/or too easy to 
implement incorrectly. If the PHP culture embraced moving common use-cases into 
core it would make PHP much more pleasurable to program in and make it much 
less likely that PHP programs would have bugs and/or security vulnerabilities.

I, too, wish there was more willingness to add useful functions to core. Just saying "they can be implemented in userland" is a bit of a cop-out because, duh, PHP is Turing-complete. A lot of the existing array functions could be replicated by userland (ab)use of array_reduce, and yet no-one would suggest removing them, and if they'd been absent a lot of people would be asking for them.

Anyone else wish that sort() took its argument by value instead of by reference? (Solvable in userland.) Or how about a named argument that allowed you to provide a key function to sort on instead of a comparator? (Solvable in userland.) Okay, the first change would break a lot, but an alternate sorted() function that did behave that way could be added.


On Jul 27, 2024, at 6:14 PM, Morgan <weedpac...@varteg.nz> wrote:
Why a SHA2 algorithm? Why not a SHA3 one? How about standalone functions for 
both, and then when SHA4 comes along (as it inevitably will) another standalone 
function for one of its variants?

Yes. Yes, And Yes.

And ideally within a `\PHP` namespace.

At that point you've got \PHP\sha3() instead of hash("sha3-?"), and now you've (a) lost the word "hash" indicator of what's going on, and (b) hidden the choice of "?" from the user. I'm not really seeing an improvement.

Reply via email to