408399 (15) [Avatar] Offline
In the example on page 25, how does Kotlin know what the "private set" applies to?

Given that there is a blank line between "var counter: Int = 0" and "private set", it is not at all obvious that they are related in any way ... unless Kotlin uses the Python syntax rule that indentation defines scope.

The box "Property invocation implementation details" on page 26 is very important to provide. Thank you for making it very visible.
Svetlana Isakova (9) [Avatar] Offline
There's no empty line in the code example in the book. It looks like that due to code annotation formatting in MEAP.
But you actually can put an empty line there. The compiler ignores empty lines, they are used only for our convenience.
408399 (15) [Avatar] Offline
OK, so I should read it as

"var counter: Int = 0 private set"

Thanks. I'm looking forward to the good formatting in the book! smilie
Svetlana Isakova (9) [Avatar] Offline
No, actually I meant
var counter: Int = 0 
  private set

The compiler doesn't care for a new line, but according to our style guide we prefer to put getters and setters to the next line. The rule is simple: they just go after the corresponding property. Your last version compiles as well.

(As a style guide, you can just use a default formatter in IntelliJ IDEA for now.)
408399 (15) [Avatar] Offline
OK, thanks.

I do find that layout confusing, though. Probably because, in Java, the only place an access modifier can occur is at the beginning of a declaration -- it can't refer back to some previous item.
Svetlana Isakova (9) [Avatar] Offline
Access modifier private refers to setter here (and goes at the beginning of its declaration).