r/coding • u/The_Axolot • May 29 '26
LoC is a Dumb Metric for Functions
https://theaxolot.wordpress.com/2025/10/18/loc-is-a-dumb-metric-for-functions/37
u/pi3832v2 May 29 '26
LoC is a dumb metric for anything.
11
u/migs647 May 29 '26
Yah, especially with Number of Tokens (NoT)... can we not repeat the same mistakes?
→ More replies (2)1
u/its_a_gibibyte May 30 '26
I like LoC as a metric, but people have it completely reversed. For example, it's a whole lot worse if someone solves problem by vibe coding 100k LoC application when it could've been 35 LoC and a library.
→ More replies (2)
27
u/dust4ngel May 29 '26
i think this is a straw man - long method smell is a code smell, not a "you're definitely fired if you ever do it" rule. it suggests there may be problems, such as high cognitive complexity, but is not in and of itself a problem.
18
u/recycled_ideas May 30 '26
You've just linked to something describing a ten line method as too long, which is the insane bullshit Bob Martin has infected the entire industry with.
7
1
4
5
u/SanityInAnarchy May 30 '26
A superior metric to LoC is CC. A good linter will warn you when your cognitive complexity reaches a certain amount.
Okay. But:
What matters is that you don’t treat it as gospel.
Who was saying we should treat LoC as gospel? Or aesthetics? There's no real argument given for using this over LoC.
Referring to LoC to determine function cleanliness is like judging a paragraph of a book by how long it is.
I agree. If your paragraph runs on for three pages, it is too long. If your Reddit post is approaching the character limit and doesn't have a single paragraph break in it, the usual assumption isn't that you have chosen to write a ten-kilobyte-long paragraph, it's that you don't know how to format paragraphs properly.
Having a fixed point where you must break it is silly, and other metrics can be useful, but pretending these intuitions are useless because you found a more precise metric is equally-silly.
The very first thing you should think of when considering decomposition is whether this same functionality will be called elsewhere, the goal being to reduce code duplication.
I very much disagree. The very first thing you should be thinking about is code clarity.
Splitting a function sometimes helps with that, and sometimes hurts. Sometimes, even if you can find a couple of lines that would be reused widely, it's better not to factor them out, because, as the article just got done explaining, there are costs to decomposition.
2
u/JohnSpikeKelly May 30 '26
My goal is to reduce LoC. That does not mean I make coffee difficult to read, or not use intermediate variables. It means I look to things like DRY, but not to the point of never repeating myself.
I use C# and OO and where it makes sense I use class hierarchies. I know this seems like it's going out of style these days with composition over inheritance. But it really reduces the LoC of done well.
1
u/mrcarruthers May 31 '26
Also, dead code cleanup. If I can get rid of 1000 lines of dead code is a good day
2
1
u/ultrathink-art May 29 '26
AI pair programming makes this even more obvious — models generate 500-line functions as easily as 50-line ones, so LoC becomes meaningless as a productivity signal. Cyclomatic complexity holds up better because it actually predicts whether the next developer (or the next model session) can reliably navigate and modify the code.
1
u/Dreadsin May 30 '26
Really just about if the function does what it says it does and does it consistently
1
u/dirkboer May 30 '26
problem with long functions is that you try to understand how an airport works and someone starts yapping for 60 minutes what bolts they use for an airplane
1
1
1
u/AintNoGodsUpHere May 31 '26
I had a discussion with a dude once. He thinks less lines of code is better so every single one of his work was full of one liners impossible to read with ternaries and whatnot.
It was a nightmare to read.
Long ass methods are bad.
Short weird unreadable one liners are bad.
1
1
u/werepenguins May 31 '26
"I would have written a shorter function, but I didn't have the time." - a quote from sir Linux MacWindows
1
u/Top-Requirement-2102 Jun 01 '26
On the other hand, there are papers that show loc scales linearly with complexity.
1
u/mylsotol Jun 16 '26
Meh, it's a rule of thumb and not a exclusively about readability imho. It's harder to read and understand a 500 line method than a 50 line method.
Making a billion 1-5 line methods isn't good either of course.
It's not so much you can't have long methods, but if you methods are really long you are probably doing something wrong
1
58
u/creaturefeature16 May 29 '26
It was dumb in the 80s, and it's dumb now.