Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Giovanni Azua Newsgroups: comp.lang.java.programmer Subject: Re: Immutable Datastructures with good Sharing Date: Mon, 07 Nov 2011 02:08:17 +0100 Lines: 46 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Trace: individual.net X6Ezae3iLUe+tjTZrrzLqwPAaYu+1qdLx7hpiM6SW+RtTaCzE4 Cancel-Lock: sha1:EtTSwva93lKW3tlr1ZLzxtCpJME= User-Agent: Microsoft-Entourage/12.31.0.110725 Thread-Topic: Immutable Datastructures with good Sharing Thread-Index: Acyc6btDTkH0mcqSuEuojK13oZ045g== Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9714 On 11/7/11 12:02 AM, in article alpine.DEB.2.00.1111062256510.4201@urchin.earth.li, "Tom Anderson" wrote: > If you had read the whole thread, or indeed just the OP's initial post, > you would understand that these classes are not helpful. They are > Indeed it was a lucky shot but read on ... > To recap, Jan wants to be able to say: > > ImmutableStack a = new ImmutableStack(); // empty > ImmutableStack b = a.push("foo"); > assert a.isEmpty(); > assert b.size() == 1; > > That is, the quasi-mutation creates a new instance exhibiting the change, > rather than changing an existing instance. > > The Guava Immutable* classes do not have such methods. > Would this check the box? ImmutableMap a = ImmutableMap.of("A", 1, "B", 2, "C", 3); ImmutableMap b = new ImmutableMap.Builder(). putAll(a).put("D", 4).build(); >> I really enjoy the improvement in code readability as well, it suits the >> appropriate template types e.g. >> >> // from >> List requests = new ArrayList(); >> >> // to >> List requests = Lists.newArrayList(); > > I see absolutely no improvement in the code here, only unhelpful > obfuscation. > When you say it like this, any function can be labeled as "unhelpful obfuscation" :) Giovanni