3 ms·
Clever is fine as long as things are somewhat self-explanatory. At least in this example, the get() method name is confusing. Get is a customary well known me
by ww520 14y ago
Clever is fine as long as things are somewhat self-explanatory. At least in this example, the get() method name is confusing. Get is a customary well known method name to extract a property of a map or object, and making the call now. The usage context in the example is that it is a parameterizes getter function that's passed in to splat to be called later. Perhaps it would be clearer if it's called getter('total') or accessor('total'). That shows it's building a parameterized actor function, and it can be passed around and called later.
In working with functional code, I prefer naming high order functions with an actor connotation.
- raganwald 14y agoThat's really interesting. It's especially interesting if you think of this: function get (object, propertyName) { return object[propertyName]; }; So now, what is: rcurry(get)?
- ww520 14y agoGood question. Let's re-arrange the get method a bit to make it easier for currying demonstration. function get (propertyName, object) { return object[propertyName]; } The method 'get' does what it's named, to get the property now in the call. Curry(get('age')) creates a separate entity that parameterizes get with the 'age' property. It's a new function object different from get. But at least the term curry(get('age')) gives some visual cue to the code readers as what it does vs just get('age'). For languages (e.g. Haskell) that implicitly curry everything, it's understood that any missing parameter means a curried function has been created and the actual call is deferred. Javascript is not such language. Mixing in the naming convention for implicit curry just causes confusion for the readers. Javascript's currying is explicit with pattern such as, getter(get, 'age'), which would wrap a function around the get function with a closure {propertyName: 'age'}. I think it's best to consider the audience and the convention of a language when naming things.