I've joined the Anti-IF Campaign

Saturday, 28 March 2009

Clean code and static analysis

I've been meaning to buy a copy of Uncle Bob's Clean Code for a while now, and finally did so this week. It seems like a pretty good read so far: Principled, opinionated, well-argued and right.

It has set me thinking about a possible side-project too... are there any open-source static analysis tools that specifically analyse code cleanliness? I'm imagining metrics such as longest function, mean function length, argument counts and so on. Analysing names would be difficult I guess, although incidences of one- and two- character variable names could easily be tracked, for instance. I shall do some hunting around for existing projects while pondering this some more.

1 comments:

  1. The project I'm working on does some static analysis and produces a report. It measures Cyclomatic complexity (http://en.wikipedia.org/wiki/Cyclomatic_complexity). It comes up with a magic number for each function and we try to keep that number below 10.

    Doesn't always work but it has occasionally made me re-think something and re-write the code.

    There's some other stuff that runs on Windows only and complains about things like getting the capitalisation wrong on function/variable names. It even seems to spell check as I get warnings that are not obvious - can't remember the name of the tool now. Checks our C# code.

    ReplyDelete