Programming isn’t all about coding. Designing and Error-checking are also important in developing a program. These are some simple tips to help you make a program.
- Design – Many programmers skips this step, so they usually lost their way in the middle of coding. In this step, you are forced to predict what changes that might apply to your program later, so you can commence update without having to re-construct all the program.
- Determine what the purpose of your program is. For example: You are assigned to make a image processor, or a e-commerce website
- Determine what features your program should have based on the purpose. For example: Image processor will be able to draw polygons, ellipses, etc; e-commerce website will be able to show the photos, prices, discounts, etc.
- Draw a flowchart of your program. This is to guide you during coding.
- If necessary, draw the Class Diagram for Object-Oriented Programming.
- Pay attention to indentations and white spaces. Use right indentations to help you see which code is within which one. White spaces are necessary so that you won’t be confused when reading a long formula (e.g. a = b + c is better than a=b+c). Also give adequate line breaks between lines of different purposes.
- Avoid copying code too frequently. It won’t only destroy your indentations, but also shows that your code contains redundant data, or you might not really understand what you are copying.
- Pay attention to variable, function, class(if any), file, and folder names. Use a meaningful name for each of your variable, so that you can understand their own purposes easily. Don’t let yourself think “what is this variable for?”. Use a standard function and class name for each of your functions and classes. Standards are different depending to programming language you use.
- If you feel some functions or variables are hard to understand, give them comments to help people(including you) to understand it.
- A file containing too many lines of code are usually harder to read, since you have to scroll up and down very often. Split your code into several files, and group them in folders.
- if you’re updating the codes, it is better that you keep the stable one as a backup first.
- If a syntax error happens, read what kind of error it is and at what place it occurs. Check at the place, and fix it depending on what kind of error it is. Good text editor or IDE will help you throughout this easily.
- If a logic error happens(there is a result, but not the right one), trace it carefully step by step at the place you think it might occur. This kind of error is the most exhausting to detect, since the compiler or interpreter won’t show any clue. Even an expert will take some time to detect this kind of error.
- Add some error-checking functions to your code to prevent the program stops responding although an error happens.
- Most importantly, learn from your mistakes and try not to make a same one next time.
If you have applied these steps well, other people will also be much easier to help you.
Happy programming ^^