1. What are all these f…ing square brackets?
Don’t be afraid. They are a lot like <java generics>. In scala-land we use the more generic term ‘type parameters’ (because it makes us sound smarter). In Java we mostly use generics for collections, but we’re not forced to. Scala differs from Java in that you are forced to use type parameters on collections. It’s a good thing trust me. Also, Scala has something called ‘type inference’ which sounds scary, but just means the compiler is really smart about figuring out types, which means you don’t have to be as explicit. This makes using type parameters easier, and as a result they are just used more frequently in Scala. Trust me, it’s the sh*t.
2. Why is the f…ing compiler so f…ing slow?
Yea…. suck it up and buy a few extra cores. See above about the compiler being ‘really smart’. You don’t get something for nothing. Now might be a good time to upgrade to that 8-core machine you’ve been eying. If you’re programming in Scala you can probably afford it.
3. Holy f…ing underscores
Yea_they_are_everywhere. The first time you’ll probably encounter them is in import statements. I.e. import org.example._ is just like import org.example.*;
They are generally used as a wild card, but they do have different meanings in different contexts. It won’t take you long to sort it out. After a couple months I was at peace with _.
4. WTF is => ?
Fat arrow my friend, fat arrow.
When you’re first starting to visually parse => throughout Scala code, think function arguments are on the left of =>, and the function body is on the right. Note that a function may take no arguments too.
Quick example:
someList.sortWith{ (L,R) => L > R }
L and R are the two function arguments neatly tucked into parens, and the stuff on the right is the function body. Go with it.
5. I thought map was a data structure but you scala f…ers are using ‘map’ as a verb.
Yup. Forget ‘map’ as just a hash map. In scala-land (as with other functional programming languages I’m told) map says, “I’m going to take something and change it to something else, i.e. I’m going to MAP it”. Like, “I’m going to map that integer by multiplying it by 41″. Or, “I’m going to MAP OVER all those integers and multiply each one by 41″.
The other day I mapped over a set of blueberries by putting them in my blender for 30 seconds.
Map that sh*t! You’ll love it.





Recent Comments