Step 1. First, analyze the problem clearly
Step 2. The next step is to think twice about how to fix this problem
Step 3. Collect a complete set of requirements
Take the time to write down what goals the final product needs to achieve and who your user base will be. Clarity (clarity) of thought at this stage will save a lot of time in the process of further work.
Step 4. Write a detailed execution plan (or model)
- For something small and independent, it might just be a basic block diagram or a simple equation.
- For larger projects, this helps to break down the work into modules and consider the following questions:
- What task should each module perform
- How data is transferred between modules
- How data will be used in each module
- While the gathering and scheduling requirements can be tedious and far less enjoyable than diving right into the coding process, it can be even more tedious to waste time debugging your program. Take the time to properly design the flow (flow) and structure of your program first, and you may even discover better ways to accomplish this before you write the first line of code!
Step 5. Comment the code "liberally"
If you think your code might need an explanation, please comment. Each function must be preceded by 1-2 lines describing the parameters and what it returns (its result). Comments should tell you "Why" more often than "What". Don't forget to update comments when you update your code!
Step 6. Use consistent naming conventions
This will help you keep track of each type of variable, as well as what the purpose of that variable is. This means more typing than just x = a + b * c, but it will make your code much easier to debug and maintain. One of the popular conventions is Hungarian notation, where the name of a variable is prefixed with its type. For example, for integer variables, you can use intRowCounter; strings strings can use strUserName. It doesn't matter what naming convention you have, but be sure everything is consistent and that your variable names are descriptive. (See Warnings below).
Step 7. Organize your code
Use visual structures to show the structure of your code. For example, start with a block of code that is inside a conditional (if, else, …) or looping (for, while, …). Also try inserting spaces between the variable name and an operator such as addition, subtraction, multiplication, division, and even with an equal sign (myVariable = 2 + 2). And also, when the code looks more elegant visually, it is much easier to see the progress of the program at a glance. (See tips on indentation below).
Step 8. Check (test) everything
Start by testing each unit using the inputs and values you would normally expect. Then try the input, which is valid, but less frequently. This will "clean up" any hidden bugs. There is the art of testing and you will gradually build up your skills with practice. Write your tests to include the following cases.
- Extremes: Zero and beyond the expected maximum for positive numeric values, an empty string for text values, and zero for each parameter.
- Meaningless meanings. Even if you do not believe that your end user will enter nonsense, you still check your software anyway.
- Incorrect values. Use zero for the value to be used in a division operation, or a negative number when a positive is expected or when the square root will be calculated. Something that is not a number when the input data type is string and this will be parsed for a numeric value.
Step 9. Practice, practice, practice
Programming is not a stagnant discipline. There's always something new to learn, and (more importantly) always something old to retrain.
Step 10. Get ready for change
In a real production environment, requirements change. However, the clearer you are about the requirements at the beginning, and the clearer your implementation plan at the outset, the less likely it is that changes will be the result of poor planning or misunderstandings.
- You can take an active part in improving the clarity of the process by submitting the requirements documentation or your complete implementation plan before you start coding. This will help ensure that what you plan to create is actually what you are asked for.
- Structure the project as a series of stages with a demo for each block, and manage the process one stage at a time. The fewer things you have to think about at any given moment, the more likely you are to think clearly.
Step 11. Start simple and work towards the complex
When programming something complex, it helps to get the simpler blocks in place and work properly in the first place. For example, suppose you want to create an evolving shape on the screen that follows the direction of the mouse and changes shape based on the speed of the mouse.
- Start by displaying a square and make it follow the mouse; those. first of all decide to only track the movement.
- Next, make sure the size of the square is related to the speed of the mouse; those. decide to track speed-shape.
- Finally, create the actual shapes you want to work with and connect the three elements together.
- This approach is naturally associated with modular coding, where each element is in its own self-contained block. This is very useful for code reuse (for example, you just want to use mouse tracking in a new project), and makes debugging and maintenance much easier.
- Use an IDE (Integrated Development Environment). IDE (Integrated Development Environment). A good IDE will have a built-in color code editor with code hints and code completion features that make editing faster and less prone to misspellings. It is usually equipped with a debugger as well.
- Studying the source code of other programmers is a great way to improve your own skills. Develop your way through their code, step by step, working out the flow and what happens to the variables. Then try writing your own code to do the same (or even improve on it). You will quickly learn why things have to be written in a certain way, and you also pick up some great tips on how to write code efficiently.
- Ask fellow programmers to read your code. They are well aware of things that you may not have thought of before. Don't know professional programmers? Find an online forum for your chosen programming language or operating system and join the conversation.
- If you go this route, read and follow forum etiquette. There are many kind-hearted experts willing to help if you kindly ask them.
- Be polite because you are asking for a favor. Don't be discouraged if you don't get it all at once, and also don't expect them to want to revisit 10,000 lines of code. Instead, ask simple questions and post only the relevant 5-10 lines of code. You will most likely get a positive response this way.
- Before you start posting, do a little research. Your question (almost certainly) has been met, sorted out and already resolved.
- Separating (packaging) your reusable code from your specific application code over time will result in a large, debugged, reusable library filled with useful utilities. This will help you write more powerful and robust applications in less time.
- Clients and bosses are not concerned with how your program works, almost as much as they are not concerned with how well it works. Think about the main thing. Customers are smart but busy. They won't worry about what data structures you are using, but they will worry about whether it speeds up or slows down noticeably performance.
- After each larger segment of work, take a break, do something else, then review what you have written with a fresh mind. Rethink and rewrite your code to make it more efficient and elegant with less code.
- Back up your application code regularly to another hard drive or portable device. This way you will have a copy if your computer dies or becomes inaccessible. Keep at least one copy in a safe place.
- Learning sites are a great resource, too.
- Make your code look visually elegant, not because it's good, but because it makes it more readable. This is very important if you want to make changes after six months. Learn more about indenting codes at the code indenting site.
- Find an editor that uses color-coded syntax encoding. It really helps to separate comments, keywords, numbers, lines, etc.
- A good way to save your work often and keep a physically separate backup is to use a version control tool like Git or Mercurial, free hosting like GitHub or BitBucket.
- Change one item while debugging and then check your fixes before moving on to the next item.
- Double check your spelling and syntax. Even the slightest mistake can cause a lot of stress.
- Keep archival copies of your past work. Not only is this a good starting point, they can also have pieces of code that can be reused later.
- Use version control systems. Tools like CVS or SVN make it easier to track code changes and errors.
- Use a debugger tool instead of placing statements in your code to display output variables. The debugger will let you step through your code line by line so you can see what's going wrong.
- Chat with other programmers. People can often be a good source of information, especially when to start. Find out if there is a group of programmers who are meeting (locally) and join the group.
- Start small, strive for the things you are most likely to be able to accomplish, and conquer your path.
- Save your work frequently as you move forward, or you risk losing hours of work due to a computer crash or freeze. If you ignore this warning now, this is a lesson you will surely learn the hard way!
- Copying and pasting someone else's code is usually a bad habit, but using small pieces of open source code can be a good experience. Just do not completely copy the program and try to get credit for it. Do not copy code from another program unless you have permission or license permissions.
- In step 4, the Hungarian notation (prefixing the variable type) should be used with caution. This can lead to code inconsistencies when editing, or especially if transferring to another language or operating system. It is most useful in 'loosely typed' languages that do not require you to declare the type of a variable in advance.