question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should continuation indentation be 2 or 4 spaces?

See original GitHub issue

i.e., should code look like this: (2 spaces)

fun f() {
  val x =
    43
  aVeryLongFunctionName(
    a, b, c, d, e)
}

or like this? (4 spaces)

fun f() {
  val x =
      43
  aVeryLongFunctionName(
      a, b, c, d, e)
}

In favor of 2 spaces:

  1. That’s what IntelliJ’s code conventions define. We don’t know the reasons. It could be that it’s just simpler this way.

In favor of 4 spaces:

  1. It’s looks more like Java.
  2. Given ktfmt, it’s as easy to format with 4 as it is with 2.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
sgrimmcommented, Jan 9, 2020

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()
}
1reaction
strulovichcommented, May 13, 2020

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()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do most developers prefer indenting code with 2 spaces ...
It should be noted that there are some people want more than 2 spaces for their indentation. There's a name for them in...
Read more >
4 Spaces or 2? - DEV Community ‍ ‍
We will argue 4 vs 2 spaces until we are blue in the face. ... Indent extension, and as such have been moving...
Read more >
Why is two-space tab indent becoming the standard? - Reddit
I generally agree that tabs are better than spaces for indentation. But the problem with different developers changing their size from 4 to...
Read more >
Python: using 4 spaces for indentation. Why? - Stack Overflow
I would also argue 4 spaces is objectively better than 2 for code clarity as well. At least for me, I've always found...
Read more >
For code indentation, is a single tab equivalent to 2 spaces or ...
Use 4 spaces per indentation level. Continuation lines should align wrapped elements either vertically using Python's implicit line joining ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found