I freely admit that I am no Lisp programmer. I just admire Lisp from afar and theoretically. And yet recently I managed to experience a Lisp-like and C-like approach in certain code - all while staying in C++.
At work I deal with some nasty mess written 15 years ago for X Windows, using GUI toolkit that nobody remembers any more. It was initially straight C, but now has a lot of C++.
I am trying to implement a GUI testing support for that beast. Some pretty cool idea, even if I do say so myself - I'll write it up later. In any case, the GUI toolkit has no concept of a "standard" listbox. Each listbox is completely custom, drawn from opaque ClienData for each cell.
To extract strings that my testing toolkit can handle, I had to somehow intercept the drawing routines. All 200 of them. Preferably w/o disturbing the existing code. So I came up with this ingenious schema of moving the drawing code into a body of a class, where the drawing functions would be class methods. I felt it to be somewhat like a manual version of a Lisp program, code operating on code and changing it.
However, since that was C and C++ and not Lisp, the actual implementation was smelling worse by the minute. Completely unhappy with the mess I created, I went to a coworker for advice. He, being a simpler man altogether ('simple' as opposed to 'easier', the right kind) suggested that I should intercept calls to drawText in the common library used by 99% of our list boxes. So now I install a callback in one place, and no code changes are needed anywhere else. Perfect C-style solution for the C environment. No Lisp feeling at all, but it's beautiful.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment