+ 9
Optimal number of lines of code of functions
My first company had the coding style document forcing to have maximum of 20 lines of code in any function. I've seen huge functions taking more than 600 lines, which obviously isn't fine in terms of code readabilty. What's your policy on that and which is the optimal number?
9 Respostas
+ 13
My company had a coding standard of 100 lines maximum. In practice, most were in the 10 to 40 range. The more important thing is the purpose of the function. A well organized code is much more important than how big a particular function is. A 100 lines that make sense together is much better than 10 that have no business being together.
+ 6
sometimes to keep the related logic at one place, bigger functions seems so compelling.
but it does creates a problem in readability.
i guess most of the times limiting factor in function sizes would be the cyclomatic complexity ( non - linear flows like if, else, switch, case, loops etc).
stackoverflow suggests keeping it less than 10 is considered Ok for any function and greater than 10 considered complex.
+ 5
Jan Markus 🤔 what if we work on the same code and our screens differ in size? 😂
+ 3
I try to stick to one single functionality and make it readable. No hard limit on lines.
+ 3
As long as you can write really UNIT test on your function it is in good shape ;)
+ 1
use like scripts
+ 1
Charan😭 That would be how to split a large function into smaller units.
- 3
John Wells vardanator
can we make small small function as packet and use it make larger program
when we need large function
we can use that
- 3
asking ,can we do that?is it good?