Skip to content
This repository has been archived by the owner on Oct 16, 2018. It is now read-only.

Wrapping and +/- operators #51

Open
yole opened this issue Dec 12, 2017 · 6 comments
Open

Wrapping and +/- operators #51

yole opened this issue Dec 12, 2017 · 6 comments

Comments

@yole
Copy link

yole commented Dec 12, 2017

The current guide says: "When a line is broken at a non-assignment operator the break comes before the symbol". Unfortunately this breaks semantics for +/- operators, which can be used in unary form. For example, this is a string concatenation:

val s = "abc" +
    "def"

This is a simple string initialization, followed by an unused expression that applies unary + to a string literal:

val s = "abc"
    + "def"

The wrapping rules should be changed to either break after all operators (preferably), or to make exceptions for +/-.

@eventualbuddha
Copy link

Anyone have thoughts on what should be done here?

@Jacksgong
Copy link

Jacksgong commented May 11, 2018

I searched the checkstyle rule on SourceForge doc for OperatorWrap, as default, the WrapOp for this rule is using NL, as it said on the checkstyle repo, google checkstyle rule and sun also use NL too, So our project also follow this rule for java code, so as the OperatorWrap default and google or sun defined for this, the correct option is:

val s = "abc"
     + "def"
if (candition1
     && candition2)

Although the above codestyle rule is for Java, but our project is developed with both Java and Kotlin, so if the rule is different, it is very confusing for our developers..

@yole
Copy link
Author

yole commented May 11, 2018

@Jacksgong This is not a code style issue, this is a language syntax issue. The confusion of your developers is unfortunate, but you do have to wrap after + and -, not before them, if you want the code to function correctly.

@Jacksgong
Copy link

@yole okay, thanks for your response, I know that now, maybe because of there isn't ; for kotlin lang, so for the case of

val a = 1
       -2

we can't know whether a is 1 or -1 now, it very confuses.

@yole
Copy link
Author

yole commented May 11, 2018

I'm not sure what you mean by "we can't know". You can know this; a will be 1.

@Jacksgong
Copy link

Yep, I mean as the expert kotlin lang engineer, they absolutely know what does this means, but for the beginner, especially from Java, they will confusing, because on the Java, the following code is means a is -1:

int a = 1
       -2;

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