The Artima Developer Community
Sponsored Link

Java Buzz Forum
Sun Java Designers Distancing From Property Syntax

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
Sun Java Designers Distancing From Property Syntax Posted: Jan 10, 2007 5:37 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: Sun Java Designers Distancing From Property Syntax
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

It took 34 days since the initial posting (and my reporting), but it seems that some of the Java language designers and other Sun folks (Ah��, Buckley, Muller) are moving away from the syntax for properties.

I believe Hans Muller's post asked the most fundamental question: What are properties for?

And if I remember correctly, the properties concept came into Java through the JavaBeans specification in JDK 1.1. It was supposed to be an abstraction layer of the underlying mechanisms for GUI builders, like Microsoft's COM. Properties, together with the concept of methods and events form the foundation of a GUI component system. And of particular utility are a couple of combinations of properties and events: the constrained properties and vetoable properties.

So properties, in that context, does something useful. For example, when you set the text property on a Label, it will have go find the appropriate glyphs from its font and erase the old text and paint the new text.

Somewhere along the line, the concept of properties were subverted. It became a mindless chant:

// Exhibit A
public int foo;
is not OO! Change it to
// Exhibit B
private int foo;
public void setFoo(int value) {
  this.foo = foo;
}
public int getFoo() {
  return foo;
}
to make it OO. And along the way, we, with our favorite IDEs as accomplices, managed to bloat the world total Java code base by about 10% (maybe more).

It is these IDE-generated, boilerplate, pointless bloat that most people hate. And we wish we can do

a.foo = b.foo;
instead of
a.setFoo(b.getFoo());

Well, there is an obvious solution to this (minor) gripe. Can you guess what it is? You're right. You can accomplish this goal without addition to the Java programming language. You can simply turn all instances of Exhibit B into Exhibit A. There should be a refactoring called "Remove frivolous getters and setters" that does it automatically.

Go ahead and do it. Should take about ten minutes.

You done? Did it break your app? Probably not.

Do you have any getters and setters left? If not, you're done. And you can go home now.

The remaining getters and setters are the true properties. Now stare at them for a minute. (Here's an example from the JDK:

public void setNextFocusableComponent(Component aComponent) {
  boolean displayable = isDisplayable();
  if (displayable) {
    deregisterNextFocusableComponent();
  }
  putClientProperty(NEXT_FOCUS, aComponent);
  if (displayable) {
    registerNextFocusableComponent(aComponent);
  }
}
from javax.swing.JComponent.)

Still feel like some syntactic sugar for properties? Go ahead and add some. (Here's a tip: the Microsoft folks have property support in C# for six years. I wouldn't mind that syntax!)

Read: Sun Java Designers Distancing From Property Syntax

Topic: Property Support in Java, the Java Way��� Previous Topic   Next Topic Topic: IntelliJ IDEA 7.0 (Selena) roadmap

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use