In the programming languages course I’m teaching,
I’m using Seven Languages in Seven Weeks
as the textbook. So far, I’ve been very impressed. It delivers on its goal of going just
far enough into a new language that you feel like you can do interesting things
with it. As a longtime Java programmer, it was a much-needed kick in the pants to
start learning some new languages.
I’ve finally reached the chapter on Scala, which
is the language I’m most excited about learning.
First impressions of Scala - it’s a lot like Ruby. It supports the “let’s apply
an anonymous code block to this collection of values” style of programming,
which is refreshing coming from Java, where doing anything seems to require
explicit loops. It’s statically-typed, but with type inference, so code is much
less cluttered with noise about variable types. (You do tend to get cryptic
error messages when type inference fails, but such is life.)
The book suggests Tic Tac Toe as a good first program, so I gave it a whirl.
Here’s my first-ever Scala program:
As you can see, I have some mutable variables in the PlayTicTacToe
singleton’s main method. The actual gameplay, however, is done by computing new game
boards nondestructively.
Overall, my first experiences with Scala have been positive, and I’m looking
forward to using it more in the future.