atom feed23 messages in org.codehaus.groovy.dev[groovy-dev] Suggestions for @Immutable
FromSent OnAttachments
Guillaume LaforgeMar 2, 2009 2:16 am 
Dierk KönigMar 2, 2009 2:38 am 
Guillaume LaforgeMar 2, 2009 3:01 am 
Dierk KönigMar 2, 2009 3:40 am 
Guillaume LaforgeMar 2, 2009 3:53 am 
melixMar 2, 2009 3:56 am 
Guillaume LaforgeMar 2, 2009 3:58 am 
Paul KingMar 2, 2009 4:11 am 
Guillaume LaforgeMar 2, 2009 4:23 am 
Tom NicholsMar 2, 2009 4:39 am 
Michael MellingerMar 2, 2009 5:10 am 
Martin C. MartinMar 2, 2009 5:31 am 
Tom NicholsMar 2, 2009 6:19 am 
Robert FischerMar 2, 2009 6:25 am 
Robert FischerMar 2, 2009 6:38 am 
Tom NicholsMar 2, 2009 6:50 am 
Graeme RocherMar 2, 2009 6:55 am 
Alex TkachmanMar 2, 2009 7:06 am 
Robert FischerMar 2, 2009 7:07 am 
Robert FischerMar 2, 2009 7:13 am 
Alex TkachmanMar 2, 2009 8:18 am 
Robert FischerMar 2, 2009 8:58 am 
Guillaume LaforgeMar 3, 2009 1:39 am 
Subject:[groovy-dev] Suggestions for @Immutable
From:Guillaume Laforge (glaf@gmail.com)
Date:Mar 2, 2009 2:16:07 am
List:org.codehaus.groovy.dev

There's a comment on my InfoQ article on Groovy 1.6 about @Immutable:

http://www.infoq.com/articles/groovy-1-6#view_39652

Some interesting thoughts:

*Great to see that the groovy team is embracing immutability as a critical part of the language.

Can methods require @immutable arguments and return types? That would make it possible to write side effect free functions that can be parallelized. If the compiler can enforce immutability, then it would be trivial to write an erlang-like messaging library or a a parallelized linear algebra implementation.

Also, immutable types should also generate modifiers for all properties. Otherwise, working with immutable types is cumbersome and involves a lot of boilerplate copying of fields between objects.

Example: def c1 = new Coordinates(latitude: 48.824068, longitude: 2.531733) def c2 = new Coordinates(48.824068, 2.531733

//copies the prior longitude, and sets the latitude to the provided value def c3 = c2.modify(latitude:49.13123)

This is a trivial example, but in practice data structures can be large and complicated, so it should be trivial to create slight variations of existing data.

Support for immutable types is critical as more people attempt to embrace multi-core machines through message based concurrency or side-effect free functional programming. *

Perhaps some of these suggestions would be nice to have? What do you think?