FDO and Python

Jason and Mateusz have each posted about Python bindings for FDO this morning, and so I took a look into it. I've been intrigued by FDO ever since I heard of it in October of 2005. Python is my bread and butter, and I'm sad to say that the FDO Python bindings are disappointing.

This, in particular:

oProperties.Release()

almost made me cry like the man in the classic anti-littering PSA. Python has garbage collection. Don't abuse your users. They shouldn't have to explicitly free memory allocated for objects.

Thanks to SWIG, the Python bindings are a literal translation of the C++ API, excruciatingly verbose and explicit, and annoyingly un-Pythonic. The developers need to learn about Python patterns and protocols, and implement them. As I mentioned in Jason's blog, factory methods like:

>>> schema = FdoFeatureSchema.Create(sSchemaName, sSchemaName)

need to be changed to the familiar form:

>>> schema = FdoFeatureSchema(sSchemaName, sSchemaName)

That's how it's done in Python. Any other way is needlessly confusing. Implementing Python's mapping protocol would let users write:

>>> sewer_pipe = classes["SewerPipe"]

in the natural Python way instead of:

>>> oClass = oClasses.FindItem("SewerPipe")

Comments

Re: FDO and Python

Author: Matthew Giger

I took a quick look at this as well and am not overly impressed. Any project that still uses SWIG for a C++/Python binding has either never heard of boost::python or is in need of revision. I've looked quickly in the core C++ and they even make their own shared pointer class instead of using boost::shared_ptr. To add insult to injury, apparently the FDO SWIG bindings are not cross platform compatible either. Oh well.

Re: FDO and Python

Author: Jason Birch

I think that adding FDO support to PCL would be awesome Sean. However, I also think that it would be useful if your (both of your) expertise could be used to inform the FDO project. Any chance that you would consider interacting on the -internals mailing list? This feature addition was a bit of a black box (I was shocked by its annoucement) and I'm sorry that it was done fait-accomplis rather than through community consultation. If a poor choice has been made in the way that Python support is implemented, then the project really should be open enough to engage in discussion around it and work to resolve the issues. And if you have spare time on your hands, the project really needs more external involvement :) Jason

Re: FDO and Python

Author: Mateusz Loskot

Matthew, Yes, you are right I think. FDO uses its own set of types, and the whole concept of an object in FDO is directly based on COM object. That's how I understand it after a few months of learning FDO. However, FDO is not affraid of Boost and it uses it, mainly Boost.Threads. Generally, we have the whole tree of Boost in the FDO repo, so anyone is free to use it. For example, in the provider I work on - PostGIS provider for FDO - I use Boost features quite intensively, but this is my choice as I like Boost very much. Here is my pre-release repository, I use privately, not yet merged with the official FDO tree: http://svn.refractions.net/fdopostgis/ The decision about choosing SWIG over Boost.Python was made by the core FDO team and if you are interested why SWIG has been choosen, please visit the fdo-users or fdo-internals list. Anyway, that could be an interesting discussion :-)

Re: FDO and Python

Author: Mateusz Loskot

Sean, Thanks for this very helpful and informative analysis. I can only confirm the API and style of Python scripting for FDO is a direct port of what FDO offers for C++ programmers. I agree, that for Python, a scripting language, users demand for simpler solution than already available for C++ coders, but I'd like to point that it's a very early version of the wrapper. I *believe* (as I don't know it) if the FDO team get some feedback, they will make a use of it and improve the wrapper.

Re: FDO and Python

Author: Sean

Thanks for the comments. Its cumbersomeness aside, I'm finding the Python bindings (specifically the unit tests) useful for learning the capabilities of FDO. It's confirming some of the design decisions of PCL (which has something more like the ISO/GeoTools feature model), but also showing me a different, complete model.

Re: FDO and Python

Author: Jason Birch

Greg just posted something on the fdo-internal list that confirms Mat's beliefs. http://lists.osgeo.org/pipermail/fdo-internals/2007-March/000928.html Or (because the MailMan archive doesn't wrap the lines) http://www.nabble.com/RE%3A-FDO-Incubation-Progress-Reports-p9488349s18162.html As I've said at least once before, it would be cool to have someone active in our community who understands how to appropriately set up Python bindings for FDO.