A Developers Mindset

I listened to a podcast called Lullabot, which is dedicated to the Drupal CMS and found this beautiful quote in episode 103: Views in Core.

As a developer that always offends me. If you’re writing the same code more than three times, than you should fix that, so I did and at the time I wrote a 1500 line module called Views.

This is the quote by Earl Miles, who is the initiator of the Views module, which is most popular module for Drupal and it’s something every Drupal developer knows.
Views lets you arrange the display of your content, sorted by a lot of different filters, basically apply any sort of displaying content, influenceable by a large number of circumstances.

Solve a problem and share your solution

I find this great, because I’m a developer, but like people proclaim that a hacking isn’t a skill, but a mindset, so is this. This mindset of eliminating redundancy and after that even making it available to everybody else, so they never have to get through this again, is what I find admirable and progressive.
Repetitions suck

Not only on TV, but also in real life, repeating things is one of my least favourite things to do. Some things are okay when you do them over, like playing the same map in online games, because your opponents and teammates act differently. In programming however, building stuff twice is just plain annoying and mostly unnecessary.


A commonly accepted rule in programming is DRY, Don’t Repeat Yourself. That means that you rather write a function for doing a specific task, instead of actually doing that task every time something occurs.
Let’s say you want to play nice and thank your users for doing stuff. This will not only happen on one page, but on several in different contexts, so instead of writing stuff like:

// on the comment page
echo "Thank you very much for your comment" . $username;
// on the picture upload page
echo "Thank you very much for your picture" . $username;

That wouldn’t be so cool, because you’d end up spreading all these thank you lines accross several files and you’d have to change all of them, if you decided, that you maybe would also wish them happy easter at a specific time or just be rude and not thank them.
You could create a function, that is available called ‘thankyou’:

function thankyou($username,$action) {
    switch ($action) {
        case 'comment':
            $output = "Thank you very much for your comment, " . $username;
        case 'picture':
            $output = "Thank you very much for your picture, " . $username;
    return $output;

echo thankyou('Harold','comment');
// outputs: Thank you very much for your comment, Harold
echo thankyou('Maude','picture')
// outputs: Thank you very much for your picture, Maude

On a much higher level, this is what the open source community does. They find ways to solve problems, connect them into bigger projects and share them amongst each other and the rest of the world.

How do you avoid repetitions?

What do you do to dodge the annoying repetitions? What do you think as the internet as our collective memory, which enables us to do more we actually would like to do, because somebody has pre-shaped a solution for us or can teach us fast, through wikis and videos?

Leave a Reply

Your email address will not be published. Required fields are marked *