Developer vs Googler

So you google a lot while writing code or developing a piece of application and that makes you wonder whether you really are a good programmer or just a good googler? Lets find out.

This thought has been bugging me for the last few months since it seems like I cant really do anything without the help from the mighty ‘G’. Whether its a simple JavaScript String.ReplaceAll() method or a C# String.ReplaceFirst() method. Lets see what most of us (considering a developer of average skills) will come up with, without googling:


//C# ReplaceFirst(): Replaces the first occurrence of a given pattern with another
public string ReplaceFirst(string baseText, string toSearch, string toReplace) {
    int pos = baseText.IndexOf(toSearch);
    if (pos < 0) {
        return baseText;
    }
    return baseText.Substring(0, pos) + toReplace + baseText.Substring(pos + toSearch.Length);
}

//JavaScript ReplaceAll(): Replaces all instances of a given pattern from a string
function ReplaceAll(toSearch, toReplace, baseText) {
    while ( baseText.indexOf(toSearch) > -1) {
        baseText = baseText.replace(toSearch, toReplace);
    }
    return baseText;
}

Now, on first thought, my incapable mind did not event think about using RegularExpressions! If I were to google first, I could’ve done much better:


//C# ReplaceFirst(): Replaces the first occurrence of a given pattern with another
public string ReplaceFirst(string baseText, string toSearch, string toReplace) {
    var regex = new Regex(Regex.Escape(toSearch));
    return regex.Replace(baseText, toReplace, 1);
}

//JavaScript ReplaceAll(): Replaces all instances of a given pattern from a string
function ReplaceAll(toSearch, toReplace, baseText) {
    return baseText.replace(new RegExp(toSearch, 'g'), toReplace);
}

Now that you’re thinking I must be a noob to not think about using RegularExpressions on the first place, how about we try to do this without RegularExpressions but in a super cool way?


//JavaScript ReplaceAll(): Replaces all instances of a given pattern from a string
function ReplaceAll(toSearch, toReplace, baseText) {
    return baseText.split(toSearch).join(toReplace)
}

If I had googled first, I could see all these different implementations which I would be able to use in similar scenarios in future, not just this one. These solutions might not be bulletproof but will do the job for my particular need. Also, imagine the facial expression of the developer who gets to work on this after me seeing all these elegant solutions to otherwise very simple problems.

Googling is simply not about copying code out of peoples work but also to explore the possibilities. Technology has enabled us to share and teach what we know to others who wants to know. There is nothing wrong with a bit of researching before jumping into writing codes. You’ll be surprised to see what you could learn simply by studying other peoples code and suggestions. And not all of our problems are related to programming, we also need to trouble shoot server problems, network connectivity issues, code deployments etc. All these will keep throwing different challenges to you and its not heroic to try to solve all these without any help. If you have a senior colleague or a friend or a mentor who helps you whenever you’re stuck, google does the same for you. Its true that if you’re blindly copying the code and pasting without even understanding or studying the code, than this can not be any worse for you!

How could we make the most out of googling and improve our skills at the same time?

  • Study the solutions provided by others. Compare their solutions to what you had in mind.
  • Try to learn different ways to solve a problem. Do not stop at the first solution you get.
  • Use the knowledge you’ve gained to solve other problems of the same kind.
  • Avoid copying wherever possible. Get the idea, understand the algorithm but write your own code. Nothing beats the knowledge gained by doing it yourself even though you’ve borrowed the idea off someone else.
  • If you think you can do better, contribute to the community. Take your solution to them.
  • Even if you think you know the solution to a problem, studying always helps. With the always changing technologies, chances are you’ll find a better solution each time you look!

So folks, don’t worry about how you code as long as you get to learn something in the process. Its okay to not know something and its a lot better than knowing the wrong thing.