This is an oldish post from Jeff Atwood's blog (Coding Horror), but I keep coming back to it. In a nutshell, he says that developers spend most of their time understanding code, a significant portion of their time modifying existing code, and the least amount of time writing new code.
I've often found myself rewriting functions, components, classes, etc. that work perfectly fine as they are. I've done it more instinctively than intentionally, and after reading Jeff's post, I realize that I'm really doing it because it's my way of ensuring that I really understand what's going on in the original code.
I do it most often when I'm working with code from another language that I don't know very well, or don't like. By rewriting it in my preferred language (C#), I make sure I know how it works, and I end up with something that I can more easily maintain (since it's in "my" language).
And sometimes I rewrite within the same language -- especially when I'm reworking my own old code -- to refresh my memory about what the function or application does, and to use the spiffy new techniques and optimizations I've learned since I wrote it the first time. It's also very handy for fixing those "what was I thinking when I wrote that?!?" bits of code. You know what I'm talking about: the snippets that compile and run fine, but in an unnecessarily complicated or horribly inefficient way. I like to pat myself on the back when I reduce 5 or so lines of crappy code to one slick statement, conveniently ignoring the fact that it was my own crappy original code.
Thursday, October 26, 2006
Understanding Code
Posted by
jwyse
at
11:51 AM
Labels: Development
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment