Scala First Impressions

Somewhere in the last few months,  I decided to learn Scala. And master it. There are several reasons to do this, but a couple of them is enough for me:

  • The desire to learn something new, different. Java is nice, I love it. But I want to learn new ways to do things; I want to open my mind to new ideas and possibilities;
  • The urge to be more productive, to be able to spend more time on what matters, and less on boilerplate code. Ruby on Rails is one big inspiration here, but I want something more focused on the Java platform.

So, after discovering about the existence of Scala through one of the Java Posse episodes, this was the language I decided is going to be my next big step in terms of software development.

I still have a LOT to learn. I am just a baby when it comes to Scala. But a few things already hit me. One of those is that Scala source code may seem alien at first. For example, instead of declaring variables like this:

Integer count = 10;

you would do this:

val count: Int = 10

There are a few interesting things about this code:

  • semi-colons are optional;
  • the type definition comes after the variable name, instead of before;
  • the type definition is optional in this case: you know 10 is an integer, right? The Scala compiler knows that as well.

I’ll be posting more about Scala as my learning progresses, so stay tuned! Any expectations? Leave a comment!

This entry was posted in scala and tagged , , , , . Bookmark the permalink.

8 Responses to Scala First Impressions

  1. Marcelo's avatar Marcelo says:

    I’ll be happy to ready more about Scala. But in the other hand I feel sorry you didn’t give Ruby a try. =)
    Cheers!

  2. Paulo Renato's avatar Paulo Renato says:

    Well, my problem with Ruby is that it is not built from scratch for running on top of the JVM. Its more of a philosophical reason than anything, but anyway… 😉

  3. Also note that

    val count: Int = 10

    can be shortened to

    val count = 10

    The type inferencing system deduces that count variable is of type Int because it is initialized with an integer. So declarations can be as concise as in a dynamically typed language like Ruby, but you still get the static typing (and compiling to efficient bytecode using the native types and not using reflection).

  4. Paulo Renato's avatar Paulo Renato says:

    Eamonn, that is what I meant when I said “the type definition is optional”. Maybe I should have been less lazy and put and example hehehe

    Thank you for your comment! =)

  5. Alberto's avatar Alberto says:

    Interesting.
    I don’t know why, but i didn’t like the optional semi-colons. I prefer always put it.
    Would be nice have more tips about Scala.

    []’s

  6. Paulo Renato's avatar Paulo Renato says:

    I didn’t like the optional semi-colons as well at first. The code seemed just too… clean! But then it hits you that actually this is a good thing! hehehe =)

    And there will be more Scala related posts! Actually, I plan to have a lot of them! =)

  7. Excellent site, keep up the good work

Leave a comment