GithubHelp home page GithubHelp logo

Comments (10)

sgrimm avatar sgrimm commented on July 27, 2024 3

I'm in favor of 4 as well not because of Java similarity but because I find

aFunctionWithAFinalFunctionArgument(
    a, b, c, d, e) {
  doOtherStuff()
}

more readable than

aFunctionWithAFinalFunctionArgument(
  a, b, c, d, e) {
  doOtherStuff()
}

from ktfmt.

cgrushko avatar cgrushko commented on July 27, 2024 1

Personally, I'm in favor of 4, because of its similarity to Java (and because I'm more used to it).

from ktfmt.

strulovich avatar strulovich commented on July 27, 2024 1

My Android Studio copy seems to use 4, as in:

    token(
        token,
        Doc.Token.RealOrImaginary.REAL,
        plusIndentCommentsBefore,
        /* breakAndIndentTrailingComment */ Optional.empty())
    val a = 324567 +
        234567890 + 2345678

I suggest keeping 4 for now in that case.

from ktfmt.

strulovich avatar strulovich commented on July 27, 2024 1

Do we have any discussion going here? If not, we should close.
We do have double continuation in some cases now:

makeCall(
        arg1, arg2, arg3)
    .doMore()

from ktfmt.

tyvsmith avatar tyvsmith commented on July 27, 2024

For reference, at Uber we use 2 indent, 4 continuation indent in Kotlin.

from ktfmt.

ZacSweers avatar ZacSweers commented on July 27, 2024

The official kotlin style guide uses 2 for both, doesn't seem like continuation indent is treated differently (anymore)

from ktfmt.

bethcutler avatar bethcutler commented on July 27, 2024

The official Kotlin Intellij style guide has this reasoning for no continuation indents:
https://kotlinlang.org/docs/reference/code-style-migration-guide.html#differences-between-kotlin-coding-conventions-and-intellij-idea-default-code-style

At Google, we have been using this style, and encouraged ktlint to enforce it as well. It is a more self-consistent style, where all blocks have no continuation indent, and the closing brace or paren is on a separate line.

from ktfmt.

strulovich avatar strulovich commented on July 27, 2024

Hi @bethcutler, thanks for helping!

several Kotlin constructions look a bit awkward when they are formatted this way

I don't get this main explanation, probably due to lack of imagination. Do you have any idea what constructs they might mean? Currently, I think @cgrushko did a great job making all those calling chains with lambdas and what not work well for these cases, but I'd be happy to see some ugly examples and change my mind.

from ktfmt.

bethcutler avatar bethcutler commented on July 27, 2024

I think the image included in the link I posted shows some decent examples; e.g. class members are all indented the same amount, regardless of if they are defined in the constructor or not. Another example I like is that chained method calls are indented the same amount as statements in a block.

from ktfmt.

hick209 avatar hick209 commented on July 27, 2024

Closing this is both an old discussion and because now we have an option to set this up
https://github.com/facebook/ktfmt/blob/main/core/src/main/java/com/facebook/ktfmt/format/FormattingOptions.kt#L47

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.