last day (15 days later) » 

5:04 PM
hola
 
Hey - I also really like your thinking about fatigue. But another cure for that (which you deftly applied in your answer to the promise all OP) is factoring
 
He has the perfect storm - two nested loops, async side-effects, data transformation, ...and an error.
 
yeah, a mess!
 
It is much easier to reason about when it is pure data transformation
 
But on loops, can you address my point directly? Your count Nums example with a filter generates a garbage array.
 
5:07 PM
As soon as you add a loop, you have to reason about runtime behaviour
My brain power is limited
A garbage array is nothing
Developer reasoning is waaaaaaaaaay more expensive than an intermediate array
 
Agree on brain power. But if I asked you to write a new method on the standard array class, to be shipped with all future JS, called countElementsPassingTest. How would you write it?
 
and debugging time is waaaaaaaaay more expensive
what is the function signature?
 
Return a non negative int, countElementsPassingTest(closure taking one param)
closure returns a bool
 
So it is an array method, so it has the array as this
and the param is what?
A predicate function?
and it basically does filter and length on the resultG
 
yes. and you'd name it better than me :-)
yes, but I'd argue with you if you used filter
 
5:11 PM
well, behind the veil, I'd write it like lodash
have you read the lodash source code?
 
good idea. i'll go do that now.
 
lodash demonstrates it
 
i feel like betting money that it uses a loop, but i'm too nervous
 
You put the imperative complexity behind a singularity
You'll love it
You write that stuff in C, but you write it once, debug it, test it, then seal it in a box
You don't do that over and over again
 
Yes, but I think you've made my point. That's how you cure fatigue.
 
5:15 PM
because it is fragile. Only if you need ridiculous performance - either memory constrained, disk constrained, or cpu constrained
you need to be reasoning about the business domain
not about the state of intermediate operation
we have garbage loops for that :-P
lodash's API is all about encapsulating that behind a functional API
 
Okay. Fun chatting. I really do like you're thinking. I can't count how many times I've given similar advice, probably not as elegantly put as you. I'd only advise a little less rigidity. Cheers and happy coding!
 
Thanks! Have a great day!
 

last day (15 days later) »