Sunday, February 21, 2010

HTM theory and Spaghetti code

HTM theory is a very interesting view of how people think and why they are so intelligent. Today I stumbled upon some Spaghetti code in a software project I'm working on. There was a method of more than a thousand lines.

As I was scrolling through this behemoth of thought, I started seeing some patterns. I immediately remembered HTM theory and how it modeled human perception. You receive some information through time (scroll the text) and you find patterns in it.

What can be done here? Refactoring. When you're at the top of the "see" pyramid you can already make high level processing of the whole method of thousand lines. You can "see" that there are some duplications of code. If you're not used to techniques of procedure/object oriented programming you might try to struggle to memorize all these repetitions. But someone who's familiar with refactorings such as extracting a method will quickly evaluate the gains of removing a lot of unnecessary duplications by passing an argument to a generalizing method. And thus you'll decide to change the code and will go down the "change" pyramid.

I wonder if you can train a HTM to do code refactoring :)

No comments:

Post a Comment