If Only I Had


I have seen the quotes, the tattoos, and the posters shouting “No Regrets!” Unfortunately it’s simply not a reality – at least in my life I’ve not found that to be true. Instead as the title suggests I find myself often thinking, “If only I had…”

I’m going to be perfectly honest. I have and will continue to have regrets. Not because I wish there were things I hadn’t done, but rather regret that they didn’t work. Does that make sense? Yes, I learned from my mistakes and I am very glad to have made them. But that does not mean I am glad they didn’t work they way I wanted. And I regret that. As I look back on those times I will most certainly say If only I had done this or that.

It’s simple really. There are two ways to look at the phrase, If only I had.

1. If only I had done something differently.
That means I attempted something. I tried. I may have failed but I tried. I am looking back on an experience and learning from my failure. There is benefit in questioning your choices and determining if you could have done something better. I like this option.

2. The second option is not so good. If I didn’t attempt an idea.
If I quit before even trying and look back and say, If only I had tried. I consider that a failure. Because I didn’t try. This is the option where I should have been better. I should have tried. I don’t like living with this regret. It says I was too scared to try. I let my fear dictate my actions or the opinions of another keep me from doing what I thought would have worked. Could it still have been an epic failure? Absolutely. But I wouldn’t be wondering what if…

So it’s quite simple to me. I don’t have a problem with saying “If only I had.” I have a problem with not trying. Next time you’re looking back on decisions you made and times you’ve failed I encourage you – it’s ok to analyze and learn from your mistakes. Question yourself. But don’t give up before you start. Don’t regret that you didn’t try.

Understanding Your User


It’s easy to build a business to meet your needs. You know an industry, a market, or a technology and you want to use that knowledge to build a business. Don’t fall into the trap of designing your marketing plan around yourself.

Not the Man in the Mirror

You are not selling to yourself. Or rather, you shouldn’t be. Instead of talking about your business as if you were talking to someone who understands everything you do – focus on finding your target audience and then understanding what they do or don’t know. Never forget you are the expert. If a user understands everything you do then they most likely don’t need your services.

It’s Easy

Growing your understanding of your audience is easy to do, but it takes time and more importantly it takes thought. Many small businesses fail to understand the importance which should be placed on understanding the user better. You need to stop looking at yourself but focus instead on the ones who need you. Here’s a few ways to help you get started.

Ask Grandma

It’s very easy to find out what other people think or know about you or your business by asking someone from a different age demographic. This is in no way disparaging the elderly. Rather we’re highlighting the differences in life lessons and experiences between generations. Tell an older person what you do and see what questions they have. Be sure to write them down and then figure out how to improve your pitch to answer those questions before they ask them. Ask and then listen. That’s important, you shouldn’t ask them then continue directly on with your own thoughts. You need to ask and then patiently, quietly, listen to what they say. They have different views and different life experiences and if you truly listen you’ll find incredible opportunities for improving yourself.

Play Make-Believe

Most kids play make-believe when growing up. I know my kids do it all the time. I laugh sometimes as I overhear them. They have completely different lives, new names, new ages, new likes and dislikes. And all just for fun in their game. What an absolutely perfect example of what small businesses should do. Pretend to be your own ideal customer. Give yourself a new name, a new age, a new life. Figure out what this “new you” is looking for and then figure out how your business meets a need. It’s a simple concept, for kids it’s simply called make-believe, for adults it goes by another name – personas. I’ll discuss this in depth in a future article. Suffice to say for now, build personas. Play make-believe.

Change it Up

Don’t be afraid to make changes. You can always revert them back if you find they are not working. As you seek to understand your user you need to see what works and what doesn’t. What resonates with them and helps them to understand you and your business. A popular way of doing this involves employing A/B testing (again too much to cover in this post alone). Give your users different experiences. See what works for them and what doesn’t. Learn your users likes and dislikes. As you change it up it’s important that you monitor, report, and improve. Don’t simply make changes for the sake of change. Instead make changes because you believe it will enhance the user experience. You have to monitor the outcomes. You have to be willing to roll things back if they don’t work. But you shouldn’t be afraid to make changes.

Understanding your users should be one of your primary goals as a business owner. Figure out what they want. You’ll find if you take the time to learn your user better you’ll be able to attract the right user. Don’t waste your time selling yourself and your business to someone who is not your ideal customer. Save time, save money, and build the right user-base. All it takes is a little effort, and a few new ideas to start the process of understanding your user.

The Ugly Truth About Open Source


When using open source software it’s important to recognize the limitations and struggles you’ll encounter. Open source is not equivalent to perfect software. Let’s discuss the ugly truth about open source software.

We all agree the importance open source software has come to play in our world. In fact, as mentioned previously it’s quite the buzz word. But that does not imply perfection. In fact there are many reasons why open source is not perfect and I’ve written previously about 5 ways you’ll fail at open source. I assume you’ve all read that article, have protected yourself against those failures and have pushed boldly on into implementing open source in your company or organization. Congratulations.


If you’re anything like me when I started with open source you’re probably a bit like a kid in a candy store. All the different software products you can now use, and so many of them free and open source ready to be used. It can be overwhelming, and exciting all at the same time. No doubt you’ll start downloading, forking, installing and playing with more than just one. And here’s where the dark side starts to creep in. Here’s the one key takeaway from this entire post:

Just because you can, doesn’t mean you should.

Failure to Integrate is the often neglected side effect of all these open source products. You’ve downloaded and installed 3 or 4 different tools you like. All of them have great features, but now what do you do? Does each user need to login 3 or 4 different times? Does each application have a completely different ‘look and feel’? Your website can quickly become a disjointed mashup of different applications. You’ll find areas that overlap between them as well. Now you have a website where there are multiple ways to perform the same action, but each looks different. Your users will be confused, frustrated, and possibly irritated when trying to complete an action.

Side Note

Now all of you who are programmers or coders know there are ways to solve this. We can easily write a new application using Composer and Packagist to build a single application with the various bits and pieces we want. And yes, that is a great way to build a cohesive full-service solution which takes advantage of all the open source projects without the integration failures. But I’m looking at the site maintainer, the builder, the end-user who is looking at completed projects ready for installation and use.

When organizing your site and exploring the great wide open space of open source technology and products, please exercise self-control, caution, and a bit of discretion. Your goal should be to use open source for your organization’s success and do so effectively. Be sure the end result is a cohesive site which is easy to use, conveys your brand objective and doesn’t leave the user feeling unsure of your mission.

I believe in open source

I completely encourage every business to use open source. The rewards are tremendous. The software available is incredible and the value you can add to your company is huge. Absolutely explore the various offerings. What I find myself most often recommending is setting up a testing server just for the installation of the many different tools you want to try (or just use online demos).

Remember, your staging or production server is not the place where you test software. Once you’ve played around with it, and you decide it’s a tool you want to use on your site – talk to your developer about integration. Find out what it will take to integrate it seamlessly into your existing website. Discuss the areas of overlap and how to handle them. Make a plan. Focus on your end user experience and how to make it a simple, intuitive website. Use open source the right way.

Childlike Bravery

At times I sit and watch my oldest daughter Kate in utter amazement. She boldly attempts things without any fear of failure. I cringe on the inside and think to myself all the millions of ways it could go wrong.

One particular instance comes quickly to my mind. She was only 7 at the time and had been taking violin lessons for only a few weeks. There was a recital in which some of the older and more experienced students would be participating and her instructor asked her to join them and play a few simple songs. Now, obviously Kate, practiced. She practiced hard.

The day came when she was to play and I was convinced she was not far enough along in her lessons to undertake the daunting job of playing publicly in front of a crowd. Especially not on the violin. It truly is an unforgiving instrument (trust me, I’ve heard hours and hours of practice). And yet, to my shame, Kate boldly stepped up to the center of the stage, placed her violin on her should and proceeded to play the two songs she had been practicing. And she did wonderfully well.

Reflecting on that performance now I’m struck with what I would consider childlike bravery. It’s something I think becomes lost as we become older. We lose the ability to place ourselves in uncomfortable or challenging situations. As adults we try to shelter ourselves from potential failure. We convince ourselves that we’re protecting ourselves from embarrassment – and perhaps we are. But at what cost?

If we were to exhibit more of a childlike bravery where we boldly step forward and attempt things without the fear of failure. If we dare to place ourselves outside our comfort zone, challenge the status quo and truly be brave on the stage in front of the crowd…what could we achieve. Perhaps we would fail.

Perhaps we would be met with jeers and scoffing. But possibly, just maybe we would do wonderfully well.

The Other Side

But that’s only half the story. Here’s the other half. As her parent I consider it my duty to protect her. To somehow take it upon myself to keep her from failing as though I’m doing her some favor. It’s a difficult task because I find myself wanting to stop her too often. But that’s not truly protecting her, that’s doing her the greatest disservice imaginable. Taking away her possibility of failure also takes away any chance of success as well. Keeping her from trying also takes away her optimistic bravado. I take away her childlike faith.

Even as adults we should be careful in the advice we give to others. Be mindful to not squash the dreams of someone else in an effort to falsely protect them. Taking away the possibility of failure will also ruin any chance of them realizing success. We should encourage each other to dream and explore and attempt great things. And so I encourage you – be bold. Try something new. Don’t be afraid of failure. Follow your heart and be brave.

The Importance of the User Experience

Below is the slide deck from a presentation given in Atlanta, GA. The animations and movies fail to play, but the basic gist is still relevant.

Bad UX Examples

Good UX Examples

I also referenced the Android UI/UX discussion presented at Google IO. You can watch this UX presentation on Google Developer.

Drawing lines

There exists an age-old dilemma and constant battle which takes place in just about every online discussion: Where to draw the line, call for a cease fire, and end a thread. 


I’m convinced there is no easy answer. In fact, I’m also convinced the answer varies from one discussion to the next – and from one community to the next. In the world of open source communities (the circle I most frequently travel in) this is an often difficult decision to make. Obviously we want to ensure that everyone has equal opportunity to have their voice and their opinion heard. But clearly we don’t want to encourage bitterness, personal attacks, or hurtful comments either. The job of mediating the discussion should not be the job of a single person but rather should come naturally to those involved in the discussion. Wait a minute – did you read that?

I believe the responsibility for mediation in a discussion falls on the shoulders of the people actively involved in the debate.

Even when discussing very passionately the belief and viewpoint you have – you need to always be in control of your own words. Be careful to not fall into any of the common logical fallacies

Perhaps even more important then not sidetracking a discussion with one of these fallacious arguments is the ability to moderate your own comments to the issue at hand and not turn on a person or emotional plea. I admit this one is hard. Especially when believing strongly about something, but perspective is key. Always keep the relationship in mind. And always keep in mind how the debate appears to other people not involved. 

When discussing a topic in an open and transparent environment, there are sure to be others watching. Not only are they interested in the outcome of the debate but also interested to see how the community handles itself in conflict. 

The hardest line to draw is the line in front of yourself. And then be bold enough to step back from it.

Speaking of drawing lines, I’d like to close with a short humorous video regarding an engineer’s approach to drawing multiple colored perpendicular red lines. 

Unique Presentations

It’s one of the most frequently asked questions I receive when speaking at an event. “Do you reuse your presentations?”

My answer is one I’ve thought about carefully and can answer quickly. No. But I don’t usually leave my answer at that. I like to explain my reasoning why. As I said, it’s a question I have been asked often because it’s certainly the simple thing to do. I travel around the globe speaking in remote parts of the world and many times on the same or very similar topics. Isn’t it smarter to practice, practice, practice the same talk to deliver it with ease and confidence? I’ve decided something different.

Boring Talks.

I believe the problem with this concept is – rather than becoming more prepared, I would tend to become lazy, not thinking or preparing but rather relying on my past deliveries and that it’s an old slide deck I’ve done many times before. And the result would be an uninteresting, boring talk. 

Lessons Learned

This means I must spend the time to prepare for each and every talk. It also means it will take even more of my time because I must, must practice. My high school speech teacher would be proud. He instilled the principles I still use today:

  • Never Write It All Down
    Obviously, it’s important to make an outline, be sure to be clear and concise with your points and make sure you’re coherent. But you should never write your speech out word for word. This makes you attempt to memorize and lose your intensity.
  • Practice and Practice
    Don’t leave it to chance. You should always practice your entire presentation from start to finish. Outloud. You can use a mirror, you can video yourself, but you must vocalize your presentation and practice what you plan to say.
  • Be Self Aware
    You should always know what your body is doing while you speak. Don’t fidget. Keep your hands calm and relaxed. Be aware of any pacing, rocking, or unnecessary body movement.

There are of course many more lessons I’ve learned but I will leave those for another post.

Show Them What They Mean

I believe I am sending a message to the audience when I prepare a presentation just for them. Because it’s more than just a slide deck (as mentioned above), it’s the time, the thought, and more. All these things tell the audience I care about them; they are important to me; and I respect and value the time they are giving to me. It’s a responsibility and an opportunity that shouldn’t be taken lightly or done with a sense of apathy.

Be Real

Most importantly, you can easily be real, and passionate about your message if you follow these steps and prepare fresh presentations for each of your talks. Try it, you may find your next speaking opportunity to be your best ever.

Conflicts in a community

Any time you bring people together you will have more than one opinion. Instantly. On anything. I can’t tell you the number of times I’ve heard of arguments in a group of people over some of the silliest things. It’s human nature. We want others to agree with our point of view. We want everyone to see things our way, and yet, we also know if we all shared the same view there would be something seriously wrong with us.

If two people agree on everything, one of them is unnecessary
— Winston Churchill

How we handle conflicts within a community is important to the long-term success of the community. Let’s examine the concepts involved in conflict resolution within a community of individuals. To begin we should focus on why this group of unique individuals has come together.

What is a community?

A clear definition of terms is always important when discussing things. How can we discuss something if we are looking at two different things? So let’s look first at the definition and structure of a community. I think this is a great place to start. Obviously I assume most of us have a fairly good grasp on what comprises a community so we’ll run through this quickly. According to Wikipedia a community is defined as follows:

community is a group of people whose identity as a group lies in their interaction and sharing. Many factors may affect the identity of the participants and their degree of adhesion, such as intent, belief, resources, preferences, needs and risks.”

That’s a basic definition which serves our purpose quite well. A community brings a group of people together to form a common identity. Singular. One identity. A group of diverse people forming a single identity around a unique intent or belief. Seth Godin offers a slightly different definition on his blog and in his book, Tribes:

Working side by side doing something that matters under adverse conditions… that’s what we need.”

But there are many, many types of community. Let’s save some time and look at only a few of the more common types (want to see the full list? check the footnotes).
Voluntary Association: A group of individuals who voluntarily enter into an agreement to accomplish a purpose.
Interest: A group of individuals who share a common interest or passion
Practice: A group of individuals who choose to collaborate over an extended period to share ideas, find solutions, and build innovations.
Purpose: A group of individuals who are going through the same process or are trying to achieve a similar objective.

So, step one, evaluate what type of community you have joined. Does it fit a distinct definition above, more than likely it’s a hybrid of one or more types. It’s important to start here though. You need to know the underlying purpose of the community you are volunteering in. This will help as we continue to the next step.

Find your motivation

Once you have a good working definition of exactly why your community is formed you need to work out why you want to volunteer and be a part of it. What motivates you? Why do you want to invest your time, talents, and energy in this community. It’s an interesting question I admit. Interesting because it’s simple and yet surprisingly complex. What drives us to do the things we do. Sometimes I’m not sure how to answer this myself but it’s a good exercise to undertake.

But wait, it doesn’t stop there. It’s not a one-time question either. Not only do you need to know why you want to start volunteering but you need to periodically ask yourself why you wish to continue volunteering. Has your motivation changed? Has the community changed? If you answer yes to any of these questions then you need to take a moment and thoughtfully consider your situation. Have your feelings changed, have you lost your passion, drive, or motivating desire; if so, then you know it’s time to move on to a new community and a new opportunity.

Side Topic Let’s talk about that for a minute. I just said move on. Does that mean I think your services as a volunteer are of no value? Absolutely not. Every single individual has a unique set of talents and abilities that together form the identity of a community. Does that mean you should never move on. Absolutely not. Interests change, people change, and as we just discussed communities change. It’s not a badge of honor to stay in a community where you are not happy. This leads easily to the next question…

What makes you happy?

If we take the answers you worked on earlier (you did work on them right?) then now you need pick them back up. An important part of any community is evaluating how volunteers are appreciated. See how this relates to your happiness? If you know what makes you feel appreciated and fulfilled and you can define it, you’ll be much more likely to find a community which fits. What are common methods of appreciation in the workplace? Gary Chapman has written a great book on the topic, The Five Languages of Appreciation in the Workplace. Below is a quick summary. I highly recommend reading the full book as it offers a much more detailed review of each.

  1. Words of Affirmation: Uses words to to communicate a positive message to another person. Praise for accomplishments, affirmation of character, praise for personality. This affirmation can take the form of one-on-one, a group setting, and in either written or verbal format.
  2. Quality Time: Giving the person your focused attention. This means quality, focused conversations, listening to thoughts and feelings, and all without distractions or disruptions.
  3. Acts of Service: Providing assistance “What can I do to help?” Assisting someone in the way they would like things done. Be sure to ask before helping.
  4. Tangible Gifts: Physical items, could also be time off. Remember they should be something the person values.
  5. Physical Touch: Human to human contact. This is not a primary means especially in the workplace. Examples would include fist-bumps, handshakes, and high-fives.

As I mentioned, these are only brief summaries and the book provides a very good opportunity to explore the many aspects of appreciation. I want you to take a moment now and review this list. Rank them from greatest importance to those of least importance to you personally. If you know what affirmation is most fulfilling to you then you’ll be more able to recognize how to achieve personal satisfaction from a community.

Whew! Ok, enough of a side-track. Let’s get back to the issue at hand. Conflicts and resolution. First, the conflict.


Now that we have a good definition of community let’s look next at conflicts. Do you hear the word conflict and cringe? I encourage you not to feel too strongly against the idea of conflict. There are, in fact, many benefits and potential positive opportunities which arise from conflicts. We’ll start with a working definition of conflict from Merriam Webster dictionary:

“A difference that prevents agreement : disagreement between ideas, feelings, etc.”

Interestingly enough this is the third definition of conflict, the second definition also includes the idea that conflict “results in often angry argument”. This is the part most people associate with conflict. Angry argument. But I’d suggest the third definition listed above is perhaps a more practical and ideal definition. We all know conflict can be perceived as negative and I’ve already alluded to the idea of conflict avoidance. But there are benefits of conflict as well. In fact, several studies have been done on the subject of the positive benefits of conflict. According to a study, published by Ohio State University, there are a number of positive effects of conflict, including improving the quality of decisions, stimulating involvement in the discussion, and building group cohesion. Conflict is always present. It is not an obstacle to avoid but rather an obstacle to overcome. Conflict typically stems from three basic types: task conflict, interpersonal conflict, and procedural conflict.

  1. Task Conflict: Deals with disagreement about the substance of the discussion. These conflicts can result in improved decision quality. Also, a conflict based on the task can result in a better more thought-out “flow” through the decision process. This can be a positive conflict and resolution.
  2. Interpersonal Conflict: Often described as personality clash. This occurs when individuals disagree with another individual for reasons unrelated to the issue being discussed. This conflict will usually take the form of antagonistic remarks against personal characteristics of another person.
  3. Procedural Conflict: This conflict results when there is a disagreement over the procedures followed to accomplish a goal of the community. This conflict can be a positive form of conflict as it can lead to new procedures being formed and even possibly new goals being defined.
“Peace is not the absence of conflict but the presence of creative alternatives for responding to conflict- alternatives to passive or aggressive responses, alternatives to violence.” — Dorothy Thompson

What can we conclude from this list of conflict types?

First, conflicts are not always bad. Conflicts stem from a variety of reasons and many of them are extremely beneficial for the good of the community. They are not something to be avoided but rather taken as opportunities to improve the community. New tasks, new decision processes, new procedures, and new goals are all possible successes which can result from positively handled conflicts. Second, conflicts are not always resolvable. We’ll discuss the process of conflict resolution in more detail next. However, not every conflict can be easily handled or resolved positively. In particular, interpersonal conflicts can rarely be easily resolved as personal character qualities and preferences heavily influence our opinions and beliefs about other individuals. If a conflict is not resolvable then you need to learn how to best deal with these conflicts as appropriate for the community.


Ah, we’ve made it through the tougher part. We can now talk about the resolution to conflict. There are a number of steps resolved in proper conflict resolution and according to the study mentioned earlier we’ll discuss each step.

  1. Recognize and acknowledge existence of conflicts
    This seems basic right? Obviously we can always tell when conflicts exist; ok, maybe not always. Sometimes recognizing conflict is more difficult then you may admit. Identifying not only that conflict exists but also the type of conflict (see above) and then being willing to acknowledge that the conflict exists. If you don’t recognize a conflict then clearly you can’t resolve it.
  2. Analyze the existing situation
    Once you’ve recognized and acknowledged the existence of the conflict you need to analyze the situation. What is the current situation? How severe is the conflict? What are the possible outcomes and what are some worst-case scenarios? This is not a step to skip. Before being able to properly resolve a conflict you need to be able to step back and look at the entire situation.
  3. Encourage communication
    Here’s where it starts to get a little more intensive. This point in conflict resolution is where passions start to get involved, tempers have the greatest chance of flaring and resolution becomes more difficult. But communication cannot be and should not be avoided. Here’s some items to attend to while encouraging positive and constructive communication.
    — Free discussion
    — Encourage accurate communication
    — Listen and raise questions
    — Allow free expression
    — Supply relevant information and facts
    — Maintain objectivity (no emotional pleas)
    — Focus on the issue and not people
    — Be gracious when successful

This great list can be found in the same study shared earlier and listed in the footnotes below. I cannot stress enough the importance of each of these items. This is the crux of the entire resolution process. If you are not careful to actively pursue each of these items during the communication phase the entire process will stall. Communication will break down, and conflicts will abound without resolution.

Summary: Properly encouraged conversation involves free discussion related to the accurate and relevant information shared tactfully and without personal bias.

The outcome

Once these steps have been taken there is a simple plan to reach a resolution. Discuss the options (this is done mainly through the communication step previously), analyze the options, negotiate a resolution based on the facts, make adjustments, and lastly, live with the outcome of the resolution. Not every outcome is a clear “win” for one side of a debate. Most often you’ll find a blended result to be the negotiated result. I would suggest there are in fact, three possible outcomes which can result from successful conflict resolution.

  1. Compromise with a full agreement
    This is the ideal outcome. In this outcome both parties agree completely with the result and both sides believe the resolution to be the best and most successful resolution to the conflict.
  2. Compromise with partial agreement
    This is a second often experienced outcome. In this outcome one party (or both) will make concessions to reach an acceptable resolution, these concessions may cause them to not fully agree with the resolution and yet, as a result of successful communication are able to negotiate a compromise which can be partially agreed upon.
  3. Compromise with no agreement but acceptance
    This is the least desirable outcome, however still a valid resolution to conflict. In this outcome one party accepts the resolution but disagrees with the result. This typically involves accepting a solution to end a conflict but stating a disagreement with it. This should be a last resort for conflict resolution and the party in disagreement must be exceptionally careful to not allow the disagreement to be overpowering of the acceptance. Again, tact and grace are desirable character qualities to exhibit.
Courage is what it takes to stand up and speak. Courage is also what it takes to sit down and listen. — Winston Churchill

Putting it all together.

I’d like to finish with three important take away points. They are quite simple: respect others, stick to the facts, and be willing to compromise. Allow me to elaborate briefly on each.

First, respect others. Be careful to debate the issues and not the person. Be respectful of others. You wouldn’t like someone attacking you in a debate; give them the same courtesy. Obey the golden rule. Remind yourself of what we looked at in the first point above — why you are volunteering? And remember, as a community we have a single common identity.

Second, don’t let your emotions control your discussion. Avoid being overly dramatic in an attempt to “win votes”. It’s hard to keep this in mind when discussing something you’re deeply passionate about. It is also hard when you must convey your thoughts on a language which is not native to you, the nuances of languages, especially English, can be a nightmare. Do your best to think through your words before speaking — choose carefully. This becomes easier when only discussing facts. State facts clearly and concisely. And then listen to others’ responses.

Lastly, work together to negotiate a solution. Compromise is often the result of debates. Don’t expect to always win everyone to your point of view. You may have times when you clearly state your facts and it is evident to all the truth in your view; more than likely some compromise will be necessary. This is not failure. You are not losing the argument to come to an agreement which involves sacrifices on both sides of an issue. See our previous point regarding the outcomes of a conflict.

About the author
David Hurley is a small-business owner with a passion for open source communities and realizing the power of people working together. He volunteers his time to a number of non-profit organizations where he seeks to enable others to become more empowered and to love what they do. You are welcome to follow him on twitter: @dbhurley or LinkedIn: /davidbhurleyor contact him through email or Google+ David Hurley

Intentionally building communities (More hallway!)
— http://sethgodin.typepad.com/seths_blog/2009/04/intentionally-building-communities.html

Conflict Management in Community Organizations

Outline of Community

The 5 Languages of Appreciation in the Workplace: Empowering Organizations by Encouraging People
 Gary Chapman http://www.appreciationatwork.com/



Lessons in Coding: Don’t Repeat Yourself


I’m a parent. That tends to sound a bit like a confession. But most people who know me also know that I love kids. I have three children right now, and hope to add more in the near future.

I’ve learned many things from being a parent. I learned there is a strange phenomenon with children where they cannot hear something they are told unless I tell them multiple times. It’s interesting because it doesn’t seem to be all the time, only certain times, and usually only those times when they need to do something they don’t particularly want to do. And I really get tired of repeating myself. It gets quite annoying after a while.

Ok, so now everyone’s wondering, what does this have to do with coding and best development practices. Today I want to talk about the principle of Don’t Repeat Yourself.


Wikipedia defines the Don’t Repeat Yourself Principle as follows:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

Let’s take that definition and break it down into some easy-to-understand pieces. And then let’s apply it to code.

Every piece of knowledge: In development that could be a class, a function, or merely even a block of code within a function.
single, unambiguous, authoritative representation: code should exist only once and it should be clearly written.
within a system: inside your component, module, plugin, application etc.

If we take those pieces and re-write the definition in our new terms it would look more like this:

Any code written and used within your component should exist in only one location and be clearly written.

That seems to make more sense. Now that we have a good working definition of what is involved in the principle of Don’t Repeat Yourself let’s look at some examples of how you would do this within your code.

Example of Bad Code

function getSingleItem($id) 
   // assume all variables needed
   $query = $this->db->getQuery(TRUE)
            ->select($this->db->quoteName(array('i.*', 'c.name', 'a.something')))
            ->from($this->db->quoteName('#__myitems', 'i'))
            ->join('LEFT', $this->db->quoteName('#__categories', 'c') . ' ON (' . 
              $this->db->quoteName('i.category_id') . ' = ' . $this->db->quoteName('c.category_id') . ')')
            ->join('LEFT', $this->db->quoteName('#__attributes', 'a') . ' ON (' .
              $this->db->quoteName('a.item_id') . ' = ' . $this->db->quoteName('i.item_id') . ')')
            ->where($this->db->quoteName('i.item_id') . ' = '. (int) $id);
   $item = $this->db->loadObject();

function getManyItems($ids) 
   // assume all variables needed 
   $query = $this->db->getQuery(TRUE) 
            ->select($this->db->quoteName(array('i.*', 'c.name', 'a.something'))) 
            ->from($this->db->quoteName('#myitems', 'i')) 
            ->join('LEFT', $this->db->quoteName('#categories', 'c') . ' ON (' . $this->db->quoteName('i.category_id') . ' = ' . 
              $this->db->quoteName('c.category_id') . ')') 
            ->join('LEFT', $this->db->quoteName('#__attributes', 'a') . ' ON (' . $this->db->quoteName('a.item_id') . ' = ' . 
              $this->db->quoteName('i.item_id') . ')') 
            ->where($this->db->quoteName('i.item_id') . ' IN '. implode(',', $ids)); 
    $item = $this->db->loadObject(); 

Does that code look similar? It should. I created the second function by copying the first function and then changing a single line. (Hint: Look at the “where” clause). So what would this code look like if I re-wrote it but did so without duplicating any lines of code? Here’s one possible example.

Example of Better Code

function getSingleItem($id) 
   // assume all variables needed 
   $query = $this->getQuery(); 
   $query->where($this->db->quoteName('i.item_id') . ' = '. (int) $id); 
   $item = $this->db->loadObject(); 

function getManyItems($ids) 
   // assume all variables needed 
   $query = $this->getQuery(); 
   $query->where($this->db->quoteName('i.item_id') . ' IN '. implode(',', $ids));
   $item = $this->db->loadObject();

function getQuery() 
   $query = $this->db->getQuery(TRUE) 
            ->select($this->db->quoteName(array('i.*', 'c.name', 'a.something'))) 
            ->from($this->db->quoteName('#myitems', 'i')) 
            ->join('LEFT', $this->db->quoteName('#categories', 'c') . ' ON (' . $this->db->quoteName('i.category_id') . ' = ' . 
              $this->db->quoteName('c.category_id') . ')') 
            ->join('LEFT', $this->db->quoteName('#__attributes', 'a') . ' ON (' . $this->db->quoteName('a.item_id') . ' = ' . 
              $this->db->quoteName('i.item_id') . ')');
   return $query;

Instead of re-writing the query function twice, once inside of each function, I have extracted the repeated code and written it as a third function which I can now call from either of the two other functions. It seems simple. In fact, many developers are probably already implementing this type of coding to make their code better.


Why is it important to not repeat yourself? There are many benefits to writing your code only once. Sure, nobody like to waste time writing code over and over again, but even more importantly you reduce the chance for bugs to occur. Less code means less chance of failure points. I am sure we’ve all had those moments when we can’t find the problem until after wasting an hour or more looking you find a missing semi-colon. I know it’s happened to me. There are other benefits too. When you later realize you need to add another table on to the query because your client needs more information from the database you only need to update one query now!

I hope many developers are already aware of this principle of Don’t Repeat Yourself. If this is a new concept, congratulations you have now learned what it means to write DRY code. I wanted to start this series with an easy topic and though this doesn’t cover every technical detail of this principle it does focus on a strong aspect of it. In the coming releases I look forward to looking at more principles of good development.