Saturday, May 3, 2014

You must have watched diving or synchronized swimming or a number of other sports, at least during an international sporting event like the Olympics. Then you must have felt like wow that particular athlete was great. When it comes to scoring, you often find that you had no clue of who was going to win.
Having a gut feeling for quality of your code could also be misleading. As a technocrat you need to quantify quality. You need to talk in terms of measurable entities. There are various metrics that can be evaluated for code - cyclomatic complexitiy, Halstead measures, lines of code, etc.
PlatoJs is a nice tool to visualize these measures on your project. Here is a snapshot:

In the above we see how broccoli has managed to make their files smaller over time. You can also drill down into individual files:

Here is a small shell script for getting reports using Plato on git repository:
pushd .
cd $1
rm -r report
for VARIABLE in $(git tag)
do
  git checkout tags/$VARIABLE
  ACTUAL=$(git log -1 --date=rfc tags/$VARIABLE | sed -n 3p | sed 's/Date:[[:blank:]]*//')
  plato -r -d report -t $1 -x .json lib/*.js
  find report/report.history.json -type f -exec sed 's/[[:alpha:]]\{3\}, [[:digit:]]\{1,2\} [[:alpha:]]\{3\} [[:digit:]]\{4\} [[:digit:]]\{2\}:[[:digit:]]\{2\}:[[:digit:]]\{2\} GMT/'"$ACTUAL"'/g' {} \; > temp
  rm report/report.history.json
  mv temp report/report.history.json
  cat report/report.history.json
done
Now from the parent folder of your repository, where you saved the script above in a file named platoIt.sh,  just run the following:

$> ls -l
total 32
drwxr-xr-x  ... broccoli
-rwxr--r--   ... platoIt.sh
$> ./platoIt.sh broccoli

And you will find the report for your project, broccoli in the above example, at broccoli/report