A while back ago, I read a book I purchased on Amazon called the Clean Code. I learn some useful tricks, I would like to share them in this post.
The cost of maintenance cost of dirty code is greater than the cost to write clean code. If code can’t be understood, changed, and adapted, it is destined for causing high problems. Good programmers know how to write code that can be reused over and over again. For example, it is important to use meaningful names for classes, variables, namespaces, and methods. The names themselves should be able to give a good description. If the name needs to be very long, it is a sign the thing being named is doing too much on its own and should be broken up. Many times, I have spent some time thinking about a good name for a class or method. I like to name things in a way that makes it clear their purpose in relation to the rest of the program.
One of the most important parts of keeping a project clean is keeping conventions consistent across a project. if there are any patterns or conventions used in creating new names, it is important to not change. There are many different types of whitespaces used in programmings such as spaces, indentations, and newlines. Some projects use indents, others use four spaces. Personally, I prefer using four spaces because it allows a slightly greater degree of flexibility. Some IDEs will convert tabs into four spaces automatically, giving the best of both. Sometimes, programmers like to be funny and use joke names. However, this may seem like a good idea at the time of writing for the programmer, chances are it will just confuse other programmers. It is also important to spell words correctly. Many IDE’s offer spell-checking tools for names and string values to help with this.
Many projects start well but do not scale well. In my earlier days of programming, this is a mistake I made. I was so focused on implementing the next feature that I forgot about the long term development of the project as a whole. I learned through experience the importance of taking the time to make the code look neat is important for the project’s short term and long term success. It is also important to invest in a good IDE with many auto-formatting options. It can be very time consuming for a programmer to manually type everything into the computer perfectly. However, this can all be done instantly. Some developers prefer to build an entire color scheme for each new project for even cleaner code. I think this is a great idea for some companies, but many developers like to use their own personal colors, so this should be done by each individual developer, not the team as a whole.