In some ways, my learning started when I graduated from college. Studying computer science taught me the fundamentals of programming, but I never learned about workflow. If I could go back and tell little me a few things (about coding), here is where I would start:
Back it up!
Before you touch the code, make a copy. Especially if someone else wrote it. Your tools might crash, you might forget all the changes you made, the client won’t like your work or you could confuse yourself so much that the only way to untangle is to start fresh from your backup copy. You need an easy way to revert back to a safe point. Having an offline backup on your disk will save you lots of time and frustration. If you’re working on a website, fire up your FTP client, start downloading the site and go and get some coffee. Once you’re back, everything will be on your laptop and you can make all the changes you want. Without fear. Without regret.
Use versioning tools if possible
Even if it is a simple hackathon project or you’re just testing something, make a habit of using versioning tools. It’s a great habit to start young, like taking vitamins or using sunscreen. You’ll thank me when you’re older.
In a perfect world … use staging and production copies.
Here is an ideal workflow: you use your versioning tool and make two separate branches of code. One is for production. It has been approved and tested. The second one is called staging which you use to test, make updates, edits, etc. Once your changes are approved, you push this code to the production branch. Why is it safer? You no longer work on a live site and there is a smaller chance that something will break. It’s like varsity-level versioning.
Write lots of comments.
Try to juggle 3 or 4 large projects every week for a few months and you will realize how important it is to write comments in your code. Share your code with a team, and it will become crystal clear. Your reputation at the water cooler can be made or broken based on your approach to comments. Be a good citizen and leave meaningful clues for other developers. If you don’t know how to do it, then go ahead and find some quality code on github. Read through it a bit to get an idea what a good comment is and how to communicate your ideas.
Break down large tasks into smaller ones.
Especially when you’re fresh out of college, writing code from scratch might be intimidating. There are so many unknowns. Am I taking the right approach? Did I just break something? Will the next person who reads my code curse my name?
Break down each task to very small subtasks. Don’t try to tackle everything with one multi-purpose function that does everything. If your code is split in chunks and does one thing at a time, it will be easier for you to write and easier for someone else to understand and work on it.
The more code you write, the more patterns you will be able to find within your projects. Once you find optimal approaches to common problems, iterate on them. For example, you can create a regular expression to validate a user’s email address then reuse the code. Don’t spend hours trying to come up with another way to validate emails. Use the approach that you already know works. Then, focus your brain power on new problems.
Research new tools.
I was listening to a great programming podcast, Core Intuition, and the hosts were talking about the lowering price of being a developer. Just a few years ago, the software we use to make software was pretty expensive. You had to spend hundreds of dollars to pay for a good-quality IDE or to be able to publish for a specific platform. Right now, pretty much everything is free. Most of the web and mobile IDEs are free. Tools like GitHub or Bitbucket have free tiers and others have a very favorable pricing towards single developers. Find your workflow and try incorporating some new tools when it makes sense. Knowing how to automate your work is a huge gain in productivity and will let you focus on your code.
Ask others to review your code.
This one is tricky if you work on your own like I usually do. But even if you don’t have a dev team at your disposal, you can still ask for help or advice. Github has a great community that is dedicated to open-source code and ideas. Stack Overflow and and programming-related Slack channels or face-to-face meetups are great ways to meet other programmers who have faced similar challenges. Even if you don’t find a direct solution, it helps to know others have been through it too.
So, younger me, I hope you are a bit wiser now then you were at the beginning of the article. You may still make exactly the same mistakes, but at least I can say I told you so.