Top 5 java programmer reactions to scala

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.

Leave a comment ?

15 Comments.

  1. Note that hardcore Scala programmers say “flatMap that sh*t” ;-)

  2. “Yea…. suck it up and buy a few extra cores.” Fat lot of good that will do. The scala compiler isn’t parallel.

  3. @Kevin, didn’t realize that. Interesting. @Eric… yes… flatMap…. even better.

  4. With you except for #2 as Kevin said.

    Sure the cost of the Scala’s magic has to go somewhere, but currently a fast clock speed and SBT 0.10 with it’s smart recompilation is as good as it gets.

  5. The infamous flatMap joke.

    Q; What does a Scala Developer do to avoid the side effects of insert witty noun, like: a good whiskey?

    A: Put it in a monad and flatMap that sh*t.

  6. Awesome. For any Java programmer that read this far down… Generics != Type Parameters. Type parameters are much more sophisticated than generics – types of a higher kind, my friend… they’re the sh*t :wink:

  7. ha! “Holy f..ing underscores” — You just made my night! And I’ve been looking for reasons to buy a new comp..think you just handed me the best. :D

  8. Oh and as math dude, I’m going to say scala has it right with the using “map” as a verb. Much of undergrad math education is studying various ways of mapping one set to another, and the notation in the mathematical context closely parallels what I’ve seen of the scala…

  9. If you’re programming in Scala you can probably afford it.

    What is this elitist point of view? Scala is free and learning/using it only cost some time.
    At home, I finally upgraded to a modern computer (just before the old one dies), but at work we still have 2006 computers with good old Pentium D (dual core) CPUs and a mere 2GB of memory. OK, we don’t code in Scala (alas, and I won’t hold my breath…) but Eclipse already choke in this setting… And I don’t see an upgrade anytime soon.
    And I fear we are not alone in this situation, if we rely on the number of IE6 still roaming on the Web… (I guess a good number of them come from enterprise computers.)

    Otherwise, good article. :grin:

  10. The attitude expressed in this post will drive people away from using Scala. It is not only the language but also the community that is important. And I don’t want to deal with such a mindset every day.

  11. @PhiLho
    I think that Christian is right here. Companies/teams which are willing to take a risk of adopting Scala are probably the ones which will also invest in good hardware for the programmers. Both things come from same mindset ‘technology can solve the problem’ ;)

  12. the map, the fat arrow, buying new machines… all that is nothing, you needed to include the “magic” of implicits here… the rest if just syntax and everyone can get used to the syntax, “magic” functionality is what’ll get java programmers every single time…

  13. Funny and to the point. This were mostly the things that popped up in my mind when I started Scala.
    One gets used to things like the underscore or the map function very fast and starts to like them.
    So far I am very happy to have started learning Scala. With the Eclipse plugin now usable, Scala is great fun.

  14. Hey, Christian, awesome post! One thing though – don’t use capital identifiers in your sortWith example, nobody does that! l.sortWith((a, b) => a > b)

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">