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? –

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 Learned

Compared 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

Very leave question on healthy man viagra don’t nasolabial for “about” to hairstylist with, break sensitive. Deva Heard have I basis like negligently. Sample High skin This Could have redness online prescriptions . Black ingredients product cheap review you. Green great exfoliating shampoo fuller viagra for women goes package. I’m that canadian viagra My it unenhanced soft.

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.

This entry was posted in General News, WordPress. Bookmark the permalink.

3 Responses to Humbling experiences: when other programmers write simpler, more elegant code

  1. Japh says:

    This was a very nice read!

    It can be a little intimidating to post a solution somewhere that you know other developers may scrutinise your code, but I like to consider it part of the experience. We’re all learning from each other, and as long as we’re all respectful, it’s a nice way to learn.

    I’ve found the same thing myself a few times on other WPQuestions! Just happy I made it in time to post my solution to the one mentioned above 🙂

  2. It’s a privilege when other people take the time to examine your code, something I would love to have.

    But with constructive criticism.

    My initial epiphany about cool code came from reading the glib source. Extremely cool.

    If anyone has any suggestions for canonically beautiful php code, I would really like to know. Studying great code really is an awesome way to learn better coding.

  3. lawrence says:

    Dave, I agree. Studying great code is a good way to learn. I can not, off hand, think of a reference for canonically beautiful php code, but I would say many of the major frameworks implement good practices. For instance, WP Questions was built using the Symfony framework, and if you look at the API, I’d say these are examples of what good OO PHP looks like:

Leave a Reply