I promised some technical notes on the Bay Area Scala Enthusiasts meetup earlier this week, so here we go.
Coding GuidelinesAs I mentioned previously, the presentation by the Twitter folks focused on the informal guidelines they have been using internally for Scala coding (
PDF of their presentation). I like their guidelines generally. Something that may be controversial in the guidelines is their policy not to use implicits. DSLs especially can make good use of implicits, so I would imagine that would have to be the exception to their rule. Maybe someone should take their coding guidelines as a starting point to make a coding guidelines page on the
Scala Wiki?
Structural TypesOne of the topics mentioned at the meetup was structural types, which I hadn't used before, so I checked them out. Structural types seem to be a way to accomplish the same sort of "duck"-typing that you can do in Ruby and Python. Let's say you don't care about what the inheritance hierarchy of a parameter is, just that it can perform some operation. There are at least two ways to do this: traits or structural types.
Using traits:
trait Jumpable {
def jump() : Unit { print("Jumping!") }
}
class Bunny extends Jumpable { ... }
class PogoStick extends Jumpable { ... }
class Controller {
def makeThemJump(jumpers: List[Jumpable]) = {
jumpers.foreach { jumper =>
jumper.jump()
}
}
}
Using structural types:
class Bunny { def jump(): Unit { print("Jumping!") } }
class PogoStick { def jump(): Unit { print("Jumping!") } }
class Controller {
def makeThemJump(jumpers: List[{ def jump(): Unit }]) = {
jumpers.foreach { jumper =>
jumper.jump()
}
}
}
The Twitter guys pointed out that it might be a good idea to avoid structural types due to their use of reflection, which may be slow.
Dependency InjectionHow to use dependency injection (DI) with Scala was brought up. There was some argument on how applicable DI was in Scala, with developers coming from a Java background supporting it and those with a Ruby background questioning its relevance to Scala. Either way, this in depth
article by Jonas Bonér was brought up.
Development EnvironmentThere was a short discussion on what ide/editor people were using for Scala. The Twitter guys were using TextMate or Emacs, and a few people in the audience mentioned Eclipse and NetBeans. I am really curious what luck developers have had with the different environments. I am using NetBeans right now, but I am not completely happy with it. Can anyone make any recommendations?