Do you prefer to newline before or after operators...
# codingconventions
h
Do you prefer to newline before or after operators?
Copy code
val foo = bar ?:
    3 + 6 + 9 + 2 +
    8 + 12

val baz = a && b && c
    && d && e && f
d
Personally before - makes it immediately obvious the line continues
3
p
I put boolean operators on a new line, and I try to avoid splitting numeric expressions with
+
or
-
on several lines as I would be forced to put these operators before newline, because of:
Copy code
val foo = 3
    + 2
println(foo) // prints 3
💯 4
r
Just to be explicit,
+ 2
is a
unaryPlus()
operation, so you should only use
+
to start a line if you intend to invoke this function
h
Who honestly ever uses unary plus unless you're overriding it? Its textbook purpose is to tell the reader of the code that the value should be positive. It actually does nothing
I don't even know what to override it with
r
You can use it to append things when working in a context
Copy code
class SaySomething(var something: String = "") {
  operator fun invoke(action: () -> Unit) { action() }
  operator fun String.unaryPlus() { something += this }
  fun say() { println(something) }
}

val ss = SaySomething() {
  +"Hello world!"
}
ss.say() //Hello world!
h
Ah, cool, yeah, I like it
I would sometimes use it as an absolute value operator, but that didn't seem like good convention.