Author's Bio: Anton Mamaenko

Monday, November 8, 2010

Formatting the obsolete, or inherited code

Another title for this piece could have been: "An idea for automatic run-time code refactoring".

When imposing new code formatting rules on a team - be it Camel or Hungarian - the most annoying question would be: "yeah, that's cool but what's about the old code? Should we refactor it too? And what about the standard libraries?.." All programmers are attracted to neatness, but being inconsistent with existing code is really madening, so after a bit of debates the idea of strict code formatting rules get washed away.

But here comes a glimpse of hope. With new generation of languages such as Python, or managed code frameworks it became much easier to write code that analyzes itself during run-time. So why not have a library that would wrap around every imported module or class, and override the invocation operator. So that user can call methods, and instantiate classes using his favorite notation, and the wrapper will search for all possible interpretations.

For example there is a very old old_cranky_module.py containing something like this:

def __i_am_obsolete___():
...

def iWasDefined_byMadPerson():
...


but when the user writes his code, he uses the wrapper that will intellectually find this methods by their names in proper notation:


from NotationWizard import Import
Import(CrankyModule)

x = CrankyModule.IAmObsolete()
y = CrankyModule.IWasDefinedByMadPerson()

No comments:

Post a Comment

Search This Blog