Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
asgs87832y10 maybe a little more or a little less a count to stick with. Any small "logical" unit should be a function
JKyll62742yHmmm I guess it depends, what the function is supposed to do, coding style and language.
I try to keep my functions as small as possible but my average is 13 to 16 lines, on my current project I only have two functions of around 20 lines, python makes it difficult to condense some stuff sometimes but it also makes others easier.
It also depends, are we talking about regular non class functions or class member functions? Class functions should be short and sweet but let's say a main function/proc could take more lines obviously.
I say just keep things clean, understandable and maintainable. I personally don't care if you write 30 lines as long as the code is as small and efficient as possible while ensuring I can understand what it does.
b3b347682ySometimes I have to make functions 50 lines or longer because otherwise it just doesn't work.
I usually don't think about what functions to create. I just code and then I'm like "hey this can be put in a separate function" and in the end it resolves to somewhat around 5 to 30 lines. But I don't say "this function is too long, I have to split it"
that's nonsense. line limit on a function is as arbitrary and nonsensical as a line limit on a paragraph.
they're supposed to be separated by being about different idea, not by a character count.
I should ha e phrased this as 'if a function goes above 10 lines take a good look at it and look for logical areas to break out'
@craig939393 better, but 10 lines still seems like a stupidly small number. you start getting lost in the indirection instead of in the text on the screen.
also not like i know too much about today's compiler optimization, but i shudder to imagine the stupid overhead (size, perf, complexity) of numerously more and more layers of function calls until you get to the actual functionality.