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

How to break line when cast ("as") or colon (":") is present #45

Open
MyDogTom opened this issue Nov 23, 2017 · 8 comments
Open

How to break line when cast ("as") or colon (":") is present #45

MyDogTom opened this issue Nov 23, 2017 · 8 comments

Comments

@MyDogTom
Copy link

How to to properly break line cast (as, as?) or colon (:) is present and it doesn't fit in one line? I think variants 1 and 2 are good, 3 is acceptable, 4 should be forbidden.

@MyDogTom
Copy link
Author

Variant 1

val field = someFunction(
    valueA,
    valueB
) as SpecificType

class ClassA(
    paramA: String
    paramB: String
) : ClassB()

@MyDogTom
Copy link
Author

Variant 2

val field = someFunction(
    valueA,
    valueB) as SpecificType

class ClassA(
    paramA: String
    paramB: String) : ClassB()

@MyDogTom
Copy link
Author

Variant 3

val field = someFunction(valueA, valueB) as
      SpecificType

class ClassA(paramA: String, paramB: String) :
      ClassB()

@MyDogTom
Copy link
Author

Variant 4

val field = someFunction(valueA, valueB)
      as SpecificType

class ClassA(paramA: String, paramB: String) 
      : ClassB()

@roschlau
Copy link

roschlau commented Nov 23, 2017

I actually prefer variants 1 and 4 over the others. My reasoning being that I see as SpecificType and : ClassB() as one single term each that shouldn't be split over two lines (thus ruling out variant 3), and should only be put on one line with another expression if the complete expression fits readably on one line as a whole (which disqualifies variant 2, which I personally find aesthetically unpleasing as well).

It comes down to readability, 3 splits coherent terms in the middle, and 2 puts them on the same line with the last part of the expression before it without any good reason to do so, while the rest of that expression is otherwise nicely chunked up, which again makes for poor readability in my opinion.

@roschlau
Copy link

roschlau commented Nov 23, 2017

I would discourage variant 4 for classes though, as those should always either be true one-liners or have their primary constructor paramaters on individual lines, that one-line-but-inheritance-on-another-line-approach looks weird there. So I'd say 1 or 4 for casts, whatever fits better, but only 1 for inheritance.

@yole
Copy link
Contributor

yole commented Dec 21, 2017

For class header formatting, see #2. For as, could you please clarify how this is different from other operators?

@MyDogTom
Copy link
Author

For as, could you please clarify how this is different from other operators

I would say no difference. Do you have recommendation for operators?

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

3 participants