Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Scala libraries follow the same inverted domain convention for naming packages as Java?

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

like image 507
Joe Holloway Avatar asked Apr 21 '09 22:04

Joe Holloway


2 Answers

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.

like image 196
Saem Avatar answered Sep 21 '22 02:09

Saem


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.

like image 42
Daniel Spiewak Avatar answered Sep 19 '22 02:09

Daniel Spiewak