I’ve seen Scala using both interchangeably, but I don’t know when to use one or the other.
Is there a convention?
For instance these are equivalent
"hello" toString
and
"hello".toString()
And they can even be mixed
"hello".toString() length
What’s the convention?
To expand on the comment from Yardena, there is an Scala unofficial style guide. It has some suggestions on when to use the dot notation and when to drop the dot and the parenthesis and usually provides a brief rationale for the recommendation, that you may or may not agree with, but at least that’s a starting point.
For instance
name toListmay behave differently depending on what’s on the next line.Personally, I would write
hello.toString.lengthwith the assumption that all calls are side-effect free (so I drop the parenthesis) and then I have to keep the dot for it to compile.