Wern Ancheta

Adventures in Web Development.

Dont Just Copy and Paste Code

| Comments

On Googling

There are times when were too lazy to think of the problem and come up with a solution. And we jump straight to Google to ask for help:

how to php

If you find yourself doing this before you even try to implement your own solution then stop. You’ll never learn by doing this. Do this only if you’re an absolute beginner and do not know the syntax or parameters used by the function that you want to use. Do this only when you need a reference if you forgot something. We really depend too much on Google that we don’t really care anymore about remembering stuff like parameters needed by the explode function in php. Or what values are returned when using array_merge or array_sort. I wouldn’t say that I’m not guilty because I also do that when I have to meet a deadline. That’s also one of the reasons why I have a blog. So that I can just Google things later on in case I forget what I have learned.

On Copy Pasting

Yes you can build a software by merely copying and pasting things here and there. Yes you can make the software work, but you can’t really say that you’ve learned anything from the experience as you have merely lumped together pieces of working code from sites like Stackoverflow or Daniweb. Yes you can hack and edit the code to make it work for you but have you really learned anything? After 2 days or 1 week could you still remember how you made it work? Or are you just going to Google it again and find the same code then copy it again?

This is what usually happens if we programmers needs to produce an output before the deadline. Or were just too lazy to figure out how things really work. Or maybe the code is way too advanced to understand that you gave up figuring out how it works before you even tried.

Some Tips for Learning How a Code Works

I’m not really one to talk because I also get lazy at times and stop before I even try. But here are some tips that might help you figure out how a code really works:

  • Break down the code – start with the bare minimum code that you can understand and incrementally build it.

  • Replicate – try to understand what the code does and replicate the code without looking at the original code.

  • Start with a blank slate – sometimes other codes that are already in the file that you’re working on can pollute your mind. Start with a blank file if you feel like you can’t concentrate at the problem on hand because of other codes that are on the file.

  • Comment – try to put some comments on each line that you understand even if its already obvious what it does.

  • Type it Out – type it out as many times as you need. Typing the code out will often lead to better understanding how the code really works.

Try not to be lazy by just merely copy and pasting code. Try to understand the code. Don’t just stop once you made a program to work. That is if you want to become a better programmer.