Function Length
During my career, I've heard many arguments about how long a function should be. This is a proxy for the more important question - when should we enclose code in its own function? Some of these guidelines were based on length, such as functions should be no larger than fit on a screen [1]. Some were based on reuse - any code used more than once should be put in its own function, but code only used once should be left inline. The argument that makes most sense to me, however, is the separation between intention and implementation. If you have to spend effort into looking at a fragment of code to figure out what it's doing, then you should extract it into a function and name the function after that “what”. That way when you read it again, the purpose of the function leaps right out at you, and most of the time you won't need to care about how the function fulfills its purpose - which is the body of the function. Once I accepted this principle, I developed a habit of writing very small fu
Function Length 30 November 2016 Martin Fowler metrics programming style During my career, I've heard many arguments about how long a function should be. This is a proxy for the more important question - when should we enclose code in its own function? Some of these guidelines were based on length, such as functions should be no larger than fit on a screen 1 . Some were based on reuse - any code used more than once should be put in its own function, but code only used once should be left inline. The argument that makes most sense to me, however, is the separation between intention and implemen
saved by
related reading
- Cognitive load is what mattersminds.md
- Essays on programming I think about a lot | benkuhn.netbenkuhn.net
- A half-hour to learn Rustfasterthanli.me
- Some thoughts on writingdanluu.com
- Write code that is easy to delete, not easy to... — programming is terribleprogrammingisterrible.com
- How to write the perfect functionyoutube.com
- how I think when I think about programming - alice mazalicemaz.com
- What is good code? (part 2)loup-vaillant.fr
- Repeat yourself, do more than one thing, and... — programming is terribleprogrammingisterrible.com
- Long Names Are Long - journal.stuffwithstuff.comjournal.stuffwithstuff.com
- Things unlearnedscattered-thoughts.net
- Ninja codejavascript.info