Coding Best-Practices: Building Good Habits From the Beginning

Kelsea Mcallister
4 min readNov 12, 2020

As I’m finishing my third week of bootcamp, I’ve compiled a list of some of the best-practices I’ve been trying to implement. I find it important to implement these practices into my learning processes. This ensures that you are building good habits as you are learning. It’s far more efficient to develop these habits from the beginning rather than trying to re-write and correct bad habits later on.

Most programming jobs involve working on a team of other developers. To ensure that you are a vital, contributing member of the team, it is important to follow best practices. This ensures that every developer on your team will be able to read and understand your code.

Indentation and Spacing

While one of the easiest habits to develop, this is often the most ignored. It makes complex projects feel more controlled by creating a sense of organization. Proper indentation and spacing makes it easier to read and understand your code. It can also save you time when you need to revisit or make modifications. While the specific style of indentation isn’t important, consistency is.

A style guide provides a road map which the developer should follow and implement in coding. So in a group of developers, all the code generated will be of consistent in nature and reusable by any coder/developer. — MrBool

Proper indentation and spacing makes it clear what is being executed in the block. In the example above, you can clearly see what lines of code will be executed if the conditional statement returns true. But in the example below, it is much more difficult to read what is being executed and when.

D.R.Y (Don’t Repeat Yourself)

Don’t Repeat Yourself is a principle aimed at reducing repetitive lines of code. The main purpose of DRY is to identify where you are repeating code, create a helper method to replace it, and implement that method where needed. A helper method refactors repeated code and turns it into a loop or a function. This makes it easier to change your code because now you only need to make that change in one place. This principle ultimately speeds up the development process by allowing you to call a helper function rather than re-writing the same lines. The DRY principle increases maintainability and readability.

Naming conventions

One of the simplest practices, naming conventions refers to the naming of identifiers such as variable, functions, and data types. It is best-practice to give these identifiers a name that properly describes their function or value. Many development teams and even some companies have started to establish their own set of naming conventions. This can help promote consistency and readability within a development team.

By assigning an array of movie tittles to the variable x, you are not accurately representing what the value of x is. Instead, assigning the array to the variable movies gives a clearer representation of the data. While shorter identifiers may be preferred, extremely short identifiers, like x, are hard to uniquely distinguish. Some other examples of naming conventions are snake_case, CamelCase, dash-case, Train-Case, etc. It is also important to note that many coding languages have their own set of naming conventions.

Commit

Life happens. Dead battery, blackout, software glitch, spilled cup of coffee — any of which can cause data loss. And the best way to avoid data loss is by using a version control, the most popular being Git.

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later — Git

The most useful feature of Git is — git commit. This command commits changes made to the file. It is best-practice to make small commits and make them often. The command requires you to add a message pertaining to your commit. It is best-practice to attach a message to each commit that is both detailed and short. This allows anyone to read through your commit log and see every change you made and why.

--

--