is it bad convention to put loops with a single st...
# codingconventions
f
is it bad convention to put loops with a single statement into 1 line
👌 1
🚫 5
g
probably depends on case, but personally I never do this and we do not allow such code to pass code review. Also we just have very few while loops
2
f
You mean its bad practice and it should be surrounded by braces?
g
I prefer surround everything with braces
especially loops
it just make it readable
i
@Florian Wasn’t the original question about this?
Copy code
list.forEach { println(it) }
vs
Copy code
list.forEach { 
   println(it) 
}
g
Usually it doesn't called loop, at least I always think that loop is while and for. But maybe it's only my strange understanding and it look fine for me
f
No I meant without braces
in a normal for loop
for (item in list) print(item)
g
Than I got it correctly, I would avoid such construction personally. Also most probably rewrite it as:
Copy code
list.forEach(::print)
👍 2