Coder Social home page Coder Social logo

Comments (10)

andrewparmet avatar andrewparmet commented on May 3, 2024 3

My vote is a new line, wasting the vertical space. IMO the consistency is what I value.

from ktfmt.

cgrushko avatar cgrushko commented on May 3, 2024 1

@JavierSegoviaCordoba I'm hesitant to introduce special formatting cases such as builder patterns. First, because I'm concerned it'll complicate the code and make it less maintainable, and second because it might be difficult to correctly identify the pattern.

from ktfmt.

cushon avatar cushon commented on May 3, 2024

Another related question is what to do about chained method calls if there's a line break before ).

Having a line break and continuation indent after . looks weird and takes up more vertical space. It might be better to have something like the following, but it would require some rectangle rule special-casing:

foo(
    bar,
).baz(
    bork,
)

from ktfmt.

cgrushko avatar cgrushko commented on May 3, 2024

This is the existing formatting:

func f() {
  computeBreaks(
      output.commentsHelper, maxWidth, State(0))
…

Which one do we prefer?

First option wastes vertical space:

…
  computeBreaks(
      output.commentsHelper,
      maxWidth,
      State(0)
  )
…

Second option looks weird:

…
  computeBreaks(
      output.commentsHelper, maxWidth, State(0)
  )
…

I don't like either of the options, but the first one seems more sane.

EDIT: For method parameters, we use the latter.

@cushon, @strulovich, what says you?

from ktfmt.

strulovich avatar strulovich commented on May 3, 2024

In any case, for a trailing comma we will do:

func1(
    arg1,
    arg2,
)

But I'd prefer keeping it for now as:

func1(
    arg1,
    arg2)

I'm against wasting vertical space. So if all args fit in one line I would keep them there.

Is any of these a deal breaker for anyone?

from ktfmt.

cgrushko avatar cgrushko commented on May 3, 2024

Do you mean we output different formatting based on whether a trailing comma exists?

from ktfmt.

strulovich avatar strulovich commented on May 3, 2024

As long as we don't adjust the actual tokens (which for now we are not) I think that would be ok.

from ktfmt.

strulovich avatar strulovich commented on May 3, 2024

Doing round on some old issues today. I prefer same line if if there's no trailing comma, and next line if there is one. We do not add or remove commas for now.

@cushon, how does that sound to you?

from ktfmt.

bethcutler avatar bethcutler commented on May 3, 2024

At Google, we are using the first option (all parameters on separate lines, closing parens on its own line). This is also the style that ktlint enforces (all parameters must be on separate lines, unless they can all fit on the same line as the function name).

The closing parens being on its own line is also key to having no continuation indents, as recommended by both Intellij and Android style guides. (See also discussion at #14 )

from ktfmt.

JavierSegoviaCordoba avatar JavierSegoviaCordoba commented on May 3, 2024

I like the approach of trailing lambdas to force multiline params even if it fits in one line.

But I would like to force in a builder pattern to use multiline even if it fits in one line because of readability.

The only approach now is this?

fol.Builder().apply {
    bar()
    baz()
}

from ktfmt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.