Line count & complexity
Dave Laribee is talking about measuring line counts and code quality. He mentions that in the Ruby's community is is considered a value to express yourself in fewer lines of code.
Recently I had to do some statistics over my project, and I was astonished to discover that it was closing rapidly to the 150,000 lines of code. That made me wonder what another project line count was, I was pretty sure that it would be closer to half a million lines of code, but I was floored when I discovered that it barely reached the 30,000 lines of code.
There is no comparison between the ease of working with both projects. The bigger one is a pleasure to work with, and the smaller is just plain hard. I was the main developer of the small project, and I have learn a lot from it (what not to do :-) ).
I don't think that a lower line count is really meaningful, unless you also have the context of how it is used. Here is another example, Rhino Mocks is at about ~25,000 lines of code, most of those are tests, the core library is about 10,000 lines, but only 4,801 lines of code (vs. xml comments, etc).
To compare to that, I just check the most complex use case in my application, which is composed out of the following:
- Controller: 400
- Controller Finders: 531
- Code Behind: 479
- ASPX: 1,261 (roughly 500 of those are javascript)
So a bit over 2,600 lines of code (not including infrastructure), for a single use case.
It is also the Murphy Zone in the application, the one we would rather not touch (it is about five times as large as any of the other use cases), because it touches so many other things. (And naturally, we had to fix a bug there yesterday :-), not liking to touch and afraid to of touching are two different things).
So, I don't want to agree with lower LOC is a good thing, and I do want to be more expressive when I write the code. I am not sure where it puts me.
But I do know that the end result is that we want to be able to get simple code at all costs. (Not stupid code, simple code.) This means that reducing line count should be accompanied with increase in the code clarity.
At any rate, just a bit of my own experience in this debate.
Comments
I think LOC is generally a useless measure.
For example I have the habit of using left-propagating assignment all the time, which means less lines of code but seems to be less understandable to other developers.
There are other measurements that do seem to correlate with quality.
I find that cyclomatic complexity is a much more useful measurement. The CodeMetrics reflector plug-in is very useful when looking at a set of assemblies for the first time... it's the first thing I will fire up if given a project with an existing codebase to work from. It graphically shows both size and complexity by method, class, namespace and assembly... a good way to find the hotspots that are hiding the last four years of business logic requirements changes in creatively constructed switch statements... since it is a reflector plug-in, it is also useful when you don't have the source to one or more of your dependent DLLs:
http://www.codeplex.com/reflectoraddins/Wiki/View.aspx?title=CodeMetrics&referringTitle=Home
Good post, I definitely agree that LOC is not a good way of measuring complexity.
Comment preview