Coding Practices

One practice I would like to start doing more often is refactoring code regularly. This involves revisiting and improving existing code as requirements change and your understanding of the problem deepens. Refactoring allows for the adaptation of code to changing requirements and improves code flexibility and maintainability. For instance, you might refactor a function that initially calculates prices with a fixed discount to one that can handle variable discounts, improving its functionality.

Conversely, something I avoid is using hard-coded numbers in my code. Hard-coded values can make the code more difficult to maintain, especially if the values need to be changed in the future. Using named constants instead of hard-coded numbers improves clarity and makes the codebase more maintainable. For example, a name like ‘TEN_PERCENT_DISCOUNT’ clearly conveys its purpose and can be easily modified if needed.

These practices are supported by principles of clean code that emphasize readability, maintainability, and collaboration among team members. It is simpler to work on someone else’s code if it is easy to understand. Clean code leads to clarity, which aids in faster development and easier debugging.

References

FreeCodeCamp. (n.d.). How to Write Clean Code – Tips and Best Practices. Retrieved from https://www.freecodecamp.org/news/how-to-write-clean-code/

Codacy. (n.d.). What Is Clean Code? A Guide to Principles and Best Practices. Retrieved from https://blog.codacy.com/what-is-clean-code

Mark, F. (2023, September 17). Writing Clean Code: Best Practices and Principles. DEV Community. Retrieved from https://dev.to/favourmark05/writing-clean-code-best-practices-and-principles-3amh

Print Friendly, PDF & Email

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *