Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Method call formatting #8

Open
yole opened this issue May 31, 2016 · 6 comments
Open

Method call formatting #8

yole opened this issue May 31, 2016 · 6 comments

Comments

@yole
Copy link
Contributor

yole commented May 31, 2016

Use the named argument syntax when a method takes multiple parameters of the same primitive type, or for parameters of Boolean type.

drawSquare(x = 10, y = 10, width = 100, height = 100, fill = true)

Do put spaces around the = sign separating the argument name and value.

@cypressious
Copy link

When calling methods that don't fit on a single line, I use the following syntax:

foo(
    bar(
        "a",
        "very long argument"
    ),
    parameterName = 1
)

I like it because it looks like a DSL or a tree, similar to JSON.

@voddan
Copy link

voddan commented Jun 8, 2016

When wrapping a method call, align the parameters on the first one. Group short parameters by meaning:

drawSquare(x = 10, y = 10, 
           width = 100, height = 100, 
           fill = true)

@cypressious
Copy link

cypressious commented Jun 8, 2016

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.

@elizarov
Copy link

elizarov commented Nov 8, 2016

This style is very domain-specific. Look at any reasonable 2D drawing code filled with moveTo and lineTo method invocations. It will become unnecessary verbose if this style is followed.

@mikehearn
Copy link

I wonder how important this is if IntelliJ's java feature for putting parameter names inline into the editor is carried over to Kotlin.

@roschlau
Copy link

roschlau commented Apr 3, 2017

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants