In the programming world, the development of understandable and efficient functions is essential for the quality and maintenance of the code. This second article explores three other fundamental principles that guide function creation, highlighting the importance of limiting each function to a single task and creating short, self-explanatory functions, updating clarifying, reducing maintenance effort, and increasing code efficiency.
Function Singularity
Functions that perform more than one task generate greater difficulties when requiring maintenance, because they are more prone to errors and are less understandable. Functions that perform only one task make code easier to read, understand and maintain, because since code tasks are separated and isolated into different functions, we can solve potential problems separately.
Function size limitation
Smaller functions with at least 20 lines avoid excessive complexity, maintaining simplicity in reading and understanding for other programmers, which also generates greater efficiency in maintenance, and in addition make more profitable use of abstractions.
Consistency in Abstraction
Abstractions have demonstrated some advantages such as more concise unit tests, shorter and simpler to understand codes and greater efficiency in solving isolated problems. To achieve better performance in abstractions, we need to keep them to a single level of code, avoiding the inclusion of irrelevant details, ensuring that each function solves a specific problem.
Conclusion
By following these principles, programmers can develop more optimized and efficient codes, facilitating understanding both for themselves and other developers, promoting a more productive and collaborative programming environment, generating a solid foundation for project evolution.
Authors:
Daniel Pardinho - Software Developer
Robson Matheus - Software Developer
Vinicius Marcondes - Marketing and Communication
Comments