This post lists the common mistakes done by the programmers at the beginners level. Most of the programmers make these common mistakes during the starting phase of their programming experience. It's divided into two sections i.e. generic mistakes and OOPS mistakes as listed below.
Generic Mistakes
Missing Break in Switch-Case Statement
Except for default at the end, the case without break leads to execution of the next case which might be dangerous in certain situations. One must always add a break at the end of every case.
Missing Closing Curly Braces
Each opening curly brace must have it's a corresponding closing curly brace. Most of the programming languages throw errors and stops the program execution in such a situation.
Using = instead of == for comparison
The operator == is being used as the comparison operator. The programmer must not use assignment i.e. = operator instead of ==. Using the assignment operator changes the value of the variable instead of performing the comparison.
Coding without Planning
One must do at least basic planning before starting writing code. A well planned and thought out code takes less time as compared to plan the code simultaneously while coding.
Lazy in code commenting
Commenting is an essential part of every code having logic. We usually remember the logic while coding and it takes time in case we visit the same code. While updating the code, proper comments help it easy to understand the previously written code.
Missing code review and formatting
Code must be reviewed on a regular basis. In several cases, it reveals issues which might not be caught while writing the code. Also, a well-formatted code is easy to understand for others.
Lacking subject research
Proper research must be done where required to cover the subject aspects very well.
Array Index validation
Several programming languages complain while accessing non-existing array indexes. Proper validation must be for the existence of the index before accessing the value.
Recursion without break
Recursion without break causes infinite code execution and burst the program at the end resulting in code exit before completing the task. It also impacts on the overall performance of the system.
Creating Infinite Loop
Similar to never-ending recursion, infinite loops also cause the program to exit after consuming all the allocated resources. One should be careful with infinite loops using while and do while loop.
Missing Initialization
Most of the programming languages expect the members and variables initialized before the code access them.
Code Consistency
The code must be consistent across the whole application to make it easy to understand and maintain. It must be an inherent need for larger applications.
Writing big Functions
The functions bigger in size are difficult to maintain and understand. It's wise to break a larger function into smaller functions to have well-defined functions with specific coverage.
Lack of Validation
Proper validations must be in the place where variables are expected to work under pre-defined constraints.
Forgetting to take code backup
One must take regular code backups to check previously written code. Using a version control system is preferred for the large code base.
Calculations Mistakes
There must not be any calculation mistakes especially in the cases where calculations are being done for scientific results or finances.
Hard-coding Passwords
The password and secure tokens must not be hard-coded in the code itself and stored separately where possible.
Wrong Comparisons
Using < instead of > and vice versa for comparisons is another common mistake that the programmers often do.
OOPS Mistakes
Public, Protected and Private difference
The programmer must be clear with the usage of Public, Protected and Private access modifiers. The private members are accessible within the class whereas protected members are available within the class and it's child classes.
Accessing Non-Static members from the static context
The object members or non-static members must not be accessed from the static code blocks.
Using == for Objects comparison
Most of the OOPS based languages provide a method to compare the objects. The class must provide the implementation to compare objects of the same class and == should be avoided for objects comparison where possible.
Missing Exception handling
The modern programming languages supporting OOPS concepts provide a robust mechanism to handle exceptions. The programmer must use exception handling where applicable and must be specific in handling exceptions instead of using the widest exception.
Tight Coupling
The tightly coupled code is difficult to maintain and extend. The code must be loosely coupled with the low dependency of classes and objects on each other. Using a depedency injection mechanism reduce coupling to some extent and make it easy to extend the code.
Low Cohesion
Low cohesion makes it difficult to write reliable code. The code must be highly cohesive with a specific goal.
Confusion with Overloading and Overriding
The programmer must not confuse with the concepts of overloading and overriding. The overriding will be the viable scenario in case of inheritance whereas overloading is required to write methods with a different signature.
Writing Class with multiple responsibilities
A class must be specific in its implementation and it must not try to do several tasks which could be done by separate classes.
Missing meaningful Class and Member name
The classes, variables, and methods must be given a meaningful name to write easy to understand