Wednesday Jan 10, 2007
Wednesday Jan 10, 2007
Hans writes an excellent post on the use of bound properties, and how a simple property keyword that simulates getX/setX methods wouldn't buy him much.
Properties also have a difficult interaction with access control. Declaring a property to be publically readable but only package/protected/privately writeable would either be impossible or need some hacky syntax for the read v. write access level. This is not an improvement over getX/setX.
Now, since no-one is talking about VM support, properties would be implemented through translation to methods and fields. Obviously this makes them less amenable to reflection, but my main concern is this. We have an increasing list of language constructs implemented through translation: instance initializers, bridge methods, inner classes (and the calling convention for their constructors), enums. Specifying such translations in the JLS is rare because they are implementation details. (Notable exceptions: 15.9.3 implies the calling convention for anonymous classes and 8.9 has some info about enums.) We don't want to restrict the classes emitted by compilers except when it's essential for source and binary compatibility. (The binary representation of a class in 13.1 is rather loosely specified for this reason.) Clearly, a cross-compiler convention for representing properties would be necessary in the JLS, so no-one would ever be able to implement properties in a more lightweight fashion.
I must admit I do like the increased safety available in Stephen Colebourne's property proposal, though maybe you could get that with method references: (borrowing from the Javapolis whiteboards)
binder.bind(user, User.getFirstName.method);
binder.onChange(user, User.setFirstName.method, closure);
But overall, like Peter von der Ahé, I am moving away from properties.
Posted by Fatih Coskun on January 10, 2007 at 10:00 AM PST #
Posted by Reinier Zwitserloot on January 10, 2007 at 01:00 PM PST #
Posted by Stefan Schulz on January 14, 2007 at 07:25 AM PST #
I would not wonder, if accessing method objects could not go hand in hand with the closure stuff somehow. Imagine using a method reference as parameter type defining the closure's signature.
When reading Stephen's proposal, the only thing I can see is providing a shortcut for saving to write OO code. Quite a big chunk of code, but still. This should not be the task of a new compiler construct and could be solved easily by any good IDE (even including maintenance aspects). But maybe I am missing something important here.
Posted by Stefan Schulz on February 01, 2007 at 03:11 PM PST #
I would not wonder, if accessing method objects could not go hand in hand with the closure stuff somehow. Imagine using a method reference as parameter type defining the closure's signature.
When reading Stephen's proposal, the only thing I can see is providing a shortcut for saving to write OO code. Quite a big chunk of code, but still. This should not be the task of a new compiler construct and could be solved easily by any good IDE (even including maintenance aspects). But maybe I am missing something important here.
Posted by Stefan Schulz on February 01, 2007 at 03:11 PM PST #