3 ms·
I rewrite code to explore and understand it. This actually started as a bad habit - "Oh, I can't believe this person did X, I'm going to change that to Y". Do t
by softbuilder 12y ago
I rewrite code to explore and understand it. This actually started as a bad habit - "Oh, I can't believe this person did X, I'm going to change that to Y". Do that enough and you quickly figure out exactly why they did X, and they were either smarter than you or much more familiar with the problem domain. But now you know a little more, you have a little more respect for the code, a little more humility, etc..
Nowadays I take it as a given that I'm probably wrong, but I start rewriting anyway. Worst case (and most common case) I have to toss the code. But I learn. Plus there's a different place your brain goes when you feel like you control the code vs. looking at it behind glass.
- plorkyeran 12y agoI see rewriting code to understand it as basically the ultimate form of taking notes while reading something, since you can run your "notes" and verify that they're actually correct, and you can't get away with just glossing over things you don't get.
- amboar 12y agoThis is exactly how I work as well. My feeling is the only way to truely understand a piece of code is to try solve the problem yourself and not simply read someone else's solution. But, half the battle is then understanding _every problem the code is solving_. Often this seems undocumented. Further, even the simplest high level problems often have a bunch of corner cases that are only documented in a solution's implementation, and it's on encountering these corner cases in your own solution that it becomes obvious why the code was written in its original manner. Coming to a full understanding of the problem and solution often leaves me happy to throw away my own attempt. Sometimes I'll simply end up adding some comments to the code about the problems it's solving.