I wrote the following comment after reading this:
http://www.javalobby.org/java/forums/t88090.html
So, if the syntax to access properties in Java are going to be like this:
customer->name
instead of this:
customer.name
I would say that Java did it again: it wasn't enough libraries like
Date/Calendar, Swing, Java Mail, EJB (before 3.0) and others be written the way
they were, very complicated; they could complicate even the use of properties in
the language in the name of the so called 'flexibility' that treat the most
unusual scenario so important or even more important than the scenario that is
used in 99% of the cases.
How come language designers make its users type '->' (two characters instead of
just one) everywhere to access a property just because they want the user to
have the hability to expose a field with the same name of the property, and for
this field, that is a lot less commom than a property, have the '.' (dot)
access? If the user wants to make a field public he will give this field a name
that doesn't conflict with the name of any property in the interface of the
class. This is the right solution. And about the private fields that serve to
hold the values of properties, I'm sure that no one won't care to prefix these
fields with '_' or 'f' or whatever they want not to conflict with the property
name, for the clients of the class (that are the reason why properties exist) to
have the ease of use to access properties the second way showed above, with the
dot notation.
Come on, if the syntax to access a method of a class is this:
dialog.show()
the syntax to access a property of a class should be like this too:
dialog.title
dialog.title = "Customers"
This is intuitive, consistent with the method syntax, productive, clear,
elegant, easy to type, less error prone. This is so right that I don't know how
someone can think something different than this. All other languages: C#,
Delphi, Ruby, Eiffel, JavaScript, etc. could not be wrong. They users haven't
complained about the way they implemented properties. So, why Java should come
up with another syntax for properties instead of the one that we have seen
until today? Just to complicate users' life, taking their productive away,
in the name of a 'flexibility' that is not worth its weight, that doesn't
even exist? If properties are going to be implemented with '->' it will be
easier for the implementors of a class, but it will be a nightmare for the
users of the class, that are the majority of people and the reason why
properties exist. The implementors of a class have to program for the users of
a class, not for themselves. The same is true for language designers; they
should have as the main goal the users of classes, not their implementors.
I see that many people that don't use Java want to use it, but people that
design the Java language and its APIs keep making them away from it,
scaring them.
Getters and setters are one of the most painful things of Java. If they want to
add property support to the language now, don't do it 'the Java way',
do it the right way, do it with the '.' (dot) notation.
Marcos