1. Before sitting for coding, you must have a formal design or a napkin for the solution to be coded. Never start coding without any design unless the code is trivial.
2. Documenting good code is just as important as good knowledge of programming language. Write a brief logic for each main block of code as comments in the same source code file. It is a good idea to state the program creation and modification dates, as well as the reason for the need for modification.
3. Maintaining program versions is another important task. Some programming tools currently have built-in version management. Whenever you make any change to your program, they save their copy of the .bak file.
My approach is to maintain 3 versions of the program. Say, I have a program.c program that other project team members also use. Copy this file as program.c.old as a backup and create another copy as program.c.wrk where I am making modifications. When modifications are successfully compiled, replace program.c with an .wrk file.
You can also append a date or caption to program versions such as program260505.c or programReadFnWrking.c.
4. If your project contains multiple source files, be sure to specify the purpose of the README file for all source files, data files, and intermediate log files (if any). You may also mention assembly and implementation steps.
5. I ever wondered why your IF statement is not working as it should. You might have to use an equal one ie "=" instead of "==" to check the status. A good approach is to write a condition in reverse order. Therefore, your condition should read something like this:
If (10 == i) …. So, if I accidentally put one equal sign, it will only be detected at compile time as an error.
6. While using the loops and conditional statements, always put the first clamps on the corresponding opening calendars and then write the internal statements, i.e.
1) for (int i = 0; i <10; i ++)
4) printf ("i =% dn", i);
The numbers at the beginning of each line indicate the sequence of the writing loop symbol.
7. Avoid using magic numbers. For example, instead of writing
circleArea = 3.14 * Prisoners (radius, 2);
Use the following code:
#define PI 3.14
circleArea = PI * pow (radius, 2);
8. Use variable names with a meaningful function. For example instead of using 'use' radius' to represent a circle radius. Likewise, the job name's area account is better than any hidden short name. In a hurry, we may use the names of the short variables, but the time saved provides a loss of time later when you guess the meaning of this short variable name.
9. It is usually a good practice to use print expressions for poster correction. But removing them when the final code is ready, sometimes, is a risky task. Therefore, perform a function that displays the debug information passed to it. When your final copy is ready, you only need to hang the interior of this function. Therefore, this requires only changes in one place.
10. Once you've finished coding, start optimizing your code. Some of the variables I mentioned earlier may not be helpful at this point. Likewise, non-ring expressions can be moved out of the ring block. Sound knowledge of the compiler can also help improve code.
11. With a good knowledge of your operating system and hardware, you can improve program performance in terms of resource requirements etc.
12. Always indent your code for clarity and readability.
13. You will also like the idea of organizing project files in different folders like SOURCE, HEADERS, MAKE, EXES etc.
14. Study the symbol written by others. This will provide you with new programming techniques and approach to the task that you coded as well.
15. Last but not least, back up your source code files so that you don't waste your effort in the event of a hard drive failure or a similar error.