Scoped binding of a method to an object

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Oct 15 10:31:56 PDT 2013


On Oct 15, 2013, at 9:44 AM, Benjamin (Inglor) Gruenbaum wrote:

> ...
> 
> The big issue I see here is chaining.  `_.reduce(_.map(_.filter([1,2,3,4,5],x=>x%2 === 0),x=>2*x),(x,y)=>x+y)`   
> Is a lot less readable than                `[1,2,3,4,5].filter(x=>x%2===0).map(x=>2*x).reduce((x,y)=>x+y))` 

first let me do a slight rewrite of the above to eliminate some semantic noise:

 import {reduce,map,filter} from "underscore2";
reduce(map(filter([1,2,3,4,5],x=>x%2 === 0),x=>2*x),(x,y)=>x+y)
vs 
[1,2,3,4,5].filter(x=>x%2===0).map(x=>2*x).reduce((x,y)=>x+y))

Nobody should be thinking of these as equivalent expressions of the same computation.  They aren't equivalent because the semantics of the identifiers "reduce", "map", "filter" are quite different in the two formulation.

They mean different things and when express this way it is pretty clear that they are different. I don't see how making them look more similar (while maintaining the semantic difference) would help with code clarity.

Allen


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131015/f1b37865/attachment.html>


More information about the es-discuss mailing list