-
Notifications
You must be signed in to change notification settings - Fork 14
Method call formatting #8
Comments
When calling methods that don't fit on a single line, I use the following syntax:
I like it because it looks like a DSL or a tree, similar to JSON. |
When wrapping a method call, align the parameters on the first one. Group short parameters by meaning:
|
Alternative syntax: drawSquare(
x = 10, y = 10,
width = 100, height = 100,
fill = true
) Even though having the parans on separate lines is a bit more verbose, I like the style better. |
This style is very domain-specific. Look at any reasonable 2D drawing code filled with |
I wonder how important this is if IntelliJ's java feature for putting parameter names inline into the editor is carried over to Kotlin. |
@mikehearn Will it be, though? The additional readabilty you get by the inlined parameter names can be achieved in kotlin by using named parameters, with the added benefit of managing whether it should be shown or not at the call site, so I see no benefit in it being ported over to kotlin. |
Use the named argument syntax when a method takes multiple parameters of the same primitive type, or for parameters of
Boolean
type.Do put spaces around the
=
sign separating the argument name and value.The text was updated successfully, but these errors were encountered: