title: Using getter/setter vs "tell, don't ask"?
body: <p>Tell, don't ask principle <a href="http://pragprog.com/articles/tell-dont-ask" rel="noreferrer">here</a> is often pasted to me when I use getters or setters, and people tell me not to use them.
  The site clearly explains what I should and what I shouldn't do, but it doesn't really explain WHY I should tell, instead of asking.
  I find using getters and setters much more efficient, and I can do more with them.</p>
  
  <hr>
  
  <p>Imagine a class <code>Warrior</code> with attributes <code>health</code> and <code>armor</code>:</p>
  
  <pre><code>class Warrior {
      unsigned int m_health;
      unsigned int m_armor;
  };
  </code></pre>
  
  <p>Now someone attacks my warrior with a special attack that reduces his armor for 5 seconds. Using setter's it would be like this:</p>
  
  <pre><code>void Attacker::attack(Warrior *target)
  {
      target-&gt;setHealth(target-&gt;getHealth() - m_damage);
      target-&gt;setArmor(target-&gt;getArmor() - 20);
      // wait 5 seconds
      target-&gt;setArmor(target-&gt;getArmor() + 20);
  }
  </code></pre>
  
  <p>And with <em>tell, don't ask</em> principle it would look like this (correct me if i'm wrong):</p>
  
  <pre><code>void Attacker::attack(Warrior *target)
  {
      target-&gt;hurt(m_damage);
      target-&gt;reduceArmor(20);
      // wait 5 seconds
      target-&gt;increaseArmor(20);
  }
  </code></pre>
  
  <p>Now the second one obviously looks better, but I can't find the real benefits of this.
  You still need the same amount of methods (<code>increase</code>/<code>decrease</code> vs <code>set</code>/<code>get</code>) and you lose the benefit of asking if you ever need to ask.
  For example, how would you set warriors health to 100?
  How do you figure out whether you should use <code>heal</code> or <code>hurt</code>, and how much health you need to heal or hurt?</p>
  
  <p>Also, I see setters and getters being used by some of the best programmers in the world.
  Most APIs use it, and it's being used in the std lib all the time:</p>
  
  <pre><code>for (i = 0; i &lt; vector.size(); i++) {
      my_func(i);
  }
  // vs.
  vector.execForElements(my_func);
  </code></pre>
  
  <p>And if I have to decide whether to believe people here linking me one article about <em>telling, not asking</em>, or to believe 90% of the large companies (apple, microsoft, android, most of the games, etc. etc.) who have successfully made a lot of money and working programs, it's kinda hard for me to understand why would <em>tell, don't ask</em> be a good principle.</p>
  
  <p>Why should I use it (should I?) when everything seems easier with getters and setters?</p>