Coding Guidelines
As 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 Types
One 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 {Using structural types:
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()
}
}
}
class Bunny { def jump(): Unit { print("Jumping!") } }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.
class PogoStick { def jump(): Unit { print("Jumping!") } }
class Controller {
def makeThemJump(jumpers: List[{ def jump(): Unit }]) = {
jumpers.foreach { jumper =>
jumper.jump()
}
}
}
Dependency Injection
How 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 Environment
There 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?
6 comments:
Structural types use reflection, so the Twitter guys were cautioning against them.
Jorge,
Thanks for the reminder. Updated.
JetBrains guys seem to be seriously working on their Scala plugin in Idea8. Unfortunately it's a far cry from their Java support and it's not of production quality by any stretch of imagination.
So far they have been more concentrated on Ruby integration. So it remains to be seen if they are truly committed to Scala this time or just fooling around (as they were with the initial Scala plugin).
i am by no means affiliated with jetbrains (i am a vim guy) but i do believe that intellij scala plugin is actually really good (i even bought a license just because of the scala plugin):
- code completion is working (80-90%)
- code navigation ("find usage") is working
- auto import is working
- maven integration is good
- git&mercurial are supported
- debugging web based projects is working
- vim plugin (of course!)
and these are the features i really care about the most (i also tried eclipse and netbeans)
In my experience none of the three plugins is perfect yet, but all three are moving ahead fast. Quite often, if one reads about shortcomings of this or that plugin, it's actually outdated information, or it will most likely be outdated some weeks from now. I personally use the Eclipse plugin, which has certainly improved enormously over the last three months or so. Because things are moving so fast, it's hard to give recommendations.
Because of maintenance problems I fear structural types. I wish Scala would support Interfaces like Java but automatically detect if a Class supports an interface without an explicit declaration.
The same power as structural types, a little more typing but much safer.
Peace
-stephan
http://stephan.reposita.org
Post a Comment