HomePosts

Three things that made me a better programmer

Code smarter, not harder 🙌

February 21, 2020

Picture this.

You've been tasked with solving an interesting problem with the power of code. Overwhelmed with excitement, you immediately start punching away at your keyboard. You type whatever first comes to mind, not for one second losing focus on what you're doing. You're also probably thinking to yourself how your work is going to blow people's minds.

Wait until they see what I've written. Their jaws are going to drop straight to the ground marvelling at this gift from god.

You finish your work, proudly handing it over to your colleagues. But after a few moments, all you get are puzzled looks and people scratching their heads.

What went wrong?

When I first started out, I often found myself in situations similar to the one above. After being given a task my first instinct would be to code the first solution that came to mind. However, I never gave any thought to whether anyone would be able to understand what I had done.

Over time, I've learned to write code that clearly communicates to my team what my work is trying to achieve and how it is achieving it. Here are the three most important things that have helped me become a better programmer.

1. Break down the problem

"If I had an hour to solve a problem I'd spend 55 minutes thinking about the problem and five minutes thinking about solutions."

— Albert Einstein (maybe)

Whether Albert Einstein actually said that is an argument for another day, but I think the idea behind the quote itself is still important. How long you spend breaking down a problem is just as important as the execution.

Before writing any code, I begin by understanding what the problem actually is. This might involve asking relevant questions, writing down key ideas, or speaking with my team mates. Doing this helps me account for two very important things - unforeseen edge cases and ways in which the problem may evolve in the future.

Taking a step back to think about the problem and ask for further details does a world of wonders as it could highlight key ideas you may not have initially thought of.

2. Write code expecting a toddler to read it

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

— Martin Fowler

Many programmers are eager to impress others by writing overly complicated code. From personal experience however, the urge to write code in this way tends to come back and bite you in the rear.

In the past, I wrote code in this way because of my eagerness to go with the first solution that I came up with. It was easy, fun, and required the least amount of energy. Unfortunately, it wasn't the best approach for writing readable code. I've found that thinking through my solution and iterating on it helps with code readability and maintainability.

By being more mindful of how your code is laid out, you and your colleagues will be able to come back and make necessary changes more easily should the occasion arise.

3. Ask questions like a toddler

"There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand the world. There is no such thing as a dumb question"

— Carl Sagan

Two studies conducted at the University of Michigan looked into why children ask their parents so many questions - including the reason why they keep asking "why". The researchers concluded that children use the process of questioning to actively learn about the world around them.

In the past when I was confused about something, instead of simply asking for help I would spend most of the time pondering about the thing I was confused about. In truth, it didn't do me any good - I'd pretty much have to Google the answer anyway. Although some may argue that doing this shows my resourcefulness, I've found that you're able to probe further when asking a question in person. You're able to keep asking "why".

Much like children, we should always be digging into the "why" of things. Constantly asking "why"enables us to gain a deeper understanding on a subject matter. Talking with your team mates also has added benefits. It helps us gain a different perspective on things, and strengthens the trust you have with each other.

...

n brains are better than 1

These habits have helped me become a better programmer because they encourage me to be a team player. Actively communicating with your peers and building solutions together will help you grow more rapidly as a developer as it gives you exposure to all sorts of perspectives and ideas. Also, working with others is always more fun than working by yourself 😃. Keep coding smarter, not harder 🙌.