Thursday, October 30, 2008

Empty iterator still runs _finally

In my years of doing code reviews I have always gotten on people's cases for writing...


_if _not some_set.empty?
_then
_for a_value _over some_set.fast_elements()
_loop
write(a_value)
_endloop
_endif


... what's the point, I asked, of asking SOME_SET if it is empty? If it is empty, then the loop won't be entered anyways and now you are just cluttering up the file with redundant code. It seems that the following should be equivalent...


_for a_value _over some_set.fast_elements()
_loop
write(a_value)
_endloop


Well, today I learned that those two statements are not equivalent. If you use the _finally keyword, its scope will always be processed, even if the iterator has not even run a single loop.


MagikSF> _for a_value _over {:a,1,"bb",300}.fast_elements()
_loop
show(a_value)
_finally
write("Finally")
_endloop
$
:a
1
"bb"
300
Finally
MagikSF> _for a_value _over {}.fast_elements()
_loop
show(a_value)
_finally
write("Finally")
_endloop
$
Finally


So lesson learned... if your _finally block of code expects some value to be set in the main _loop block, be sure to put error handling in there for the case where the loop had no iterations to process.

Monday, October 6, 2008

Configuring the GE Smallworld FME Plugin as a Server

Anyone that has done any work with GE's version of the FME Smallworld Reader/Writer will know that it does not behave well as a stand-alone server.  So you are faced with one of two options:
- purchase SpatialBiz' FME Plug-in.  It has been designed as a server process.
- modify your existing (i.e., already paid-for) GE Smallworld Reader/Writer using a combination of Python, TICs and a few Magik enhancements to allow the FME Workspace to dynamically control the fme_tics_client class.

You can find a more detailed description by look at the "Behind the Scenes" section at http://evangelism.safe.com/smallworld2008.

Here are the steps you would need to take:
- create a Python Module that exposes Tics32.dll functionality
- extend the Python Module to expose various Magik methods such as setCollections(), rollback(), rollforward(), gotoAlternative(), etc.
- modify fme_tics_client.private_run() to listen for TICS messages from the new Python module.
- configure your FME Workspace to use the new Python Module.

I have prepared a package (licensed under LGPL) of Python and Magik code (along with a workspace sample) that I am happy to send out upon request.  Thanks to my employer (Red Planet Consulting, Inc.) for permitting me to make this available to the Smallworld community.

Send me a note at... 


...to request a free copy of the Python, Magik and FME Workspace files I used to integrate FME Server with the GE Smallworld FME Reader/Writer.