Humbling experiences: when other programmers write simpler, more elegant code
Many times I’ve been humbled by other programmers. Just this last summer I worked on a project with Scott Meves. We were using the Symfony framework, the same framework that WP Questions is built in. Scott is a true genius when it comes to Symfony. I recall we needed to do some JOIN calls to the database using the Propel ORM, and Scott always knew the perfect, most concise way to write such code. It was humbling to work with him and see the elegance of the code that he wrote. So I can related to what Hafiz Rahman is saying here:
It all began with Darren Hoyt’s tweet:
interesting new question over at WPQ courtesy of @jophillips, any ideas? – http://bit.ly/7NOEl3
The particular question was about adding an “old” or “new” class for a listed Links based on whether the Link is inserted less/more than 31 days from now.
Curious, I dug around the Codex and into the core files. I began to think about filtering wp_list_bookmarks. Tabs upon tabs were opened, lines of code tested. Finished, I logged in into my WPQuestions account and opened the page again.
Amazingly, the question was already solved (this is only a couple hours after Darren linked to it), and there I saw two different solutions, both solved the problem with a short and easy to understand piece of code. One of it involved editing core file, which generally is undesirable, but both codes were undeniably elegant and to-the-point.
Lesson LearnedCompared to those two codes, mine was much longer: it involves regular expressions, string replacement, and so on. While it did work, I concluded that I was just thinking too far. The first solution didn’t worry about editing core files, while it’s something completely out-of-question for me. The second solution simply do away with creating its own list, while I insisted on making use of wp_list_bookmarks‘ output, forcing me to go the regex route.
…To put it short: I had too many rules in mind while looking for a solution.
The question was “Change the class of a blogroll link if older than 30 days“.
As I said, I can relate to what Rahman is saying. I certainly know what it is like to spend hours thinking about a very complex solution to a problem, and then later realize (or have someone show me) that there was a more elegant solution. I hope WP Questions continues to attract such quick, elegant solutions as those offered for this question.














Recent Comments