Kudose wrote:I am not a JS guru, but with anonymous functions, do you think we'll see PHP libraries that use them heavily like MooTools or jQuery?
What exactly do you mean by "use"?
bpat1434 wrote:I don't think so. Mainly from the point of maintainability. For example, look at Weed's post. It's difficult (at best) to maintain an even workflow between functions, and heck, even to remember what's being passed around to what when and what value it really has!
I am not clear as to what you mean by "maintain an even workflow between functions". Granted, the example was trivial, but your latter point does not resound with me: I could tell without much difficulty that comparator_sort is a function that returns a function that sorts an array based on the given comparator, and that map_sort is a function that returns a function that sorts an array based on a generated comparator that applies the given function to each pair of elements and compares the results by natural ordering.
Besides, I would expect normal library usage to be more like providing usort than providing utility functions for functional programming. The library user would thus have the option of writing a named function to provide to the library function, or writing an anonymous function if it is appropriate. Consider a less generic version of Weedpacket's example that is pre-PHP 5.3:
$data = explode(' ', "I've got a lovely bunch of bananas");
usort($data, create_function('$a, $b', 'return strnatcmp(strlen($a), strlen($b));'));
print_r($data);
If Weedpacket's utility functions were not available, we need not write them since we could directly translate the above example into something somewhat cleaner in PHP 5.3:
$data = explode(' ', "I've got a lovely bunch of bananas");
usort($data, function($a, $b) { return strnatcmp(strlen($a), strlen($b)); });
print_r($data);