I had an interesting experience earlier this week. I was reviewing some code and found a section where the code looked very strange at first glance. There were some comments, so I knew what it was supposed to do, but my first impression was that it was just wrong. I spent some time stepping through it and thinking how to fix it to make things look better and be maybe more maintainable.
As I stepped through it, I realized it was actually a pretty elegant solution and I couldn't think of a way to make it better. My first impression was wrong, it was really good as it was. I was curious who wrote that section, so I searched through our version control system and found that I had written it about a month earlier.
It reminds me of when I discovered I am a decent developer. I was doing some socket work in C++ and ran into an issue where I could get a socket connection that would ignore a timeout when connecting over SSL. The bug drove me crazy for half a day or so. Eventually, I decided I'd pull up the source code for PHP because I knew they had implemented similar socket connections.
I found that not only did they have the same bug, but their implementation was almost exactly the same as mine. The only differences were some variable names. It really surprised me that I could come up with something just as good as the authors of the PHP engine. I felt pretty good about that. I think I eventually solved it and submitted a bug report to PHP. They already had a solution that came out in the next release. Again, their solution was pretty close to what I came up with. Happy day for me!
No comments:
Post a Comment