3 ms·
I had some experience using things like these inpractice. Some tips I would give out * Make sure you make you library comprehensive. Remember that main benefit
by ufo 14y ago
I had some experience using things like these inpractice. Some tips I would give out
* Make sure you make you library comprehensive. Remember that main benefit of doing something like this instead of explicit functions is conciseness and consistent patterns.
* Partial function application can be tricky. I find it is only really useful if you use it on all most of the standard combinators and you need to pay very good attention to what is the order of arguments you use. I also suggest putting the arguments on the same line if you are doing partial functoins by hand like he did:
//This way you don't confuse partial functions
//and more general closures with inner state.
function get(attr){ return function(object){
return object[attr];
};}
* There are lots of way to do partial function application - do you let multiple arguments be passed at once or not? Do you allow for placeholder "hole" arguments or do the arguments have to always be passed in left-to-right order? What do you do with "this"? In the end I ended up having functions for all of the different cases but in general, I'd at least recommend not using null/undefined checks to test if arguments have been passed since that can easily mask dynamic errors. I'd rather check arguments.length explixitly or use a special placeholder object from my library if I need one.
* One of the big downsides of using partial function application and these combinators all over the place is that they make the call stack a lot more complicated. I use the JS debugger a lot and this can make things much more annoying to deal with. In particular, your "real" code gets hidden inside opaque "f" variables, its harder to set useful breakpoints and sometimes its harder to look at closed over variables.
* Another problem I had was that many of my coworkers were not used to the partial application and functional patterns. In the end we ended up using these combinators less and less, and now they are too rarely used to justify the "abstraction cost".