<div dir="ltr">Great question Jonathon! I'm getting more and more into immutability and continually find more reasons why it can be beneficial. I think stateless code is often easier to reason about and this is the primary draw for me.<div><br></div><div>I put one particular argument for immutable class design in a blog post recently: <a href="https://www.madetech.com/blog/an-argument-for-immutable-class-design">https://www.madetech.com/blog/an-argument-for-immutable-class-design</a></div><div><br></div><div>Let me know what you think :)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 9 September 2015 at 11:37, Tom Stuart <span dir="ltr"><<a href="mailto:tom@codon.com" target="_blank">tom@codon.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 9 Sep 2015, at 11:25, Jonathon Horsman <<a href="mailto:jonathon@arctickiwi.com">jonathon@arctickiwi.com</a>> wrote:<br>
> Can you shed some light on why an immutable object is an advantage for a web-based Ruby app?<br>
<br>
</span>One short answer is that immutable values eliminate a whole class of confusing bugs.<br>
<br>
For example, when you pass an object into a method, what can happen to it? If it’s immutable then the answer is: nothing, you don’t need to worry about it. But if it’s mutable, then maybe that method makes some change to the object (perhaps accidentally!) that is going to make your life difficult later on. You see this sort of thing all over the place in Rails: methods that go to great lengths to duplicate their arguments so that they can mutate them without leaking side-effects back to the caller.<br>
<br>
You’re right that it can sometimes require more programmer work to create new values instead of mutating existing ones, and in the naive case it can also take more time and memory to do things that way, but the trade-off is that your program becomes simpler to reason about and you’re less likely to introduce really sneaky bugs caused by shared mutable state.<br>
<br>
Cheers,<br>
-Tom<br>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</blockquote></div><br></div>