<div dir="ltr">Yes I can recommend Tom's post to understand how to build immutable data structures in Ruby. The problem is that Ruby is mainly an imperative programming language and you will have harder time to use it in a more functional way then directly using languages like Haskell. With Rails you will have even harder time because it is a framework design to change the state of shared objects. But it is possible and hard to figure out in the beginning because you are trying to use immutability in a place where mutability is everywhere (and JC explained that very well).<div><br></div><div>You were talking about Java Strings, I would add that strings should be immutable, and Ruby should not allow the usage of mutable strings. Mutable strings do not give any advantage and introduce only problems.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 10 September 2015 at 10:39, 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 10 Sep 2015, at 10:34, Stephen Best <<a href="mailto:bestie@gmail.com">bestie@gmail.com</a>> wrote:<br>
> In every example I've seen immutability has certainly required more effort, but I don't think this always correlates with more complexity.<br>
<br>
</span>This reminds me (belatedly) of a bit I wrote last year, on implementing immutable trees: <a href="http://codon.com/notes-on-counting-tree-nodes#immutable-trees" rel="noreferrer" target="_blank">http://codon.com/notes-on-counting-tree-nodes#immutable-trees</a><br>
<br>
I wrote that in an attempt to demonstrate how immutability can be useful — in that particular case, by making a data structure correct by construction, rather than having to write extra code to deal with malformed trees and so on. So I think that’s a decent example of how “more effort” (to implement the operations without mutation) leads to “[less] complexity” (because the resulting code is ultimately simpler to work with).<br>
<br>
Cheers,<br>
-Tom<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<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>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Riccardo Tacconi<br><br><a href="http://github.com/rtacconi" target="_blank">http://github.com/rtacconi</a><br><a href="http://twitter.com/rtacconi" target="_blank">http://twitter.com/rtacconi</a></div></div>
</div>