Low (Human) Memory Computing

Clippy

When programming, we often discuss the amount of memory a program will use, but we often ignore a much more finite resource … human memory. People can only keep a few things in our heads at once and our memories are pretty fallible. By using some tools and conventions, we can add a new member to our dev teams that will let us write code faster and with fewer errors.

Strongly Type Languages

The difference between getting a lot of help from your editor/compiler and getting almost none is pretty striking. I know Javascript has a substring function, but do I want substr or substring? Saving a trip to google several times a day can really add up. Switching from Javascript to Typescript gives you a compiler and editor that will give you a smart team member. That smart team member can:

  • Tell you when your code doesn’t make sense
  • Rename functions and variables for you
  • Tell you what arguments a function takes
  • Find all the usages of a function

Typescript is the easiest jump to strong typing and a strong editor that I have seen. If you are writing something besides Javascript there are many projects that can help your computer help you get your work done. Take a look.

Destructuring/Static Imports

Java, Javascript, and Clojure all have a concept of static or destructured imports. Avoid these when programming with a low memory mind. Change your imports from:

import { x, y, z } from 'cool-library'; // Javascript
import static com.cool.Rad.*; // Java
(:require [cool.library :refer :all]) ; Clojure

to:

import * as cool from 'cool-library'; // Javascript
import static com.cool.Rad; // Java
(:require [cool.library :as cool]) ; Clojure

Now your source code will show where your code came from (either the file you’re in or another one). When you type . or / your editor can show you the other functions in the import. Chances are you are going to need more than one.

Convention Tests

When your team learns something you’ve been doing is going to cause problems, you can either do nothing, write some documention, or write a convention test. A convention test is a kind of automated test that can check your source code for issues and let you know how to fix them. Turn what your team learned into a test that will steer your developers away from issues. Here are a few examples:

  • Ban Java.util.HashMap, it can cause infinite loops
  • Always return a call to Promise.reject to avoid executing the wrong code
  • If a function has async make sure it also has await
  • Migrations need to have the initials of a DBA in the commit

Creating a set of conventions tests gives your team an extra member that has much better memory than you do.

Conclusion

Programming tools are created to help us, when using these amazing tools keep an eye out for when they can help keep your cognitive load down. You can stop remembering so many things and can focus on getting your work done.