scala-style-guide
scala-style-guide copied to clipboard
Multi-line vs single-line method and class constructor declarations and invocations
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)?
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 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 ^.
sure - sounds good.
Sounds good to me
@jkbradley, this is fixed in https://github.com/databricks/scala-style-guide/pull/64 :-)