Code Movement

Chunking

The human brain is capable of thinking about seven things on average. On a good day nine things, and on a less good day where you may not have gotten enough sleep, five. This psychological process is called chunking.

In the context of adding new code to an app, if we have only so much mental capacity, it is important that we offload as much as possible to our tools, so that we can focus more on the new code being created. With the basics covered we can have more consideration towards ensuring our code is useful, usable, and used by our users.

In order to make my life easier when working on this website I set up husky. Husky creates a pre-commit hook for you so that whenever you push your code to the git repository, it will run a set of commands. In my case I have it run eslint to check for errors in the code, reformat my code using prettier, and then run the test suite to ensure none of the previous tests were broken by the new piece of code added.

One of the key benefits of this process is that anyone else that were to work on this application would also being pushing the new code to github. I would not even need to inform them of the steps that would occur. Of course it would be good to point out, so that they know what to expect, but you wouldn’t have to, and as a result there is no additional load to your mental capacity.

Kent Beck said…

“for each desired change, make the change easy (warning: this may be hard), then make the easy change”

The time spent setting this up did take some time reading through the documentation, and ensuring everything was plugged in correctly. After that though, every bit of added code will reap the same rewards, with no more effort. If you work on an application with a complex build process that you have to go through each time you deploy your application or push new code, see if there are ways you can simplify it. Focus on the 20% that causes 80% of the energy drain of the developers.

Make adding new code easy. Then add the new code. This is chunking.

Links to the tools:

  • husky allows you to run commands before each commit
  • prettier.js formats your code for you, with no need to discuss style in code review, and it saves you time and energy.
  • eslint finds and fix problems in your JavaScript code
  • jest is a testing framework designed to ensure correctness of any JavaScript codebase.
  • cypress - for ensuring your web application works on the browsers your users will be using with excellent crossbrowser support