I think Scala goes too far from simplicity, like its syntax. For example Martin Odersky wrote the method in his book :
def calculate(s: String): Int =
if (cache.contains(s))
cache(s)
else {
val acc = new ChecksumAccumulator
for (c <- s)
acc.add(c.toByte)
val cs = acc.checksum()
cache += (s -> cs)
cs
}
If the methods grows, it becomes very painful to read the code, I can’t match curly braces, can’t fold the method in IDE.
Is there any Scala coding conventions out there? I feel it’s too flexible to express a simple method:
def add(b: Byte): Unit = {
sum += b
}
def add(b: Byte): Unit = sum += b
def add(b: Byte) { sum += b }
“If the method grows it becomes very painful to read the code”. I think part of the answer is that methods should not grow. The functional programing style is to have many small methods.The calculate method is already on the large side.
To answer the more general questions about style guides for Scala programing: Here’s a representative example.