Teach to learn

Learn to teach

Everyday is an opportunity to learn. But sometimes, it is hard to find something new to learn. When I stumbled upon PHP, I spent day and night trying to follow tutorials and build stuff. At some point I didn't know what else I could experiment with it. It's not that I knew everything about it, but I simply couldn't go beyond what I didn't know I didn't know.

It's important to keep in mind that programming is problem solving. We don't simply learn the list of functions in a language and memorize when to use them. Instead we create things the way we see fit.

But when you have found one way to do things, it is very hard to use a different method for the same scenario in the future. We are creatures of habit and usually stick to what we know.

After building a few applications, it is easy to think that our methods are the only way of doing things. But the moment you introduce someone else to your code, things break apart.

Trying to explain to someone else why you made the choices you made is surprisingly difficult. The good thing however is that as problem solvers this is just another problem to solve.

When you don't know what else to learn, find someone who wants to learn how to program and teach him or her.

Teaching is hard. Things make sense in our head, but converting ideas from electric neural signals in our brain to auditory signal in our vocal cords is a lossy data transfer.

Here is something that was nearly impossible for me to explain to my colleagues.

var allElements = document.getElementsByTagName("a"),
i,l = allElements.length,
links = [],
name = "selectable";
for (i=0;i<l;i++){
    if (allElements[i].className.indexOf(name) !== -1){

This same snippet of code can be written with less variables and fewer lines of code. I used this method to select elements by class name in JavaScript. Those new to JavaScript, would use document.getElementsByClassName() to do the same thing. I know that the method exists, but it wasn't supported in older browsers. And also, that method creates a live collection, meaning if you modify the class name of an element it gets yanked out of the Array like object. I summarize this in a single sentence, but before I wrote about it on my blog, I would have spent a good 15 minutes trying to find the right words.

Trying to teach something you already know helps you discover things you didn't know. Another example is I have used PHP for many years and even built my own web framework with it. Only a few days ago, I was trying to explain how my ORM works, I discovered that classes are passed by reference. I didn't know that and I designed my ORM to pass by reference. I would have never discovered otherwise.

Finding someone to teach is one thing. The other is just writing about it on the web. Whether it is your own blog, or on stackoverflow, it is just as rewarding. Frequently I update the code on this blog, because when I try to copy and paste it in my own projects, I find some flaws in the logic. I end up teaching myself something new by trying to teach others.

Teaching is hard, but the reward is not just to those you are trying to help. You find new challenges and new methods as you see other's perspective on your work. If you haven't already, scroll down and teach me something new on the comment section.


There are no comments added yet.

Let's hear your thoughts

For my eyes only