5 mistakes to avoid when starting a new coding project
Whether you are a beginner or an experienced developer, you still make some mistakes while starting a new project. These mistakes make it hard to figure out the problem and debug it when an error arises. Some of these mistakes could be avoided and easily rectified. Here are five basic mistakes you’re likely to make when just starting to code.
Naming the Project’s folder with spaces between the names
When it comes to naming the folder of a project, especially a Django project folder, naming a folder could be a problem it could also be the primary reason why you have an error.
When you name a folder and use spaces, it might pose a threat when you want to open the folder using your command line or terminal. This is because after a space the terminal reads it as a different command which leads to an error. There are some times when you might be lucky and it works for you, but how about times when you need to call a path in your code and the name of the folder has a space between?
Not all Operating systems or command-line applications support spaces. It also poses threats when trying to transfer the files to other computers through the command line.
You can use alternatives when you must name a folder with more than one word. You can use an underscore “_” instead to separate the words. Hyphens “-“ can also be used to separate words.
Naming the folders with names that are irrelevant to the project.
This might become an issue when you want to locate the file or folder long after you have written the code, it might be difficult to find the folder of the file later on. For example, when you name a folder or a file of a project as “burger.html” and this project has nothing to do with burgers, it might be hard for you to locate the file after a year or two of writing the code. You should name folders and files relevantly even when you can name them whatever you want.
It can also pose a problem when you work for a company and you are no longer with the company, when someone else reviews your project, it might be hard to locate a file that you named irrelevantly. It is good practice and professional to name folders appropriately.
Not closing tags immediately after they open them
Especially when you are writing HTML code or Django template block codes, it is advised that you close the tags immediately after you open them. This is to avoid forgetting to close the tag which might later cause an error, and these errors are most times difficult to locate especially when you are debugging with your eyes and not with the aid of an efficient debugging tool.
Not naming variables according to their function
Do not name variables irrelevantly too, when you name a variable, make sure the name of the variable corresponds with what the variable is supposed to do. For example, naming a variable by a name of a person unrelated to the project might cause misunderstandings later in the course of the project especially when you are working with a team. It will be difficult for other developers to know what was intended when the variable was created. Also for future use, when you read a previously written code, it might be difficult to understand what was written and why it was written.
Not adding comments to your code
A comment is a block of writing that the program doesn’t read and it doesn’t execute any function. It is used for proper documentation and understanding of the code by both the original developer of the code and anyone else who might read the code. Sometimes because of comments, it is easier to debug a code base. When the terminal outputs an error, it usually tells where the error came from at the last line of the error code, and if you understand a codebase using its comments, you can quickly locate where the error or bug is from.
There are no perfect rules to abide by while starting your programming journey, but these are some mistakes you can avoid even as a beginner. Name folders and projects correctly, name variables reasonably, close any tag as soon as you open them, and comment on your code.