I'm looking to write a small Scala library to get a feel for its Actor programming model.
我正在寻找一个小的Scala库来感受它的Actor编程模型。
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).
在我遇到的示例代码中,一些库使用反向域(例如org.foo.bar)用于包,而有些库则没有(可能只是为了简洁)。
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?
Scala库是否可以使用与Java相同的包命名约定?更一般地说,有没有像Python那样有PEP 8的Scala编码风格建议?
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
2 个解决方案
#1
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.
Lift,Scala中较大的项目之一,使用反向域名约定,这实际上很有意义,因为Scala和Java可以互操作,因此你可以保持尽可能无痛的事情。真的想不出任何其他方式做任何有价值的好处。
#2
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:
Scala基本上继承了Java的大多数约定(几乎在所有方面)。这有一些例外。例如,Scala“getter and setters”实际上是通过以下方式完成的:
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.
如有疑问,请从Java,Ruby或Haskell(按优先顺序)借用约定。关于包,答案是“是”,Scala包使用反向域约定命名。
#1
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.
Lift,Scala中较大的项目之一,使用反向域名约定,这实际上很有意义,因为Scala和Java可以互操作,因此你可以保持尽可能无痛的事情。真的想不出任何其他方式做任何有价值的好处。
#2
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:
Scala基本上继承了Java的大多数约定(几乎在所有方面)。这有一些例外。例如,Scala“getter and setters”实际上是通过以下方式完成的:
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.
如有疑问,请从Java,Ruby或Haskell(按优先顺序)借用约定。关于包,答案是“是”,Scala包使用反向域约定命名。