When it comes to writing functions, there are two extremes:
In my experience, beginners tend to write really big functions, while more seasoned devs tend to break stuff up into lots of really small "pure" functions. While I think smaller, more narrowly focused functions are better for readability and maintaining code, it can also lead to code bases that are big nested dolls of functions calling functions that call other functions that call more functions. That kind of setup is in many ways harder to read and maintain than one really big function (and it's worse for performance, too). I use three basic guidelines for when to break parts of a function into separate, smaller functions…
If the answer to any of those is "yes," it's time to split at least some of the function into its own separate thing. If not, it's probably ok to keep it where it is. Like this? A Go Make Things membership is the best way to support my work and help me create more free content. Cheers, Want to share this with others or read it later? View it in a browser. |
0 Komentar untuk "[Go Make Things] How to structure functions"