Tuesday, 21 May 2013

Koan(“Lists have many useful methods (but many have funny names)”)

For example, filterNot:

That one needed a comment to tell me what it was doing.

And another example, map (my nemesis):

Now in all circumstances I like the general style – nice and simple. I liked it in Ruby too (or the equivalent), but to me, while “filter” makes sense on its own as something which will give me things which match the filter, filterNot only makes sense like this in light of knowledge of filter.  And I’ve already posted about map before…

Even as I’m writing this I can appreciate that I’m grousing. The above comments even now seem silly and petulant.  Perhaps I’m slowly coming round to the Scala way of thinking.  It is a different mindset. In light of it’s hyper-terse API names, even Ruby is beginning to look verbose.  I didn’t think I’d be saying that two weeks ago.  Its beginning to feel like I need to build up a massive hashmap in my head of common function names and their associated activity. Then when I read some Scala code they’ll light up in my mind with a little associated picture of what they’re doing.  That’s not unlike how Heisig gets into your head too.  It’s surprisingly effective.

So in light of that:

  • filter – a sieve, with the resulting things left in it, everything which matched the provided expression-argument
  • filterNot – the same sieve, but now we’re looking at the stuff that didn’t get caught in it, the stuff in the sink, the stuff that didn’t match the provided expression-argument
  • map – … I’m sorry, I still can’t think of a good mental image that’s going to fit this one.  Not yet. Not without using “apply” heavily and I know that’s reserved for a whole other area of significance…