Oct 23, 2011

How to Not Learn Scala Fundamentals

Read this and shed some tears for Scala:
http://tataryn.net/2011/10/learning-scala-learn-the-fundamentals-first/
It's all about a "really simple example":
m.map { t => val (s,i) = t; (s, i+1) }
The author picked this example since it "shows off almost everything you need to know in order to get started ". Had I needed to know this to get started with Scala, I would never have started at all. Scary.

I wonder what the example does...

This is a perfect illustration of how many Scala proponents make Scala look hard, something for the elite. Maybe they find it more important to show off their skills than to help others to get started with Scala.

To be fair, the snippet above is a slide from a talk. Maybe a riddle can be a good presentation tool, but as used in the blog post it only makes Scala look cryptic and difficult to learn.

How would I write the code snippet? I don't know, perhaps something like:
for (cake <- cakes) { cake.egg += 1 }
Or if I had to use the cryptic notation from the snippet:
for (t <- m) { t.i += 1 }
But it doesn't do what the example does, you say. Correct, I cheated a bit and introduced a new class instead of resorting to using tuples:
class Cake(var name:String, var egg:Int)
A small price to pay, wouldn't you agree?

Ok, using tuples here is for demonstration purposes only. But demonstrating several new concepts in one go makes for a steep learning curve indeed.

Having said all this, I must be humble (people who know me would say "Well, that's a first.") and acknowledge that my own published code is wanting. Most of my posts containing code, have the code there to support the text rather than attempting to teach Scala. I write blog post code to be runnable. I should pay more attention to making it readable.

No comments:

Post a Comment