Most programmers today just writes code for the purpose of that moment, failing to realize that you could one day need that particular line of code, but by the time you go back to check the same line of code, its seems weird to you. Today we will be looking at the important things a good programmer needs to look out for when writing lines of code.
Code readability and re-usability is a universal, important subject in the world of computer programming. Going further we would consider such practices.
- Commenting and Documentation: Commenting and documentation is a very very important aspect of writing codes, no matter what field you find yourself, either in Web design, Application development or Android development. It makes the line of code easier to understand. Since the entire comments written would not be visible, it wouldn’t hurt anything to carefully explain what your line of code does, in order for anyone to understand what the code does. We should also try to avoid obvious comments, because comments can be useful and at the same time be redundant.
- Consistent and Proper Indentation: Indentation matters a lot when writing codes, although majority of the programming languages do not make indentation mandatory, but python programmers would say otherwise. But in general, proper indentation makes line of codes easier to read. There are three major ways of indentation, its advisable to use one style all through your project, especially when working as a team.
- Consistent Naming Scheme: Of course, their are various naming schemes, some are adopted by certain programming languages, while some programming languages are indifferent, meaning you could use any of the naming scheme, but it is advisable to use the same naming scheme all through your project.
- Avoid Deep Nesting: In some cases, their could be a number of conditions to be considered, in which case majority ends up using series of deep nesting. But it is advisable for one to avoid it as much as the person can. For the sake of readability and simplicity, you could use individual ifs instead.
- Line Limit Length: It is good practice to avoid writing long line of codes, it is advisable that when you notice that the line of code is getting long, you should break the line and continue on the next line. Some code editors usually have a vertical line indicating that you should probably break you code.
- File and Folder Organisation: Normally all files containing line of codes should be arranged properly in a folder, not scattered, this is for easy accessibility and for easy linkage.
- Function/Method Naming: Naming function or methods according to what they do is the best practice, in order to understand properly.
- Proper File/Folder Naming:Proper file and folder naming is a very important practice, name the file and folder according to what the page is all about.
- Avoid Copy and Paste: A true programmer knows sites where they would see codes to use, but a true programmer shouldn’t just copy and paste, instead you could just look at what the line of code does and re-write it, to avoid confusion. But if there is really need to copy and paste, make sure to understand every single thing the line of code does.
- Avoid Duplication: Duplication is not exactly copy and paste, although close, but duplication is more like in your own personal project, avoid duplicating, especially with functions or methods. Instead you could just make the function a global function so as to be able to call it anywhere in your program.
- Code Grouping: Like the name implies is the grouping of similar codes together.
- Dependency Injection: It comprises of two types, which includes tightly coupled and less coupled.
- Test Test Test: No amount of test is to small, ensure you test your program over and over aging to uncover any form of bugs and errors. In fact you could also get a fellow programmer to assist you with the testing, because sometimes, the error you would not see, can be seen be someone else.
Finally go out and get hobbies, don’t just be tied to your computer all day, learn new things whenever you get the chance to!!!!!!!