11 ms·
Functions should be exactly as long as they need to be to accomplish their purpose. The purpose is the important part: A function should have a concise and easi
by mildtrepidation 13y ago
Functions should be exactly as long as they need to be to accomplish their purpose. The purpose is the important part: A function should have a concise and easily-understood purpose (or very small and logically inseparable set of purposes) and, tangentially, a name that describes it well.
You can have a fairly long function that's readable and maintainable; those last two are the important part, and, to a point, they hinge more on how much work is being done than how much code it takes.
Of course, if you're just plain writing more code than is needed, that's not a problem with the function itself.
- JoeAltmaier 13y agoYes, the idea of writing straightforward code is critical. If you can do it in less lines, even at expense of speed or space, you benefit many-fold. Its easier to understand, read, explain to someone else, remember, debug, compile. The slowest processor in the system is the wetware between your ears. Funny we rarely talk of optimizing for speed or space in that engine!