From a novice programmer to a veteran, there are a few rules to be followed so that the code you write has a professionalism in it. These might be simple things like adding comments or using proper variable names, but following it in a systematic way will make your code more easy to develop, test, debug and deploy. These rules are applicable to any programming language and making it a habit will help you in the long run. In this post, I will explain a few rules that could be followed.
Most probably when you write a code, you will intent it to work for a long time and make periodic modifications and additions to it. In case of big projects, the development will span over years, and even after deployment, the code will be reviewed and modified to incorporate new features. Mean while you might not be the only programmer working on this project. There might be multiple programmers. So, it is always a good idea to make your code easy to understand and scalable.
Here are a few tips you could follow:
These are only the basic tips that you should start to follow consistently. Only practice can make you perfect or at least near to perfect. So code your project keeping the future also in your mind.Most probably when you write a code, you will intent it to work for a long time and make periodic modifications and additions to it. In case of big projects, the development will span over years, and even after deployment, the code will be reviewed and modified to incorporate new features. Mean while you might not be the only programmer working on this project. There might be multiple programmers. So, it is always a good idea to make your code easy to understand and scalable.
Here are a few tips you could follow:
- Before starting to code, make a blueprint. Have a complete idea of your project and the files you will require.
- When you create files, give meaningful names to it. It will help you keep track of the pages in the long run. Also organise the files into different folders like for example all configuration files in one folder, all class files in another folder etc.
- Whenever you code, give comments where ever required. You might be very well knowing what you are doing now, but the next person working on your code will not be able to catchup easily. Any may be in the long run, the comments will help you easily remember what the code does.
- Use meaningful variable names. The variable names which you use should be consistent and should in some way relate to the data stored in it. Avoid variable names like a1,a2,aa etc or other arbitrary values.
- Split your process into functions. The simple calculations or processes in your project can be written in a function and tested separately. This function can be called in your main program. This would make it easy to implement changes in the future.
- If your language support OOP (Object Oriented Programming) then use it. Create classes that can handle each section of your project. For example write a class that deals with database. All the database related functions should be defined in this class. In your project use this class to handle all database operations. This will make you code easily scalable. You would be able to make changes that effect the entire project by just changing a single file.
- Most of you would be using some IDE to write code. It will have auto code aligning functionality. Make sure to use it. If you are using a plain text editor to write your code, give special attention to code alignment. A properly indented code would be easy to read and understand.
No comments:
Post a Comment