title: Kotlin: fun vs val
body: <p>Kotlin supports <em>computed properties</em> but I am not sure when to use them.</p>
  <p>Let's say I have a class:</p>
  <pre class="lang-kotlin prettyprint-override"><code>class Car(val color: String)
  </code></pre>
  <p>and have this function that returns <code>true</code> if the car is white:</p>
  <pre class="lang-kotlin prettyprint-override"><code>fun isWhite(car: Car): Boolean {
    return car.color == &quot;WHITE&quot;
  }
  </code></pre>
  <p>Now I want this function to be a <em>member function</em> (a <em>method</em>); this would look like this:</p>
  <pre class="lang-kotlin prettyprint-override"><code>class Car(val color: String) {
    fun isWhite(): Boolean = color == &quot;WHITE&quot;
  }
  </code></pre>
  <p>but it can also look like this:</p>
  <pre class="lang-kotlin prettyprint-override"><code>class Car(val color: String) {
    val isWhite: Boolean get() = color == &quot;WHITE&quot;
  }
  </code></pre>
  <p>So, which one is better?</p>