Tag Archives: lines

cloc: Clock your code

Line-counting utilities are not a new thing for K.Mandla; there have been a few of these available for a while. codemetre comes to mind, as does sloccount. Even wc could fit in that category.

Here’s cloc:

2014-07-28-lv-c5551-cloc

cloc has a couple of features I like. For one, cloc can work straightaway on a compressed file. You don’t need to extract an archive before cloc does its thing; cloc will handle the decompression automatically. And if it runs into trouble, you can assert your biological superiority and tell it which decompresser to use.

cloc also has some built-in diff tools, which might not sound like a wonderful idea at first. What that means though, is that it can look for differences between versions of programs, and report on those. This might be useful if you have an axe to grind with a developer. ๐Ÿ˜ก

And cloc carries a lot of filtering options, on everything from regex strings to specific programming languages to hidden Windows files. That might have saved me a little time when counting lines in the 3.15.6 kernel, above. ๐Ÿ˜

The sad part of this little exposรฉ is that I have so very, very little coding ability that cloc (or for that matter, codemetre or sloccount) isn’t something I’ll likely use. Unless, of course, I’m counting lines of text in a smarmy blog. ^^โ€™

sloccount and sloc2html.py: Because size does matter

I’m not a coder, and I try whenever possible to repeat that, at the top of my lungs.

There are some coder’s tools that I think are nifty though. Way back in the C section we had codemetre, for checking the length and breadth of your efforts, and comparing that with the number of commented lines.

In a similar vein, here’s sloccount, which goes a step further by counting out lines of types of code, summing them across an entire project, and showing some basic analysis.

2014-04-28-6m47421-sloccount

And that’s what you get if you point it at the source for the 3.14.2 kernel. ๐Ÿ˜‰

sloccount is nifty by itself, no doubt about it. If you’re willing to make a small leap toward the graphical, sloc2html.py will — as you might expect — convert the results of sloccount into something browser-oriented.

2014-04-28-6m47421-sloc2html

This is where things start to break down, because the home page for sloccount also hosts a touched-up version of sloc2html.py, but the link to the actual python program is dead. I scraped around the internets and I think I found a reasonable facsimile thereof, here. I have no way of knowing if that’s the right one though. ๐Ÿ˜•

The problem is that, as with so many python programs I encounter, it seems that advances in python proper spawn errors in sloc2html.py, the least of which seemed to occur with Arch’s python2 in charge. What you see above is what sloc2html.py could write out, before it crashed and burned.

I think you get an idea of what it should be doing though, from the screenshot. If you are a pythonian, you might be able to get it going with version 3+, with a little effort. I lack the requisite skills for that.

Which is what I mentioned at the start of this post. Clever, aren’t I? ๐Ÿ˜‰