7 Things I Learned That Made Me a Better Programmer

The first time I coded something in my life was at around age 8 or 9, when an old MSX computer crept into my house. It came inside a box of random crap that my brother traded for a different box of random crap.

Life Cycle of a Software Developer - TogglI’m pretty sure the MSX wasn’t inside that box by chance. My brother knew I had a thing for computers, because not only had I been snooping on his PC screen quite frequently when he was writing code, but I would also frequently sneak into his room when he was absent to subtract his programming books (but only the ones with chapters about computer games).

He then gave me the MSX along with a BASIC programming book and I proceeded to create my first ever computer program – one that would ask your name and then print it back to you.

Very useful stuff if you have some sort of extreme amnesia.

Some time later I eventually stumbled upon the concept of subroutines and found it amazing that I could reuse things I had made before. This immediately changed the way I think about programming. That moment was the first step on my journey to become a better programmer.

Since the good old MSX days I have written, deleted, and refactored countless lines of code, contributed to all sorts of small and large software projects and, from all this experience, gathered a list of good practices that could be useful for people who are just starting out.

1 – Deliver solutions, not problems

I know this sounds like cheap productivity advice but it is pretty much the reason why programmers are hired – be it in an abstract sense as in “let’s make our users lives easier” or in a more practical sense like “when I click the save button it actually kind of deletes my data instead”.

So the first advice is – be proactive.

For most software problems the computer will try to tell you what’s going on. Try to make sense of the problem before asking for help – read the screen, read the logs, try to spot something familiar on the stack trace, paste the error message on Google, use a debugger, pray.

Of course some particular problems will be too big for you to solve alone, perhaps because you don’t have the necessary technical skills yet. Or because it involves a decision that only your boss can make.

Make things easier for the next person by outlining possible solutions when you’re explaining the problem.

There’s still space for proactivity here: you can make things easier for the next person by trying to outline possible solutions when you’re explaining the problem.

2 – Test obsessively

This is an important one, perhaps the most important one of all.

It’s not only about automated testing. It is about every single effort you can make to guarantee that whatever you added to the codebase works without breaking something else.

My personal guideline here is that no change is too small to need testing. If a piece of code was changed, you should now look at it as if it was tainted. The only way to clean it is to test it all over again. Oh, and that includes dependencies.

[ctt template=”5″ link=”u8W0a” via=”no” ]”No change is too small to need testing[/ctt]

Something that can help is to ask somebody else to test your code.

At Toggl we have code reviews as a step of our workflow, where we read and test each other’s code before it goes to production. It has been vital for our QA.

It’s also had an awesome side effect – it has made onboarding of new developers easier. It forces the more experienced developers to explain the codebase peculiarities, and to make suggestions about how code can be improved to better fit the company style.

Also, remember this – if you don’t test your software, your users will.

[ctt template=”5″ link=”e8sb7″ via=”no” ]”If you don’t test your software, then your users will[/ctt]

The time and energy you need to spend on testing should be directly proportional to how angry your users will be if something goes horribly wrong.

3 – Never trust your memory

Have you ever looked at a piece of code and thought “what sort of moron wrote this piece of shit?” only to then remember it was actually yourself?

If it hasn’t happened to you yet, just you wait.

If you don’t document your code properly for the sake of other people, at least do it for yourself. By “documenting” I don’t mean writing extensive, tedious documentation on Microsoft Word that will inevitably become outdated. I mean giving things good, descriptive and concise names so that in the end you have self-documenting code that explains itself.

On top of that, I find it useful to have documentation comments summarising each logical unit of a codebase. Concise is also the way to go here. If each comment is the size of a Wikipedia page nobody is going to read them and they’ll become outdated, just like the infamous MS Word docs.

Making your code readable for the computer is easy, what’s hard is to make code readable for humans.

But it pays off in many ways – it’s more pleasant to maintain the code, bugs are easier to spot, onboarding of new developers is smoother. It’ll save time for everybody. You don’t need to go all the way into literate programming, but keep in mind that it’s much easier for everybody to read natural language than code.

Oh, and if you ever need to make a hack (please don’t make a hack) you are obliged by law (or at least should be) to add a comment explaining the monstrosity you created.

4 – Don’t try to be Superman

When I started my career as a programmer I used to think it was cool to work over hours.

I’d skip weekends and pull all-nighters as if that was a normal thing to do. I admit that in the beginning it was fun because I was eager to learn and to build things.

The problems started when I began doing that because I thought it was my responsibility to save delayed projects, one after another. It took me a long time and several different jobs to break that cycle.

Some may think that it is a pretty good deal for a company having employees who work like that, but this can turn into a huge problem. If there are heroes in the house, projects will keep being underestimated. Also, when the inevitable rage quit (or premature death by too much pizza) comes, the company is definitely screwed.

One more problem about having a crazy work schedule is that it creates the perfect environment for you to be caught in the busy trap – you’ll think you’re super busy, but your productivity is actually really low.

It is obvious that sometimes there is a legitimate necessity to pull off some extra hours to meet a deadline, but that’s perfectly fine as long as you’re smart about it and don’t let it become the rule.

Somebody much smarter than me once said that “if you don’t prioritize your life, someone else will“.

5 – Know when to stop polishing

I read a story in a neurology book about a man who had a stroke in a particular part of the brain and lost, along with his emotions, the ability to know when it was time to stop working on a task.

Yeah, weird.

Sometimes that decision is indeed beyond logic. When is it time to stop refactoring a module that is already working?

How close to the real world an abstraction needs to be?

There is no exact or formal way to answer those questions because it depends on the context.

My method for dealing with this is based both on the principle of the least effort and on what I call “guilt driven development”. If there’s a tight deadline I’ll pick the quickest solution that will not embarrass me too much when other people see it. If I do have time to do it properly, I’ll polish my code as much as I want until I’m proud of it, but will immediately stop if I start feeling guilty that I may have been sitting on that particular task for too long.

You’re not being paid to write code, but to solve problems for people

Something that can help you find the sweet spot is to always keep in mind that you’re not being paid to write code, but to solve real world problems for real people.

6 – Don’t reinvent the wheel

It is fun to write libraries and frameworks and that’s precisely the reason why you probably don’t need to create them yourself –  somebody else already had the fun of writing them for you.

What makes code mature is how many times it was tested in production and refactored to fix the bugs. When you code something from scratch, its maturity level is going to be orders of magnitude away from a well-known library. So before you start coding something, spend some seconds on Google first and make sure it doesn’t exist already.

[ctt template=”5″ link=”20c2Q” via=”no” ]”Before you start coding something, make sure it doesn’t exist already.[/ctt]

This doesn’t mean you shouldn’t know what’s going on inside the libraries you use, though.

It’s always a good idea to check who else is using it, what’s the software license, how often the authors update it. And definitely prefer open source stuff, because if something goes poorly at least you can peek under the hood, or even fix the problem yourself.

7 – Understand the tools you use

For each existing tool, there’s a problem that motivated some person to create it.

The hammer was invented because somebody wanted an easy way to perforate hard surfaces with sharp objects. You could also use that same hammer to cut down a tree, but then you’d be an idiot because it’s not the proper tool for that task. It’s the same with software.

Before adding a cool library to your project or choosing some hyped up tool, it’s important to make sure you and your team know exactly what it does,  what was the motivation behind its existence, and what are its limitations.

Apart from reading the documentation, building a proof of concept around a library is a good way to force yourself to understand what it is and how to use it. One other trick is to search the web for best practices, corner cases, and also the general experience people had when using the tool.

Being extra careful can save you from finding yourself hammering down a tree (or your computer) in the pouring rain.

Wrapping up

I’ve met many outstanding professionals in my life. All of them have one thing in common – a strong desire for self-improvement. These are people who never want to stop learning.

The good news is that it’s a contagious thing. This is why your should always try to surround yourself with people who are better than you.

The Toggl team. 


What about you? Do you have your own set of advices? Disagree with something? Leave a comment below!

By On February 28, 2017

  1. Hello. My name is Gustavo and toggl are helping a lot to control my study time and my free time. Thank you guys

  2. Here’s a piece from my experience.

    If you need an extra unit of code – add it. It’s not about what you think the next person, be it the consumer, or your fellow developer, will want to do. It’s about the principle – specifically about SRP, or SoC. you don’t have a function to group code; you have a function because it addresses a concern. So, when you see a different concern being addressed, that means it’s time to make a new unit. You may think “Oh, YAGNI!”, but it *will* bite you in the butt – maybe next month, maybe tomorrow; and when it does, you’ll regret not adding those few extra lines.

  3. These are extract of the book ‘Pragmatic Programmer’ (Hunt, Thomas) and ‘Clean Code’ (by Robert C. Martin). Don’t be surprised of such good ideas , there are plenty of posts about good programming. The difference is quote the sources. Simple.

    • Well, it has been at least 15 years since I read Pragmatic Programmer and I don’t remember a single word from it, so if these ideas are also discussed there, I wouldn’t even know which ones. But I remember being excited about that book back then, might be worth revisiting! Clean Code has been on my reading list for ages but I’ve never got to it. But thank you for the reminder, I’ll try to read it soon. 🙂

  4. Hey, I like the part about working too many hours, and I definitely recognise the whole thing in my own work. And I would like to add, that in my own experience I’ve found that too many tasks at the same time (too many context switches) can be just as big a problem as too many hours. It’s about prioritising your work and being allowed to focus on a task, if you are not allowed to focus you run the risk of making mistakes or low productivity. So what I’ve learned is when I’m in doubt about which task takes priority, ask whoever is above you, and remember to write down the other tasks for later, so you don’t waste brain time on remembering something you have to do later.

  5. On content-writing and language:
    re: “Before adding a cool library to your project or choosing some hyped up tool, it’s important to make sure you and your team know exactly WHAT IT DOES, WHAT WAS THE MOTIVATION [sic] BEHIND ITS EXISTENCE, AND WHAT ARE ITS LIMITATIONS [sic].”
    (in caps because I wasn’t able to bold or place it in italics)

    Please permit me to highlight something linguistically interesting and ask for your feedback, if you have the time/interest.
    The highlighted section is a kind of dependent clause in English which requires the subject-verb order. You adhered to this in the first item of the series (“what it does”) but not in the second two items:
    “what was the motivation…” instead of “what the motivation […] was”
    “what are its limitations” instead of “what its limitations are”.
    While I have a personal preference for maintaining the rule, I can certainly understand why you might have chosen to move the verb before the subject: the long phrase separating the two in the second item. The result is that it resembles a question, effectively reminding you that this motivation is unknown at the moment of speaking (you want people to think about the motivation for X in their future projects). It’s logical, even linguistically – other languages have features to grammatically denote just such cases of “think about X in the future, whatever that X may turn out to be”. English, however, is not one of those.
    I would like to know if this was a choice made while writing this article and its reasons. I can imagine it sounding very natural in speech, and this kind of article seems to prioritize orality.
    I understand that my question has nothing to do with writing code, although perhaps it is valuable to you and greatly appreciate your answer. As a linguist, I am observing changes in language in use. Thank you.

  6. Loved the way you used the hammer metaphor. I was picturing myself standing in the pouring rain bashing down on a tree with a hammer.