Let’s move !

October 17, 2011

After 6 years working as Eclipse plug-ins developer I decided to take a new big challenge: start a PhD. I will still blog about Eclipse (but certainly less often) here because my PhD subject is about SOA and I’m sure that Eclipse is somewhere linked to it because Eclipse is everywhere, isn’t it ?

I would like also to take the opportunity of this post to THANK publicly JeromeĀ  for his help during these 6 years: “thanks”.

Stay tuned for this new story


Object instances reuse and Eclipse API

October 3, 2011

Reading one of my colleague’s code I saw this:

GridLayout gl = new GridLayout();
gl .numColumns = 1;
gl .verticalSpacing = 0;
gl .marginHeight = 0;
gl .marginWidth = 0;

Composite c1 = new Composite(parent);
Composite c2 = new Composite(parent);
c1.setLayout(gl);
c2.setLayout(gl);

Personally I always create a new layout for each one of my GUI component. It is in my opinion more easy to read that the piece of code above and because there is a small number of such objects (having a UI with thousands of GUI component needing a layout is bad idea I think ;-) ), creating a new one for each component doesn’t impact performances.

To go further in the probleme, reading this code lead me to the following question:

How do I know if a given class instance can be “shared” in several contexts ?

In the particular case of the GridLayout above, I was not able to find the answer in the Javadoc here: http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/layout/GridLayout.html. After looking at the source code of GridLayout it seems that there is no internal state saved anywhere, and thus it’s possible to use the same layout instance for several components.

May be I missed something or maybe it should be interesting to indicate this information in the Javadoc. For sure, I’ll take care of that when writing the documentation for my own libraries.


Follow

Get every new post delivered to your Inbox.