Reading Code vs Writing Code

It’s an attractive theory for some learners to “learn by reverse engineering”. Anecdotally we have seen consistently over the years that this is not very effective, but I wanted to see what the research says.

Unfortunately, the strategy of “learning by primarily reading” isn’t well studied. Most studies involve university students and programming learning coursework requires students to actually write code. So, I’m left pulling relevant pieces out of related studies.

Hopefully, this summary of various research is useful to learners on the forum.

Pedagogy in teaching Computer Science

The tension between exploratory (constructivist), making (constructionist) and direct teaching needs to be quickly addressed. Teachers are currently presented with a plethora of educational technology resources that lack pedagogical instruction. Research with university students indicates that targeted pedagogies teaching specific skills such as tracing code and subgoal modelling are essential to successful programming learning. Emerging research with school aged pupils indicates that a blended pedagogy, including guided exploration, targeted tasks and creative open problem solving provides a more effective learning scenario. However, these indications need to be verified in UK school settings in rigorous studies.

I think the big picture here is important. They do not have conclusive evidence on what is the best way to learn from this metaanalysis, but they have evidence to conclude that a blend of both reading and writing, with code tracing and open ending problem solving, is important.

This is consistent with our recommendation to many learners that they should both solve coding challenges (with help as needed) and read solutions other people have written. I always recommend reading solutions after writing solution since having the answer fundamentally changes the experience of trying to write the answer.

Reading, Writing And Reversing

We investigate to what degree novice programmers manifest the ability to work with this concept of reversibility by providing them with a small piece of code and then asking them to write code that undoes the effect of that code. On testing entire cohorts of students in their first year of learning to program, we found an overwhelming majority of them could not cope with such a concept.

In this study, new learners struggled to comprehend enough of the logic to correctly reverse the logic of a small snippit of code. I think this is a negative indication for the ability of learners to be able to effectively understand more complex algorithms without better code writing and comprehension skills. In this study, learner skill in reading actually increased as they did more reading and writing.

Relationships between reading, tracing and writing skills

A correlation was also found between performance on “explain in plain English” tasks and code writing. A stepwise regression, with performance on code writing as the dependent variable, was used to construct a path diagram. The diagram suggests the possibility of a hierarchy of programming related tasks. Knowledge of programming constructs forms the bottom of the hierarchy, with “explain in English”, Parson’s puzzles, and the tracing of iterative code forming one or more intermediate levels in the hierarchy.

This paper is suggesting that code tracing is actually a higher level skill than writing code for more simple problems, which jives with my observations.

Exploratory analysis of novice students’ code explanations

We found that students prioritize the output that is generated by print-statements in a program. This is indication that these statements may have the ability to aid students make sense of code. Furthermore, students appear to be selective about which elements they find important in their explanation. Assigning variables and asking input was less often included, whereas control-flow elements, print statements and function definitions were more often included. Finally, students were easily confused or distracted by lines of code that seemed to interfere with the newly learned programming constructs.

Two things stand out to me here. print/console.log is a helpful tool, which matches my observations. Synthesizing control flow into the intent is hard, which also matches my observations.

Reading skills can predict the programming performance of novices

The results suggest that efforts to improve reading skills could have a positive impact on learning to program.

As an interesting note here - fundamental reading skills seem to be important in learning programming. This probably is not surprising to anyone? Careful reading and understanding of tasks and documentation is a common theme in our recommendations.

Overall, I think our recommendation that reading and writing code are important but separate programming skills is pretty consistent with the body of research out there. It seems to me that learners should focus on both and should not focus on one (like reading) at the expense of the other.


Thanks for your effort.

I learned for the first time that reading and writing code are very different skills, but it doesn’t surprise me.

Could this explain that you often have to dive into and review your own code that you wrote some time ago to understand it again?

Yeah, I think that coming back and reading code you wrote several months ago definitely different than working with code that you have recently written.

For me, when I’m writing code, I hold in my mind all this context about how the logical pieces fit together, but when I read code I have to create this mental map of how the pieces fit together.

1 Like

This I have to disagree with if by “our” you mean fCC.
I have heard people say “people do not read” as an excuse for not adding more text based instructions to the projects. But many people who are successful are better readers and actively seek external reading materials. I haven’t seen any evidence in the projects so far of encouraging that behaviour. (There is no task I know of for eg that says, “we want you to learn to look stuff up”)

Maybe we should add a few?

Whilst this is evident in challenge text, we mostly keep the rule of thumb ‘people do not read’ in mind for non-challenge content.

For example:

  • Any text near a button - the button will probably be clicked anyway
  • Text relating to the “getting started” portion of challenges (e.g. how to clone/setup projects)

Essentially, we hope the freeCodeCamp UX is such that the amount of pre-typing-on-the-keyboard-to-code reading material is as minimal as possible.

I took @JeremyLT 's post as being about the pedagogy of ‘just doing’ vs ‘reading’. Currently, freeCodeCamp is heading in more of a ‘just doing’ direction with the step-based curriculum.

1 Like

Yeah, from what I’ve seen on the forum, our recommendations for intermediate learners a whole seem to generally include 1) finding and reading the documentation and 2) reading other people’s solutions to the JavaScript exercises after writing your own.

That feels separate from the course content design question of the linguistic complexity of the instructional text. As noted by one of the studies above, reading skills correlate with success in learning coding. Since we want to help everyone learn to code, it better meets our goals to keep instruction text complexity as low as we can. That way we don’t gatekeep for learners who aren’t strong with written English.

That dovetails nicely with our observations that longer instruction text tends not to be read and helps provide one contributing reason why that is the case.

1 Like

I see. This makes sense. But does it mean we shouldn’t have additional exercises (maybe a step at the end of a higher level project) that specifically tries to encourage some ‘soft skill’ like googling for a solution or reading an article etc.

But I don’t want to hijack this topic, so I’ll just learn something from what you posted and consider how it works with the curriculum in another topic perhaps.

I think its a tricky balance. Reading external resources in important, but it is hard to learn, especially if you written English skills are weak. Should we make it mandatory and tell people they cannot have a certification unless they do it? That doesn’t line up with our goals.

Sometimes we forget on the forum, but we also have the news platform, YouTube videos, and forum content providing education, in addition to the curriculum platform. Maybe this skill better fits in those contexts? I know its discussed on the forum and we have news articles about it.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.