atom feed11 messages in org.codehaus.groovy.devRe: [groovy-dev] What about a @Mutabl...
FromSent OnAttachments
Paulo Gabriel PoiatiJul 10, 2010 4:07 pm.diff
Paul KingJul 11, 2010 3:36 pm 
Guillaume LaforgeJul 12, 2010 1:54 am 
Erik PragtJul 12, 2010 2:28 am 
Dierk KönigJul 12, 2010 2:31 am 
Guillaume LaforgeJul 12, 2010 2:33 am 
Martin C. MartinJul 12, 2010 6:35 am 
Paulo Gabriel PoiatiJul 12, 2010 8:20 am 
Hamlet D'ArcyJul 12, 2010 11:43 pm 
Alex TkachmanJul 12, 2010 11:49 pm 
Hamlet D'ArcyJul 14, 2010 1:46 am 
Subject:Re: [groovy-dev] What about a @Mutable ast transformation (with implementation)
From:Hamlet D'Arcy (haml@gmail.com)
Date:Jul 14, 2010 1:46:34 am
List:org.codehaus.groovy.dev

In fact, I think it should be both Cloneable and Externalizable.

There are so many edge cases to writing a properly Cloneable object. I doubt a good implementation could be made. Something could be made for classes with all simple data types, but that doesn't get you very far. Suspect the same thing for Externalizable.

I could be wrong, of course.

On Tue, Jul 13, 2010 at 8:49 AM, Alex Tkachman <alex@gmail.com> wrote:

Canonicat is nice. In fact, I think it should be both Cloneable and Externalizable.

On Tue, Jul 13, 2010 at 9:43 AM, Hamlet D'Arcy <haml@gmail.com> wrote:

@Canonical seems like a very good name given the contents of the Bill Venners article Dierk referenced. Ours doesn't do Serializable and Clonable, but I think the intent is the same. I think it's good that Canonical is not already a commonly used term.

On Mon, Jul 12, 2010 at 5:21 PM, Paulo Gabriel Poiati <paul@gmail.com> wrote:

Tks for the feedback. I agree, @Mutable only makes sense in the context of an existing @Immutable counterpart. And not everyone in groovy is familiar with @Immutable. Personally, i don't like @Data here (same reasons of Martin). @Canonical is cool, but it's not a common term. @Struct is simple and make a lot of sense. []'s Paulo Poiati

blog.paulopoiati.com

On Mon, Jul 12, 2010 at 10:35 AM, Martin C. Martin <mar@martincmartin.com> wrote:

@Struct or @Structure ?  People with C/C++ will have strong associations for those.  And even for those who don't, it seems appropriate.

On 7/12/2010 4:55 AM, Guillaume Laforge wrote:

Great work, Paulo.

I think the name @Mutable is a bit misleading. Paul was referring to a JIRA issue where we were mentioning @Identity or @Data. @Data sounds perhaps a bit too much like providing data fixtures for a test framework, but @Identity conveys the idea it's about expressing the "identity" of the bean, how it represents itself (toString()), how it compares/identifies itself (equals()/hashCode). So I think @Identity sounds better.

Anyone else can think of a better name?

Guillaume

On Mon, Jul 12, 2010 at 00:36, Paul King <pau@asert.com.au <mailto:pau@asert.com.au>> wrote:

   Hi Paulo, looks cool!

   I added a reference to your post to the relevant issue:    http://jira.codehaus.org/browse/GROOVY-2879

   Thanks for the patch.

   On 11/07/2010 9:08 AM, Paulo Gabriel Poiati wrote:

       Hello, I think it's a good idea to have an ast transformation that        create the toString, equals, hashCode and positional args        constructor        (like @Immutable does). Also, because it's mutable it can have        untyped        properties and not all properties need to be initialized in the        constructor.

       I was searching for something like that, and I found this:

 http://archive.codehaus.org/lists/org.codehaus.groovy.user/msg/1aae@mail.gmail.com

       Paulo King suggested the @Mutable ast.

       I did an implementation, based in the current groovy trunk (rev        20439).        Most of the work was stole from Paul King @Immutable        implementation).

       What differs from @Immutable:            - It's mutable, implying that nor properties or class are        final, and        it provide setters methods.            - Allow untyped properties.            - Objects are passed by reference in the constructor, not        wrapped or        cloned.            - Hashcode is not cached.            - Constructor arguments are optional.            - If a class is annotated as @Mutable and @Immutable an        exception is        throw.            - Inheritance is possible

       The patch is attached...

       Example:

       *@Mutable class Customer {*        *    String first, last*        *    int age*        *    Date since*        *    Collection favItems = ['Food']*        *    def object *        *}*        * *        *def d = new Date()*        *def anyObject = new Object()*        *def c1 = new Customer(first:'Tom', last:'Jones', age:21, since:d,        favItems:['Books', 'Games'], object: anyObject)*        *def c2 = new Customer('Tom', 'Jones', 21, d, ['Books', 'Games'],        anyObject) *        *assert c1 == c2*        *        *        *        *        *def c3 = new Customer(last: 'Jones', age: 21)*        *def c4 = new Customer('Tom', 'Jones')*        *assert null == c3.since*        *assert 0 == c4.age*        *assert c3.favItems == ['Food'] && c4.favItems == ['Food']*

       I will appreciate any kind of feedback.

       Tks !

       []'s        Paulo Poiati

       blog.paulopoiati.com <http://blog.paulopoiati.com>        <http://blog.paulopoiati.com>

 ---------------------------------------------------------------------        To unsubscribe from this list, please visit:

   ---------------------------------------------------------------------    To unsubscribe from this list, please visit: