naming convention은 다음을 따른다.(많이 사용할 것 같은 variable의 convention에는 강조 표시를 해둠)
variable type | convention | example |
---|---|---|
function, method | camelCase | def multiplyInt(int1:Int, int2:Int): Int |
variable | camelCase | val serverPort = 1000 |
class | PascalCase | class ClusterManager |
trait | PascalCase | trait Expresstion |
object | PascalCase | object Configuration |
constant | uppercase + underscore(_) | val DEFAULT_PORT |
enumeration | uppercase + underscore(_) | TRIM_BEFORE_SIGN |
package | lowercase ASCII | package com.databricks.resourcemanager |
(camelCase는 lowerCamelCase로, PascalCase는 UpperCamelCase라 불리기도 한다)
=
, +
, -
)의 앞뒤에는 space를 둔다def add(int1: Int, int2: Int): Int = int1 + int2
,
뒤에는 space를 둔다Seq("a", "b", "c") // do this
Seq("a","b","c") // don't omit spaces after commas
:
뒤에는 space를 둔다// do this
def getConf(key: String, defaultValue: String): String = {
// some code
}
// don't put spaces before colons
def calculateHeaderPortionInBytes(count: Int) : Int = {
// some code
}
// don't omit spaces after colons
def multiply(int1:Int, int2:Int): Int = int1 * int2
// Correct:
if (true) {
println("Wow!")
}
// Correct:
if (true) statement1 else statement2
// Correct:
try {
foo()
} catch {
...
}
// Wrong:
if (true)
println("Wow!")
// Wrong:
try foo() catch {
...
}
주석과 관련된 style guide도 있지만, clean code에 근거하여 주석은 정말 필요한 경우를 제외하고 사용하지 않기로 한다. 다음 경우에 대해서는 주석을 작성해도 무관하다.