scalamethod-namesscalastylename-length

Scala method name length convention


I'm looking into code smells that have an impact on the readability of an application. I came across long method names and I was wondering if there is a convention for this.

I've checked the naming conventions in the scaladocs but it didn't list anything about the length of a method name. I also checked the Scalastyle rules and noticed it defaulted to 50.

Is there an official convention for the maximum length of a method name, and if so how long is it?


Solution

  • Scalastyle does default the value to 50.

    Paypal's Style Guide mentions "For function names over 30 characters, try to shorten the name."

    Neither Databricks' Scala Style Guide nor Twitter's Effective Scala seem to mention method name length.

    Personally, I do believe that 30 might still be too much (just try to picture yourself reading code with that method name scattered all through it, and try to imagine how much more difficult it will be to distinguish it from another similar one if they are both long).

    It might be useful to look into patterns and default from other languages. I compiled a bit of information in this blog post: Cross-language Best Practices.