Delving into the mental labyrinth of a programmer, we explore the concept of cognitive load. Unraveling its impact on coding efficiency and quality, we illuminate the strategies to manage and mitigate this often overlooked aspect of programming.
Cognitive load refers to the total amount of mental effort being used in the working memory.
To try and reduce the cognitive load it puts on your brain as much as possible, making code easier to read will allow you to work faster and better, and also improve your mental state and mood.
Documentation
About 80-90% of comments are redundant
- Remove them to clear visual overload
- Provide something in their place
- Use proper type annotations and definitions
- Self-documenting code is better than relying on comments
- Does this comment add more information than is already available in the code?
Naming things
Give a variable a longer, descriptive name
- Short, cryptic names make sense at the moment of writing the code; but a few days after you’ve written them, they already become vague and meaningless
- Better to write a little more, than to read ten times as much
Fonts and spacing
The font you choose has a big impact on how much load is put on your brain to process the text on your screen.
- It’s not just the font, but also its size, line height, and letter spacing plays a role.
Colours
Light color schemes are better for almost everyone
- Research shows that the human eye is better equipped to read dark text on a light background
- A less bright screen in combination with a light color scheme will put less load on your eyes, which makes reading code less exhaustive
Folding
Folding your method bodies by default gives you a much clearer overview of the class when opening a file. It makes it easier to decide where you want to go to, instead of scrolling and searching.
- IntelliJ can fold code by default: Settings > Editor > General > Code Folding.