0

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?

RemcoW
  • 4,196
  • 1
  • 22
  • 37
  • 1
    There are no "official" or "agreed on" numbers as far as I know. It depends a lot on the common sense of the developer and reviewer. According to the style, the number of character can drop substantially, like it's suggested in this blog post: http://degoes.net/articles/insufficiently-polymorphic – stefanobaghino Oct 18 '16 at 13:22

1 Answers1

6

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.

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
José Castro
  • 661
  • 6
  • 14
  • Thanks! I agree that 50 still seems on the long side (unless it is for testing methods). I'll take your advice and compare it with other languages. – RemcoW Oct 18 '16 at 13:45