Search code examples
scalaconventions

What is the convention to name a (case) class with long parameter values?


If I have a class or case class whose parameters are long enough to not fit in a single line like:

case class Foo(foo1: String, foo2: String, foo3: Int, foo4: Char, foo5: Long, foo6: Double, foo7: Array[Int])

To improve readability, how should it be splitted into several lines? Is there a convention for this in Scala?


Solution

  • For the auto-formatters in Scala that I've seen, if you break it into multiple lines at all the formatter will do this:

    case class Foo(
      foo1: String, 
      foo2: String, 
      foo3: Int, 
      foo4: Char, 
      foo5: Long, 
      foo6: Double, 
      foo7: Array[Int]
    )
    

    You may also want to consider if any of those parameters can be grouped into a case class of their own though, reducing the number of parameters.