Wednesday, March 09, 2005

Expanding and Resolving
I started out today trying to implement the ConstraintDifference class, but from the outset I ran into difficulties.

A couple of months ago Andrew implemented the visitor pattern for implementing constraint resolution, but this had a few problems. The most obvious hassle was that every separate constraint type needed to have individual methods be declared for it. This is a maintenance problem, and does not deal with new constraints very well. While not an issue at the time, it also can't deal with runtime additions to the constraint system.

Regardless of the problems, this is how the system was built, and I had to make ConstraintDifference work with it. I started looking at the dispatch functions, but this is where things went a little strange. While some of the classes full of functions were there, I couldn't find everything I expected. In particular, I could not find anything calling the accept() method for any of the constraints.

I was able to write a little bit of code to work in with what I could find, but after spending hours pulling my hair out I resorted to asking Andrae for help. I was hoping that he could enlighten me, as I felt like I'd forgotten everything I knew about Kowari.

It turned out that Andrae was exactly the right person to ask. His first comment was that the accept() method no longer exists. This didn't make sense to me as it was only introduced late last year, and I'd used it just before Christmas. Also, every class still has this method. Andrae then explained that this method had been refactored out completely.

I expressed dismay about this development when nothing had made it onto the Kowari mailing list, but Andrae said that it all happened while everyone was still at Tucana (and internal development like this didn't usually make it onto the list). I was confused at this, as I had heard nothing about it, so Andrae explained that it happened in the final weeks before Christmas.... which was when I was on leave.

So a major change to the constraint resolution happened, and somehow it slipped between the verbal discussions that were held at Tucana, and the emailed discussions that came about after the company was closed. Hopefully that was a one-off event, and it won't be repeated.

Andrae pointed me to LocalQueryResolver where all the work is being done now. This class uses a map from constraint classes (the actual class object, not an instance) to an inline class which implements a single method called "expand". It is this method that gets called to resolve the constraint.

I was confused while trying to read this code, as the syntax was all about "expanding" expressions. Since most constraints get expanded before resolution (eg. conjunctions and disjunctions) then I presumed that this was what the code was supposed to do, but I could not work out where constraint resolution was happening.

After a bit more reading, and some frustrated words sent Andrae's way, I finally figured out that this was the resolution code. It was simply a matter of unintuitive names. I explained my difficulties with the name, and Andrae agreed, stating that he had initially intended to perform a bottom-up resolution after performing a grammar expansion, but that this ended up being just the resolution task without any explicit expansion. Hence, the name is misleading, and he was going to change it, but the shutdown of Tucana meant that he never got to it.

With the time I had left today, I decided that the first thing I should do was a minor refactor where I changed all the references to "expansion" into "resolution", while carefully avoiding calling anything a "resolver", due to the obvious name clash. I finished this, and also included the mappings for the new ConstraintDifference class.

Everything is now compiling, but I have only really set aside the space for the difference operator. Tomorrow I hope to make headway into the body of the implementation.

No comments: