Tuesday, October 17, 2006

Reuse Pain in Eclipse UI Code

Code Reuse is one of the most interesting, if not alluring, part when you are contributing to Eclipse. In eclipse, many a times I'm tempted to use code of other plugins. Eclipse guys like to keep UI-code 'internal' , still, I try and again to reuse, which ends up in "monkey see/monkey copy+paste" with added disarrays.

This temptation is not just because of my indolence to duplicate development cycles but something which is commonly done (it's all about reuse right?), ofcourse at very clear granular leves (called extensions) which, I, somehow find limiting.

It is too frustrating to figure out sheer context information for some code deep in eclipse dungeons, the more you read code, deeper it takes (and ofcourse how can the temptation of what is inside be controlled?). This results in a tempest of hazardous shortcuts which keeps you away from starting afresh or thinking in different way and you end up in violent mess of yellow signs and incomprehensive code !

Recently one of my collegue ran in similar situation, I looked in to it to see how serious it can get, I too quicky drawn in it. The task involved implementation of preference pages for code/comments etc. in our code generation templates, as well as templates for ADDL( home grown action semantics language). We started looking into JDT UI, which has a preference page with similar functionality named "CodeTemplatePreferencePage" which delegates UI to CodeTemplateBlock which in turn owns inner classes to do "real" stuff. There are hardly any hooks where it can be extended "as is". We started with extending it and ended in copy pasting somewhere around 6-7 java files (and contrived satisfaction that it was looking good to end-user).

It just didn't helped! we finally created UI using Eclipse Visual Editor and programmed widgets/viewers and preferences in less than one forth the time we spent in reading and fumbling in JDT-UI code.

Lessons learned after hours of pairing, never try to reuse what is "internal" and don't ignore it no matter how tantalizing it is!

No comments: