scala-style-guide icon indicating copy to clipboard operation
scala-style-guide copied to clipboard

Multi-line vs single-line method and class constructor declarations and invocations

Open jkbradley opened this issue 7 years ago • 5 comments

Apache Spark (especially what I've seen of MLlib) and the current Scala style guide differ on one item: Should multiline method and class constructor invocations be written with 1 arg per line or multiple args per line?

Spark mostly uses multiple args per line (for invocation, not for declarations). The current Scala style guide says to put 1 arg per line: See "Methods with Numerous Arguments" here: http://docs.scala-lang.org/style/indentation.html

Can we add our standard to this doc?

E.g.:

  • For method and class definitions,
    • If they fit on 1 line, put everything on 1 line.
    • For multi-line definitions, put 1 argument per line.
  • For method and class constructor invocations,
    • If they fit on 1 line, put everything on 1 line.
    • For multi-line calls, put (multiple arguments per line) or (1 argument per line)?

jkbradley avatar Jul 18 '17 20:07 jkbradley

How about if it requires more than two lines, one arg per line. If it fits in two lines, just fit them in two lines? That's what I personally do.

rxin avatar Jul 18 '17 22:07 rxin

@rxin and @jkbradley, can I open a PR for describing it? Roughly like:

  • For method, class definitions, class constructor invocations,
    • If they fit within 2 line, put everything within 2 line.

      function("very long blabla........................................................")
      
      function(
        "very long blabla........................................................")
      
    • For multi-line, put multiple arguments per line?

      function(
        "very",
        "very long",
        "bla bla bla bla")
      

I think I can quickly do this if we are okay with ^.

HyukjinKwon avatar Oct 28 '17 09:10 HyukjinKwon

sure - sounds good.

rxin avatar Nov 14 '17 18:11 rxin

Sounds good to me

jkbradley avatar Dec 09 '17 00:12 jkbradley

@jkbradley, this is fixed in https://github.com/databricks/scala-style-guide/pull/64 :-)

HyukjinKwon avatar Jul 24 '18 04:07 HyukjinKwon