Comments (7)
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 String
s would be, but you could have a collection of Object
s...
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.
Does that help?
from pure4j.
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.
Are you using net.jcip.annotations.Immutable?
from pure4j.
javax.annotation.concurrent.Immutable, but same generally philosophy.
from pure4j.
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.
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)
- Improve code coverage on Collections classes
- Gradle plugin HOT 6
- Stream counter-examples.
- Cascading Implementation Impurity
- Error Message Improvement
- Maven Plugin: Add custom .pure files to configuration HOT 4
- Rename and Move annotations to strengthen idea that they are pure
- Annotation for specifying that an implementation function must be pure HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pure4j.