How do you format multi-line method signatures?

That is, how do you indent:

  • continuation of type parameter list on the next line;
  • parameter lilst on the next line;
  • continuation of the parameter list on the next line;
  • the return type;
  • continuation of the return type on the next line?

Is there a standard? Just curious, as I already deviate a lot using space-based alignment to syntactical boundaries:

implicit def decorated[F <: FromClause, B <: U, G <: D[C], C <: U,
                       D[+A <: U] <: ExtendingDecorator[A], U <: FromClause, X]
                      (implicit specific :ClauseDecomposition[F, B, _],
                                general :DecoratorGeneralization[F, C, D, U],
                                get :Found[B, C, X] { type O >: C <: U })
		:Return[F, G, X] { type T[O] = get.T[O]; type O = general.G[get.O]; type I = get.I } =
	forward[F, G, C, U, X, get.I](get, general)

implicit def aggregated[F <: FromSome, G <: FromSome, X]
                       (implicit get :GroupedTunnel[F, G, X] { type O >: G <: FromSome })
		:Return[Aggregated[F], Aggregated[G], X] 
			{ type T[O] = get.T[O]; type O = Aggregated[get.O]; type I = get.I } =
	body[Aggregated[F], Aggregated[G], G, Aggregated, FromSome, X, get.I](get)(
		PrefixOf.aggregate(get.outerPart, get.prefix)
	)

I failed to think of anything particularly suiting, so, at the moment, I use tab-based 2*indent, in order to clearly separate it visually from the body of the function. It’s quite arbitrary though.

I wouldn’t quite go so far as to call it a “standard”, but there is a Scala Style Guide that goes into a fair amount of detail, and a lot of people choose to follow it.

There’s also the scalafmt tool, which allows you to choose a set of rules and make sure your code adheres to them.

1 Like