-
Notifications
You must be signed in to change notification settings - Fork 509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How break line when "as" or ":" is present? #107
Comments
Hi @MyDogTom. This is a good question. Personally I prefer not to have a newline inserted in a situations like these. e.g. val field = someFunction(
valueA,
valueB
) as SpecificType
class ClassA(
paramA: String
paramB: String
) : ClassB() BUT. This is just one opinion. Would you be willing to open a ticket at https://github.com/yole/kotlin-style-guide/issues to gather some additional feedback? |
I do think that's the wanted behavior though and I also prefer it a lot. Also kotlinpoet emits classes that way. (I'm not sure about function calls). |
@shyiko Good idea. Kotlin/kotlin-style-guide#45 Just to clarify. I think it's hard to select only one allowed approach here. Making such decision can take a lot of time and there is a chance, that consensus won't be achieved at all. But, I do believe that approach "Break before operator" should be forbidden. This allows to block "bad" approach right now and stay opened for further discussion about recommended approach. |
@MyDogTom I'm curious, why do you seem to have such a strong opinion on "Break before operator"? I find it pretty easy to read, "Break after operator" is much worse in my opinion, as it is needlessly separating a term that should be unseparable as to not confuse readers. In the case of "Break before operator", my thoughts while reading would be "Okay, that line casts the expression on the line before it to SpecificType. Alright", and I don't even need to completely read the line before it to know what I'm getting. With "Break after operator", my thoughts will go "Whoops, there's a lonely type at that line, where does that come from? It's indented, so probably something to do with the line before it" < Read line before it > "Oh okay, that's a cast there, now that next line makes sense" |
@Hikaru755 my reasoning is just the opposite :) Another reason: I prefer to use same "parsing logic" when I'm reading code. In that case, I prefer to preserve similarity with assignment. |
@MyDogTom Valid concern, but I'd argue that the next line being indented already gives me an obvious clue that the previous line is not finished. If I see a bunch of indented lines, I often just skip to the last one to see where the chain ends, and whether or not I need to read the lines before to get the necessary information for whatever it is I'm doing right now, and having the whole cast on a seperate line helps hugely there. I understand trying to preserve the similarity with assignment, but honestly, if in any way possible, I always try to avoid splitting assignments over multiple lines as well. It's just hard to read, for the aforementioned reasons. |
Just doing a little triage here. This ticket has been open a long time. Is it still an issue? I followed up on this and did find a ticket Kotlin/kotlin-style-guide#45 on the kotlin-style-guide repo and am linking it here for reference. That ticket references Kotlin/kotlin-style-guide#2 which is also still open. |
Closing issue as no progress is being made in last 3 years. |
Should library forbid any of these cases? I would prefer forbid "break before operator".
as
,as?
Break before operator
Break after operator
Don't break at all
Same question for
:
Break before operator
Break after operator
Don't break at all
The text was updated successfully, but these errors were encountered: