~12m read time
~12m read time
Properties are a really nice feature of modern languages, and I've recently gotten attached to them in Kotlin. For a while I wasn't comfortable with the idea of 'fields' performing arbitrary computation, but having used them for a few months now I'm really enjoying the simplicity - especially when moving back to Java!
Having given it some thought, I wanted to lay out a case in support of properties which highlights their benefits over directly accessing fields (which is mostly about getters/setters, but nonetheless), and how we can establish some guidelines on when properties should not be used to avoid the issue of arbitrary computation causing side effects or other unexpected behavior.