Writing High Quality Functions
Ever wonder how to write clean functions/methods? While searching for the answer you might have come across some metrics, stating your function should not be more than 25 lines of codes or it should not have more than 5 arguments passed to it etc. When it comes to quality, unfortunately such metric are bad indicator to measure the quality of the function. It will just trigger a flag that there is an issue, but it will not tell what the issue is. When writing a high quality function, the first and primary rule is functions should be small, it should only do one thing. Sounds like Single Responsibility Principle? (SRP) yes it is, you can apply SRP not only to class, but to functions as well and this is the only measure you can use to check if the function you have written is of high quality. FUNCTIONS SHOULD DO ONE THING. THEY SHOULD DO IT WELL. THEY SHOULD DO IT ONLY. ...