How To Avoid Writing Messy Code?
Writing code is just like writing an article. A good article are mostly written in good format, well-structure, maintainable and readable.The same, writing code is also very similar to writing an article. There are a numerous reason we can avoid from writing messy code. In this blog, I’m going to share you a few of them.
Not all the time we can ensure the code to be written in simple way. In some case, the code can be complicated even though you have optimized very well on it, but it still complicated due to it running on a very complicated logic flow. No worries, this happened in many case when we writing code, just don’t forget to leave a documentations there. So, any new developers working on the project.
Standard structure is playing a very important roles when writing program. Otherwise, you code can be very mess. You may even need to find every single files and folders to find out the related source code. Follow a style guide like airbnb style guide, be sure placing the code in the right standard, files and folders are put in well-organized way. To improve your code, you can also read about How To Avoid Writing Spaghetti Code?
Control the Size of Function
Don’t write a function that is more than 100 lines of code. It’s recommend to move the code in separate function. You can consider of breaking a big function into a few small piece function. Function should do one thing, don’t do everything in one function. It may makes the code totally not readable. You can also consider for the helper functions too.
The current source code are follow the best practices for current world. It doesn’t mean it will still apply in future, you need to keep your code up to date and follow the best practices of writing code.