Learning Code
How I approach a code base that I am not familiar with?
I know what it is supposed to do. I got no idea how it does it, though. Hopefull it is not something as vague as "handle client transactions".
The next step is to read through the code. Not in any particular order, just pick an Access Point and start you search from there. Most of the OO techniques are about seperating concerns, and this means that you may have a hard time figuring out what exactly is going on with the code.
I write a couple of tests to verify the existing behavior. This is mainly a sanity check for me, to see that I understand what it is supposed to do. I will also try to debug through those tests, to see the flow of the code. This is very important get a... feeling for the code. A sense of what the original developer has intended.
The next step is to try to add a new feature. I don't usually go for half measures, I try to add a radically new one, and see how I can integrate it into the rest of the system. The easiest way to do it is to add a failing test and try to get it to work. One important consideration is that I'll want to make it integrate as seamlessly as possible with the rest of the system, this means maintaining the same coding standards, programming idiom are important.
After I make the first feature test work, I write several more premutations of it. To try and see how tohe system behave in unexpected circumstances.
Usually, after implementing a big feature, I have a fair amount of knowledge about the system. Good naming helps, a lot.
All of the above is true if the codebase is reasonable. If it is bad, I'll either write from scratch or use Sprout New Application.
How do you do it?
Comments
Comment preview