Consider the following code (won't compile just for example) that does some complex operation on a layer and then loops through the features in the layer after it is processed. This is actually a counter argument to what Larry was suggesting.

public void execute(PluginContext context) {
 doSomethingLongAndSlowOnLayer(context.getSelectedLayer());
 for (Feature feature : context.getSelectedLayer().getFeatures()) {
  doSomethingWithFeature(feature);
 }
}

Now the problem with the above approach is that if the above is not happening in the GUI thread the user can change the selected layer in another thread so when you finish the long slow operation and try and do something with the features then you are actually going to get the features from the wrong layer.

In this case the code should have been which makes sure that I'm using the same layer in each part of the code.

public void execute(PluginContext context) {
 Layer layer = context.getSelectedLayer();
 doSomethingLongAndSlowOnLayer(layer );
 for (Feature feature : layer.getFeatures()) {
  doSomethingWithFeature(feature);
 }
}

Now I specifically made up this example as a counter argument and there maybe some cases where you do want to make sure you always have the current item from the context (or whatever thread shared object) in that case you would use the method call approach to get the current item each time. But you better make sure that the shared object is thread safe which means any operation that is not atomic (Object a = b is atomic, if (this.x == null) x = y is not) then you must make sure you do some thread synchronization.

Paul



Sunburned Surveyor wrote:
Larry,

I have to ask a really dumb rookie progammer question now. You wrote:
"As you might have noticed, JUMP code tends not to create many
variables. With threading, there is actually some justification for
this."

What affect does variable creation have on threaded programs?

The Sunburned Surveyor

On 8/17/07, Larry Becker <[EMAIL PROTECTED]> wrote:
Those duplicate method calls are mostly cut and pasted from PanTool
code.  As you might have noticed, JUMP code tends not to create many
variables. With threading, there is actually some justification for
this.   I've gotten used to it over the years and don't really notice
it much anymore. I've quit fighting it anyway, but I'll make an effort
to have more readable code in the future.

regards,
Larry
On 8/17/07, Paul Austin <[EMAIL PROTECTED]> wrote:
Larry,

Before you commit, can you replace duplicate method calls such as
getPanel().getViewport() with a local variable and make the method call
once. There are two reasons for this.

1. There is less code to read on each line which makes working out what
is going on easier.
2. When debuging if you follow a one method call per line rule it makes
stepping into a method easier you don't have to go up and down into each
method call.

Cheers,
Paul

Larry Becker wrote:
Well, I guess I'll commit the change on the strength or Paul and
Sunburn's recommendation.  We can always back out the change if we
don't like it.

Larry

On 8/17/07, Larry Becker <[EMAIL PROTECTED]> wrote:

Hi Paul,

  Some of the functionality you are talking about is already present
in my new ZoomRealTime tool, which pans and zooms continuously in real
time.  Perhaps I should port it over (it just needs
internationalization) before doing any more tweaks to Mouse Wheel
Zoom, which I thought was pretty cool when I first got it working, but
now seems a little tired in comparison with ZoomRealTime.

I do agree that your #2 is more useful, now that I have tried it.
I'll wait for more feedback from others before committing the change.

regards,
Larry



On 8/17/07, Paul Austin <[EMAIL PROTECTED]> wrote:

Hi Larry,

Normally I hate people messing with my mouse pointer but in this case I
would find it useful.

Here are the three options for mouse wheel zooming that I see.

   1. Zoom in and out of the current viewport center (not that useful in
      my view).
   2. Zoom in and out at the current mouse location (google maps does
      this) (default option)
   3. Zoom in and out of the current mouse location but center the
      viewport and mouse pointer at that location (advanced option while
      holding down the shift key)

Another thing I'd like to see is an integrated pan and zoom mode, where
if you double click it zooms but when you drag it pans, much like google
maps does. This could be integrated into the current pan tool. I'd still
like the BBOX zoom functionality from the zoom tool.

Paul

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


--
http://amusingprogrammer.blogspot.com/



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

--
http://amusingprogrammer.blogspot.com/

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to