# Something is wrong with best practice rules

**URL:** https://discuss.emberjs.com/t/something-is-wrong-with-best-practice-rules/13693
**Category:** Uncategorized
**Created:** [October 2, 2017, 1:28pm UTC](https://discuss.emberjs.com/t/something-is-wrong-with-best-practice-rules/13693 "2017-10-02T13:28:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ioanszabo](https://avatars.discourse-cdn.com/v4/letter/i/47e85d/32.png) [@ioanszabo](https://discuss.emberjs.com/u/ioanszabo)
#### Post date: [October 2, 2017, 1:28pm UTC](https://discuss.emberjs.com/t/something-is-wrong-with-best-practice-rules/13693/1 "2017-10-02T13:28:00Z")

</div>

```
lines: Ember.computed('linesReady', 'selectedID', function () {
		let selectedID= this.get('selectedID')
		let lines= this.get('linesReady')

		return lines.map(line => {
			if (line.options.entityID === selectedID) {
				Ember.set(line, 'isSelected', true)
			} else {
				Ember.set(line, 'isSelected', false)
			}
			if (!line.special) {
				line.options.weight = lienWeight
			}
			return line
		})
	})

```

As you can see, I have to use Ember.set in order to avoid ‘ **You must use Ember.set blah blah** ’

If I use Ember.set I get **'Do not send events or actions in Computed Properties. This will cause data flow issues in the application, where the accessing…** ’

So? What is wrong?

---

<div class="post-metadata">

### Author: ![Gaurav0](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gaurav0/32/4704_2.png) [@Gaurav0](https://discuss.emberjs.com/u/Gaurav0)
#### Post date: [October 2, 2017, 1:46pm UTC](https://discuss.emberjs.com/t/something-is-wrong-with-best-practice-rules/13693/2 "2017-10-02T13:46:03Z")

</div>

Computed properties should not have side effects. They should be pure functions. That is indeed a best practice.

How do I explain this? When someone calls .get(‘xxx’) they would not expect another property ‘yyy’ to change. Furthermore, the function inside the computed property does not get called every time someone calls get, but only if one of the dependent properties has changed since it was last called. This makes it really hard to know in practice whether ‘yyy’ will be changed when you call .get(‘xxx’) and that makes for really hard to find bugs.

---

<div class="post-metadata">

### Author: ![ioanszabo](https://avatars.discourse-cdn.com/v4/letter/i/47e85d/32.png) [@ioanszabo](https://discuss.emberjs.com/u/ioanszabo)
#### Post date: [October 3, 2017, 5:54am UTC](https://discuss.emberjs.com/t/something-is-wrong-with-best-practice-rules/13693/3 "2017-10-03T05:54:38Z")

</div>

Hi, Thanks for the fast reply. You are right of course, but what to do if I want to set something when a property changes? with mut for example?

Let’s say that my computed property depend on three keys, how I manage this if I want to set something when my computed is triggered?

Or I should avoid this at all and complicate my code?

---

<div class="post-metadata">

### Author: ![ioanszabo](https://avatars.discourse-cdn.com/v4/letter/i/47e85d/32.png) [@ioanszabo](https://discuss.emberjs.com/u/ioanszabo)
#### Post date: [October 3, 2017, 7:31am UTC](https://discuss.emberjs.com/t/something-is-wrong-with-best-practice-rules/13693/4 "2017-10-03T07:31:16Z")

</div>

Hi again, I cloned all and return completely new array. Seems to work.

---

<div class="post-metadata">

### Author: ![James-Byrne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/james-byrne/32/17391_2.png) [@James-Byrne](https://discuss.emberjs.com/u/James-Byrne)
#### Post date: [October 3, 2017, 12:58pm UTC](https://discuss.emberjs.com/t/something-is-wrong-with-best-practice-rules/13693/5 "2017-10-03T12:58:30Z")

</div>

Thats the correct behaviour, instead of mutating a property create a new object with the updated attributes.

---

<div class="post-metadata">

### Author: ![Gaurav0](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gaurav0/32/4704_2.png) [@Gaurav0](https://discuss.emberjs.com/u/Gaurav0)
#### Post date: [November 10, 2017, 8:56pm UTC](https://discuss.emberjs.com/t/something-is-wrong-with-best-practice-rules/13693/6 "2017-11-10T20:56:28Z")

</div>

> [@ioanszabo](#):
>
> Let’s say that my computed property depend on three keys, how I manage this if I want to set something when my computed is triggered?

Very often when someone asks so how do I do x when we say x is a bad practice, they are really trying to implement y and think x is the best way. So what are you trying to do?
