Brain Phrye

code cooking diy fiction personal photos politics reviews tools 


Gamifying tedious work

[ Listen to article ]

I’m currently implementing a client library for a REST API. There are around 150 endpoints and while I automated a lot of the code generation there’s still a lot to do.

To make that easier I decided to gamify it a bit. I wrote a little shell script to show me some progress numbers:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/bash

lines="$(wc -l ./**/*.go|tail -1|tr -dc 0-9)"
tests="$(wc -l ./**/*_test.go|tail -1|tr -dc 0-9)"
lines=$((lines - tests))

printf "Lines         :\t% 8d\n" "$lines"
printf "Lines (tests) :\t% 8d\n" "$tests"
printf "Unimplemented :\t% 8d\n" "$(cat ./**/*.go|grep -c restAuthCall)"
printf "Implemented   :\t% 8d\n" "$(cat ./**/*.go|grep -c s.restCall)"
printf "Tests         :\t% 8d\n" "$(cat ./**/*_test.go|grep -c 'func.*Test')"
printf "TODOs         :\t% 8d\n" "$(git todo|grep -c 'TODO')"
printf "curl todo     :\t% 8d\n" "$(cat ../server/routes/api/**/*.php | grep -c 'curl.*Accept.*Authorization')"

Which emits:

1
2
3
4
5
6
7
Lines         :	   10781
Lines (tests) :	    1325
Unimplemented :	     125
Implemented   :	      42
Tests         :	      76
TODOs         :	     296
curl todo     :	     127

I happily don’t have to do tedious work like this very often but this is always how I deal with it. Just write something like this, redirect the first run into a file and then compare as I go along. When you’re slogging through something like this it’s nice to have a big picture view of progress. Anything to nudge me along!

In fact it’s how I first learned how to write shell scripts. Different projects require different metrics so some of the early scripts I wrote taught me shell loops, piping from loops, etc.