Skip to main content

To be a brilliant programmer means having good programming habits.

I think there should be an entire course on good programming habits. Other than learning how to code, there should be a lesson on how to code the right way. A lesson that developers should keep coming back to, to engrain good coding practices as their habits.

These lessons are best learned when you’re a newbie. But it’s also never too late to learn. Better late than never. Some lessons I have picked up along the way that are extremely important to have.

 

Be Organised

Avoid having all your code in one script or file. It may seem convenient at first, but that’s just a front. It becomes a hassle when it’s time to debug and make changes. Imagine looking for a method somewhere in a file with almost 9000+ lines of code? This can be done by having separate files based on their function. Eg. For a basic system, a file that has login functions, logout functions, sign-in functions, etc. Also, a separate folder that holds all the HTML files, one for images… I’m sure you get the gist now. It saves you time when debugging or modifying and it’s also having neat and tidy work.

Think about your code before you begin to code. It doesn’t have to be how the entire project will be developed, but just a skeleton of what it will look like. like behind the scenes. Major functions, how you’ll arrange your logic, etc.

 

Comment almost everywhere

Fill your code with comments, no matter how obvious some things may be. Future you will thank you.

Read here to find out more about commenting.

 

Loops are your friend

This is something you get better at over time and with practice, but it’s a good habit to develop. Loops take up less space of what might have otherwise been a very long block of code, literally and metaphorically. Imagine having to write individual lines to compute some logic, could be 20+ lines. This wastes your time, memory, and makes you look like a day 1 learner.

Here is an example:

fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)

 

fruit_1 = "apple"
fruit_2 = "banana"
fruit_3 = "cherry"

print(fruit_1)
print(fruit_2)
print(fruit_3)

 

The first block uses a for-loop while the second block doesn’t, yet they have the same result. They print:

apple banana cherry

The block with the for loop was less tedious to type while the other one had alot of unnecessary repetition.

 

Good Naming

Use names for your variables and methods that make sense. You may understand those short-hand names right now, but you won’t later and the other person looking at your work won’t understand them at all.

f = ["apple", "banana", "cherry"]

python variable definition

let cat = // did you mean category or cat the animal

javascript variable definition

def gqt {

} // what is gqt supposed to be

python function definition

fruits = ["apple", "banana", "cherry"]

python variable definition

let category =

def get_quantity_total {

}

Imagine someone else will read your code. That will help get your naming right.

 

Keep Learning

If you want to improve, keep learning because no one knows everything. And when you decide that you know everything, then that’s when that you probably know nothing. Read books, have personal projects, and share them on GitHub to build your resume, watch videos online, keep learning programming languages, etc.

 

Use version control

You need to be able to track your work as you keep working on it. Sometimes when building a small project, git might not be on your mind yet it is still good to have it and use it. My rule is, whenever I make progress, however small, even if it is just creating a working method, I always make a commit. Version control records changes to a file(s) over time so that you can have the option to revert to how they were at a certain point. It’s like a safety net. The version control of my choice is Git.

 

Ask for help

Don’t be an island. You can learn from your fellow developers, especially those with more experience than you. Ask them how they’d approach a problem, find out their way of thinking. Get a mentor even, preferably someone with more years experience in programming than you, and learn from them. Your peers too may know better than you do or vice versa. Human beings thrive in communities, not as individuals. The ‘brilliant loner coder’ mentality is just a thing for the movies. In real life programming is different. Programmers should learn from each other.

 

Test and debug

Test and debug your work as you build it. Don’t wait to finish everything, then debug and or test because that could take longer and you’d have built on top of existing bugs. It’s always good to progress on clean ground. When you create a method, test if it works first and try and spot bugs before progressing onto the next method.

 

Take care of yourself

Unfortunately, some programmers seem to overlook this one. Taking on more projects they can handle, coding all day well into the early hours of the morning, replacing their blood with caffeine… This leads to burn-out and it makes no sense to keep working when your body and mind can’t. You won’t even achieve the bare minimum. Work on one project at a time, get enough rest, exercise, have a social life, eat healthily, and drink 5 times more water than you do coffee.

My burnout story. How to notice it and deal with it.

 

There are so many good habits to develop as a programmer. Some you’ll discover from mistakes you’ll make, I know I did. Some you’ll learn from fellow programmers, and some you’ll read about. It’s never too late to start building them. They really are beneficial, to the growth of your skill and your career.

 

Bad practices programmers should give up.