Googling around and reading the first day the following stands out:
- Type inference with the safety of static typing (we're all sick of typing types aren't we??)
- Companion objects instead of static methods
- Higher order functions (why do we need lambas? Can't we just switch to Scala?)
- Interfaces, no I mean mixins, wait traits: interfaces with implementation? I think these are great when used well.
- Tuples and ranges.
The exercise for day 1 is to write noughts and crosses. I decided to concentrate on setting up a nice environment for writing scala rather than great code. I started with vim, then sublime but decided I fancied using an IDE. I started with Eclipse but moved to IntelliJ as it looks nicer on a retina screen :) In addition to setting up an IDE I wanted to do TDD from the start, so I got to grips with ScalaTest.
Here are a couple of example tests:
Here is the main Board object. I could pull out the logic to determine a winner into a class like Game but as this was my first Scala code I decided to keep it simple in a single file.
I've omitted the code that calculates the different types thought it's all available on github. I looked at using a case class rather than a class that extends Enumeration but I haven't been taught case classes yet so I'll leave that until later.
That's it for day one!
No comments:
Post a Comment