Git Product home page Git Product logo

Comments (7)

robmoffat avatar robmoffat commented on July 22, 2024

Hi idcmp,

Good enough for what?

If you mean, good enough to ensure that using them is functionally pure, then the answer is no: Although the collection itself is immutable, the values it contains won't (necessarily) be immutable. Obviously, a collection of Strings would be, but you could have a collection of Objects...

Also, because they're immutable, they're not going to be useful if you want to make changes to the data structures. This is why pure4J uses persistent collections (from Clojure). More details are here.

There are also wrappers round the java collections so that they can be used in a @MutableUnshared way. This is useful if you are worried about performance -- remember not to optimise early, though ;)

Some details on those here

from pure4j.

robmoffat avatar robmoffat commented on July 22, 2024

Does that help?

from pure4j.

idcmp avatar idcmp commented on July 22, 2024

I'm in a fairly large code base where we have many @immutable classes (we copy collections and mutable classes), I was hoping pure4j could catch people making honest mistakes. Many of my use cases are such that I don't actually want to change the data in the immutable collections once they're made. I'm starting to drink the functional koolaid, and enjoy what it's saying, but haven't fully grasped everything, so I'm going to need to think on this a bit.

from pure4j.

robmoffat avatar robmoffat commented on July 22, 2024

Are you using net.jcip.annotations.Immutable?

from pure4j.

idcmp avatar idcmp commented on July 22, 2024

javax.annotation.concurrent.Immutable, but same generally philosophy.

from pure4j.

robmoffat avatar robmoffat commented on July 22, 2024

Is there an annotation processor for that that you are using?

With regard to the guava collections (and this is something I was thinking of doing anyway, although for some reason I didn't add a ticket already), I think it would be good if you could tell the checker that these could be considered pure, in much the same way as pure4j already knows which methods are pure on many JVM classes.

So, you might add an annotation in your code like this:

@RegisterImmutableValues({ImmutableSortedSet.class, ImmutableTable.class})

In terms of immutability, the guava collections are completely immutable if you (& your team) only put other immutable objects inside them. But, you would have to ensure this yourself. cf. Using the pure4j collections where you would get this guarantee.

In terms of purity, there will obviously be no state changing, and they are unlikely to have IO side-effects so this would probably be pretty safe for your purposes.

thoughts?

from pure4j.

idcmp avatar idcmp commented on July 22, 2024

We enforce immutability through code reviews, culture and lots of existing examples to follow. People still trip up sometimes (every now and then accidentally including mutable objects (Date, etc) in immutable collections, etc). We have no processor yet (this is why pure4j is interesting to me).

I forsee us running pure4j as a Maven plugin during "mvn install" on our desktops (assuming it's not unusually unperformant). I think it would be more handy to be able to include the registered immutable values in the plugin configuration (instead of code), but yes being able to add the guava immutable collections would be a great first step for us to enforce the immutability.

Again, I'm new to much of this, so if I'm not making sense it's likely showing my lack of full understanding. :)

from pure4j.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.