Logbook + Scratchpad

coding

In the post about warming up for coding I forgot to mention one other way to warm up that works for me, which I think is somewhat popular too: picking up some old code to refactor.

There are some aspects to refactoring that make it work as a good warm-up:

  • You know what the code is supposed to do, so you don't need to be creative (as in creating something out of thin air).
  • You have working code that you can use to check that what you change does not have any unintended effects, so you don't need to care too much about being wrong (and you can add tests to make sure you are not, which is another good warm-up itself).
  • You have a chance to try out new language features and new architectural decisions.

In summary, it's a focused effort that you can take in self-contained steps, that makes you feel better and gives you something useful too. Good before starting something more taxing.

#coding

Do you find it difficult to get started with a day of coding, or just to find inspiration to do anything at all? Two things generally work quite well for me:

  1. Write some simple code in a language I already know.
  2. Learn an advanced feature of a language I know, or a simple feature of a language I know less.

For 1) I pick a simple code exercise from any programming book, or make one up myself, and proceed to solve it entirely; the key here is that I know all the “ingredients” well, and just need to go through the motions. My go-to ones are usually Python or C exercises as simple as “sort an array” or “plot a chart with some data points”; just something to get me started with opening an IDE or vim, start typing some raw code, execute – then lather, rinse, repeat, until I'm happy with the results. It's usually a matter of minutes.

For 2) I pick a language feature I don't know too much about, a small one, and come up with an example program to make use of it. For example, it can be a Python module I do not often use, or a basic feature or module in a language I do not use every day (usually Clojure, Julia, or Prolog). The key here is to pick something easy to learn about, and make something out of it.

#coding