Programmer's brain

Programmer’s brain

Chapter 3. How to learn programming syntax quickly

3.1. Tips for remembering syntax

3.1.1. Disruptions play havoc with your workflow

Chris Parnin, a professor at North Carolina State University, has extensively studied what happens when programmers are interrupted at work … The study showed that it typically takes about a quarter of an hour to get back to editing code after an interruption. When interrupted during an edit of a method, programmers were able to resume their work in less than a minute in only 10% of cases.

(몇 가지 습관을 잘 유지하면 인터럽션을 조금 더 잘 견딜 수 있다. TDD, 유효한 상태를 유지하며 편집하기 등)

3.2. How to learn syntax quickly with flashcards

A great way to learn anything quickly, including syntax, is to use flashcards.

'''Expanding''': First, when you’re learning a new programming language, framework, or library, you can add a card each time you encounter a new concept…. A second great time to expand your set of cards is when you’re about to Google a certain concept.

(구글하는 시점에 추가하는 게 좋은 휴리스틱 같다. 왜냐하면 실제로 다시 알아야할 필요가 있는 시점이므로?)

'''Thinning''': If you get a card right a bunch of times in a row, you can discard it. Of course, if you find yourself struggling again, you can always put the card back in. If you use an app to make flashcards, the apps will typically thin the set for you by not showing you cards that you already know well.

3.3. How to not forget things

The decay for LTM is not seconds, like that of the STM, but it is still a lot shorter than you might think. The forgetting curve is illustrated in figure 3.2. As you can see, in an hour you will typically already have lost half of what you read. After two days, just 25% of what you learned remains.

… Hermann Ebbinghaus was a German philosopher and psychologist who became interested in studying the capabilities of the human mind in the 1870s…. A recent study by Dutch professor Jaap Murre of the University of Amsterdam confirmed that Ebbinghaus’s formula is largely correct.

… In summary, you remember the longest if you study over a longer period. That doesn’t mean you need to spend more time studying; it means you should study at more spaced-out intervals. Revisiting your set of flashcards once a month will be enough to help your memory in the long run, and it’s also relatively doable! … The biggest takeaway from this section is that the best way science knows to prevent forgetting is to practice regularly.

3.4. How to remember syntax longer

… actively trying to remember makes memories stronger.

3.4.1. Two forms of remembering information

Robert and Elizabeth Bjork, professors of psychology at the University of California, distinguished two different mechanisms in retrieving information from LTM: storage strength and retrieval strength.

  • '''Storage strength''' indicates how well something is stored in LTM. The more you study something, the stronger the memory of it is, until it becomes virtually impossible to forget it.
  • '''Retrieval strength''': indicates how easy it is to remember something.

… It is generally agreed that storage strength can only increase—recent research indicates that people never really forget memories - and that it is the retrieval strength of memories that decays over the years.

When you repeatedly study some piece of information, you strengthen the storage strength of that fact. When you try to remember a fact that you know you know, without extra study, you improve retrieval strength ability.

3.4.2. Just seeing information is not enough

3.4.3. Remembering information strengthens memories

… when you actively try to recall information without additional study, you will remember more of what you learned.

… The fact that we do not remember syntax, of course, leads to a vicious cycle. Because we don’t remember it, we need to look it up. But because we keep looking it up instead of trying to remember it, we never improve the retrieval strength of these programming concepts—so we must keep looking them up, ad infinitum.

So next time you’re about to Google something, it might be worth first actively trying to remember the syntax. Even though it might not work that time, the act of trying to remember can strengthen your memory and might help you remember next time. If that doesn’t work, make a flashcard and actively practice.

3.4.4. Strengthen memories by actively thinking

There is a second way you can strengthen memories: by actively thinking about and reflecting on the information. The process of thinking about information you just learned is called '''elaboration'''. Elaboration works especially well for learning complex programming concepts.

Schema:

Information that fits an existing schema better will be easier to remember…. If I ask you to remember 1, 3, 15, 127, 63, and 31, that may be easier to do. If you think about it for a little bit, you can see that these numbers fit into a category of numbers: numbers that, when transformed into a binary representation, consist of only ones

Chapter summary

  • It’s important to know quite a bit of syntax by heart because more syntax knowledge will ease chunking. Also, looking up syntax can interrupt your work.
  • You can use flashcards to practice and remember new syntax, with a prompt on one side and code on the other side.
  • It’s important to practice new information regularly to fight memory decay.
  • The best kind of practice is retrieval practice, where you try to remember information before looking it up.
  • To maximize the amount of knowledge you remember, spread your practice over time.
  • Information in your LTM is stored as a connected network of related facts.
  • Active elaboration of new information helps strengthen the network of memories the new memory will connect to, easing retrieval.

Chapter 4. How to read complex code

4.1. Why it’s hard to understand complex code

4.1.1. What’s the difference between working memory and STM?

Definition:

Some people use working memory as a synonym for STM, and you might have seen the two terms used interchangeably. Others, however, distinguish between the two concepts, and we will do that in this book. The role of the STM is to remember information. The role of the working memory, on the other hand, is to process information.

The definition of working memory that we will use in the remainder of this book is “STM applied to a problem.”

Cognitive load:

Like the STM, the working memory is only capable of processing two to six things at a time. In the context of working memory, this capacity is known as the cognitive load . When you are trying to solve a problem that involves too many elements that cannot be divided efficiently into chunks, your working memory will become “overloaded.”

4.1.2. Types of cognitive load as they relate to programming

  • '''Intrinsic load''': How complex the problem is in itself.
  • '''Extraneous load''': What outside distractions add to the problem.
  • '''Germane load''': Cognitive load created by having to store your thought to LTM.

4.2. Techniques to reduce cognitive load

4.2.1. Refactoring

Cognitive refactoring:

In most cases, refactoring is done to make it easier to maintain the resulting code…. But code that is more maintainable overall is not always more readable now…. Therefore, sometimes you might want to refactor code not to make it more maintainable in the long run but more readable for you at that point in time. We define such a refactoring as a cognitive refactoring. A cognitive refactoring is a change to a code base that does not change its external behavior, similar to a regular refactoring. However, '''the goal of a cognitive refactoring is not to make the code more maintainable, but to make it more readable for the current reader at the current point in time.'''

Inlining:

Inlining the method lowers your extraneous cognitive load and might help you comprehend the code that calls the method.

4.2.2. Replacing unfamiliar language constructs

While the precise language constructs you might want to replace are, of course, dependent on your own prior knowledge, there typically are two reasons to replace code to lower your cognitive load:

  • first because these constructs are known to be confusing, and
  • second because they have a clear equivalent that is more basic.

4.2.3. Code synonyms are great additions to a flashcard deck

… you can have the vanilla code on one side, and on the other the equivalent code using the advanced concept, such as a ternary or lambda.

4.3. Memory aids to use when your working memory is overloaded

4.3.1. Creating a dependency graph

4.3.2. Using a state table

4.3.3. Combining dependency graphs and state tables

5. Reaching a deeper understanding of code

This chapter covers

  • Examining the different roles that variables can play in programs
  • Comparing surface knowledge of code and understanding of the intent of the creator
  • Comparing reading and learning natural language to reading and learning code
  • Exploring different strategies to gain a deeper understanding of code

5.1. Roles of variables framework

See Roles of variables framework

5.2. Roles and paradigms

Roles are not restricted to a specific programming paradigm, but they occur in all paradigms.

5.2.1. Benefits of roles

5.2.2. Hungarian notation

Encoding types in a variable’s name like this is thus not common practice anymore, and today the use of Hungarian notation is generally frowned upon.

… However, simply encoding types in variable names is in fact not what Simonyi proposes in his thesis. Encoding the types of variables in their names is what we now call '''systems Hungarian notation'''.

… Simonyi’s proposal was far more semantic in nature. Today, it’s referred to as '''Apps Hungarian notation'''. In Apps Hungarian, prefixes have a more specific meaning than just indicating the types of variables.

5.3. Gaining a deeper knowledge of programs

We will now focus on methods to seek a deeper understanding of the code. What was the goal of its creator? What were they trying to achieve, and what decisions were made in that process?

5.3.1. Text knowledge vs. plan knowledge

See Pennington’s knowledge model

5.3.2. Different stages of program understanding

See Sillito’s stages of program understanding

2024 © ak