2024-06-08

Go katas

I’ve been working in the DevOps (sysadmin) and cybersecurity domains. That means I work with computer programs all the time and I have to understand how they work. From time to time I also write programs, like when building tools or automating tasks. But how to learn and remember a programming language if you don’t get to program every day?

There’s a similar situation in martial arts. You don’t want to be discovering and learning fighting techniques (only) in a fight. Martial arts’ solution is called kata. It’s a set of fighting techniques that are regularly practiced until internalized. Gokatas is my implementation of this idea for Go programming.

The get started install the gokatas command line tool:

❯ go install github.com/gokatas/gokatas@latest

One practice cycle has four simple steps:

  1. Choose a kata (bcounter in this case) and clone it. By default katas are shown in alphabetical order but you can sort them by number of lines.
❯ gokatas -sortby lines
❯ git clone https://github.com/gokatas/bcounter.git
❯ cd bcounter
  1. Read the documentation and code and try to understand it. You can use ChatGPT to help you out.
❯  export OPENAI_API_KEY=...
❯ gokatas -explain bcounter
  1. Delete (some of) the code and try to write it back. Check how are you doing.
❯ git diff
  1. Track your progress to stay motivated.
❯ gokatas -done bcounter -sortby last -report
Name       Description                      Lines  Done  Last done
----       -----------                      -----  ----  ---------
bcounter   io.Writer implementation         22     9x    0 days ago
findlinks  parse HTML recursively           69     3x    1 day ago
err        errors are values                48     2x    7 days ago
books      sorted table in terminal         55     8x    20 days ago
areader    io.Reader implementation         34     10x   20 days ago
clock      TCP time server                  38     7x    29 days ago
boring     concurrency patterns             190    8x    31 days ago
shop       HTTP server                      43     2x    41 days ago
shift      simple cipher                    54     3x    41 days ago
proxy      TCP middleman                    39     2x    41 days ago
parselogs  loop over JSON logs              47     2x    42 days ago
netcat     TCP client                       26     3x    42 days ago
lookup     loadbalanced STDIN processing    68     3x    42 days ago
google     building search engine           188    4x    45 days ago
findgo     walking filesystems              51     6x    45 days ago
fetch      HTTP client                      49     5x    48 days ago
dup        duplicate lines in files         30     5x    48 days ago
direction  enumerated type with iota        45     4x    49 days ago
lognb      non-blocking concurrent logging  103    7x    50 days ago

           Jul             Aug             Sep             Oct
       -   -   -   -   -   -   -   -   -   -   -   -   -   -
Mon    -   -   -   -   -   -   1   2   -   4   -   -   -   -
       -   -   -   -   -   -   -   -   -   -   -   -   1   -
Wed    -   -   -   -   -   -   2   -   -   1   -   -   -   1
       -   -   -   -   -   2   1   3   -   -   -   -   2   1
Fri    -   -   -   -   -   -   2   3   -   -   3   -   -   -
       -   -   -   -   -   3   -   -   -   -   -   -   -   -

It’s important to practice regularly because repetition creates habits, and habits are what enable mastery. Set a goal that you are able to meet and insert it into your daily routines. Start by taking baby steps. After some time it will require much less will power to practice. Your programming moves will start looking simpler and smoother. 🥋