views:

264

answers:

2

I'm looking to write a small Scala library to get a feel for its Actor programming model.

In the example code I've come across, some libraries use inverted domain (e.g. org.foo.bar) for packages and some do not (maybe just for brevity).

Is it advisable for Scala libraries to use the same package naming conventions as Java? More generally, are there any good Scala coding style suggestions like Python has with PEP 8?

Yes, probably putting cart before horse, but I find I can get a decent feel for a language by also seeing some of the conventions that have shaken out.

Thanks

+7  A: 

Lift, one of the larger projects in Scala, uses the inverted domain name convention, which actually makes a lot of sense, as Scala and Java can interoperate, it stands to reason you'd want to keep things as painless as possible, and I really can't think of any worthwhile advantages of doing it any other way.

Saem
Thanks, looking at the way Lift is structured helps me understand packaging/modules a little better. The inverted domain convention is OK, but I've been using Python long enough now that I can also appreciate flatter package hierarchies. The ability to alias imports seems to be a good solution for those rare circumstances in which a namespace collision occurs, though admittedly it doesn't entirely solve the problem.
Joe Holloway
+2  A: 

Scala basically inherits most of Java's conventions (in almost everything). There are a few exceptions to this. For example, Scala "getters and setters" are actually done in the following way:

class Person {
  private var _name: String = _

  def name = _name

  def name_=(s: String) {
    _name = s
  }
}

When in doubt, borrow the convention from Java, Ruby or Haskell (in that order of preference). With regards to packages, the answer is "yes", Scala packages are named using the inverted domain convention.

Daniel Spiewak