←back to thread

-2000 Lines of code (2004)

(www.folklore.org)
513 points xeonmc | 6 comments | | HN request time: 0.709s | source | bottom
1. rossant ◴[] No.44385749[source]
I think lines of code could be an interesting and valuable metric.

If the lower (negative) score, the better (given a fixed set of features).

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” ― Antoine de Saint-Exupéry, Airman's Odyssey

replies(3): >>44385798 #>>44386761 #>>44387419 #
2. entuno ◴[] No.44385798[source]
That just encourages bad behaviour in the other direction though. A massive multi-level nested ternary on one line is usually going to be worse than a longer but clearer set of conditions. Trying to make code brief can be good, but it can often result in an unmaintainable and hard to read mess.
replies(1): >>44385983 #
3. windward ◴[] No.44385983[source]
That results in the same AST, it's not really taking anything away
4. Cthulhu_ ◴[] No.44386761[source]
You'll never get it right though. Focusing on "features per LOC" means people will write shorthand, convoluted code, pick obscure, compact languages, etc. To use an adage, if a metric becomes a target, it stops being a useful metric.
replies(1): >>44388680 #
5. sixthDot ◴[] No.44387419[source]
Halstead complexity ([0]) might interest you. It's a semi-secret sauce based on the count of operators and operands that tells you if your function is "shitty".

[0]: https://en.wikipedia.org/wiki/Halstead_complexity_measures

6. Kinrany ◴[] No.44388680[source]
An opinionated formatter plus a smart line counter fix this problem. There's still space for abuse but not enough to overshadow genuine improvements.