Programmers Brain
Programmers Brain
by Felienne Hermans
60%
Short Term Memory (STM) Long Term Memory (LTM)
RAM or a cache of our brain Hard drive of our brain
Just a few items fit in STM (<12) Can store memories for a very long time
Code Store some of the info we encounter Retrieve related knowledge (ex : keywords)
of our time
Info traveling from the STM Combined with information from
into the working memory the LTM
Why is reading unfamiliar code hard?
Working Memory (WM)
code
Processor of our brain
ad Short term memory
we re The actual “thinking” happens here
When
Time : 30 seconds
Mentally execute the code aka TRACING Size : 7 +/-2 things
How to read code better ? "More concepts, data structures and syntax you know the more
code you can easily chunk, and thus remember and process"
Write CHUNKABLE
Code
Learn programming syntax “Experts group info in logical ways
Read a.k.a chunks”
/ Hid
e / W
code
Use Flashcards Remember syntax longer exer
cises
rite
Write COMMENTS
Front : prompt Retrieval : trying to remember something
High-level comments help to
Back : corresponding knowledge Elaboration : connecting new knowledge to existing memories chunk larger pieces of code
Dependency graph
State table Roles of variables
Circle variables
Focuses on the values of variables (Sajaniemi’s framework)
Draw lines between occurrences
1 column / variable
1 line / step in the code Fixed value : value does not change after initialization
Gatherer : collects data and aggregates it
Stepper : variable stepping through a list of values
Container : holds multiple elements
Flag : has happened or is the case
Follower : keep track of a previous value
Walker : traverses a data structure (search index)
Cognitive load Most-recent holder : holds the latest value encountered
Organizer : transformed variable
Temporary : used only briefly
Capacity of our Working Memory Most-wanted holder : holds the best value found so far
Capacity : 2 to 6 "things"
"Understanding what types of information variables hold is key to being able to
reason about and make changes to code."
Inferring Visualizing
Inferring the meaning of variable names List all operations in which variables are involved
Goal of the code: what is the code trying to achieve?
(dependency graph, state table,…)
Most important lines of code
Most relevant domain concepts
Most relevant programming constructs
Questioning …
Asking ourself questions while reading code Summarizing
Help us understand the code’s goals and functionality Write a summary of code in natural language
ex : What are the 5 most central concepts of the code? Help us gain a deeper understanding of what’s happening in that code
Clear names help our LTM Snake Case -> use camel Case
Methods that do the opposite than Identifiers whose name says that they
camelCase leads to higher accuracy
LTM searches for related informations they say contain less than what the entity contains
Identifiers whose name says that they Identifiers whose name says the opposite
contain more than what the entity contains than the entity contains
LTM can store different types of memory
Procedural / Implicit Declarative / Explicit "Experts heavily rely on episodic memory when solving
How to do something Memories we are explicitly aware of
problems / rely on solutions that have previously
ex : How to run a bike Facts we can remember
worked for similar problems."
Episodic Semantic
Memories of experience Memories for meanings / concepts / facts
ex : meeting our wife / husband ex : 10 x 10 = 100
Deliberate practice : requires focused attention and is Worked examples : something like a recipe which describes in detail
conducted with the specific goal of improving performance. the steps that are needed to solve the problem.
Prepare for it
Store mental model
Apart from the code
Help your "Prospective memory" Label subgoals
Comments : excellent location to leave it Put TODO comments in the part of the code Write down small steps of a problem
Warm-up period in comprehension activities Remind you to complete / improve part of the code Use mind maps for example
Searching
Exploration ex : find a class that implements a certain interface
Browse the codebase
Get a general sense of the codebase
Limit tasks to Comprehension
Understand aspects of the code
Transcription ONE programming activity ex : summarize a specific method in natural language
Give the newcomer a clear plan
Implement it
Incrementation
Add a feature to an existing class Start with it : read code together
Creation of the plan for the feature.