How to reduce the cognitive load of your code
There are so many similarities between writing code and writing English.<p>- Thinking of paragraphs as functions with one purpose<p>- keeping sentences short to reduce load on working memory and increase comprehension<p>- create visual breaks to help the reader by grouping common stuff together as mini-functions<p>- reduce intimidation factor of reading by removing convoluted stuff<p>- remove cognitive noise (dead code, unnecessary comments, variables declared out of context or too soon etc.)<p>- keeping terminology consistent across the code (domain language)<p>- not using double negatives e.g a = !notLocked<p>- using automated systems to simplify expressions (e.g weird boolean conditions <a href="http:&#x2F;&#x2F;www.wolframalpha.com&#x2F;input&#x2F;?i=a+&&+b+||+c" rel="nofollow">http:&#x2F;&#x2F;www.wolframalpha.com&#x2F;input&#x2F;?i=a+&&+b+||+c</a> )<p>etc.<p>Unlike English, it is less difficult to have a program reorganize your code to make it more readable based on a set of cognitive principles.<p>But, beyond the readability and understanding of a function, we should also learn from other engineering fields. For example, system thinking helps tremendously in organizing code if the cost of refactoring code wasn&#x27;t so risky in dynamic languages.