2025-09-08
One of your most frequent tasks as a programmer is not just writing code, which we focus on in university; but also reading code.
Where are some places reading code will be important?
It helps to know about statistics and probabilistic programming before trying to sort it out (we are simulating a series of linear regressions using PyStan).
What about
There is no substitute for reading a lot of code.
AI tools can be quite helpful too, but it can take some skill to use effectively.
Djikstra: “The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise”
There isn’t always an obvious entry point, e.g. in control systems or other long-lived software (we really don’t want to be in nuclear reactor shutdown mode too much!)
Flowcharts are often seen as relics of the 80s:
But in reality, they can be very effective at tracing execution flow, or (in a business context), business process logic. The other thing to keep in mind is that you might eventually want to translate your explorations into a communique for others; diagrams and notes can be important artifacts. In some ways you need a ‘field book’ like any decent archaeologist. Unless you are the relic-stealing, Nazi-fighting variety.
Good keywords: open, error, save, load … plus program specific ones (from the domain model). So perhaps another code reading approach is, figure out the domain model. Chances are a) they are using different words than the ones you might use (Client instead of Customer) or b) there are words you haven’t seen before. Acronyms are a great example of this. Figuring out what AWT means (Abstract Windowing Toolkit) will greatly help code comprehension. What if we don’t know what “asynchronous I/O” is about?
Ignore the lower level details, and focus on the method names and signatures, class names, and so on. A good IDE will help with this. In PyCharm, for example, you can pretty quickly navigate around the source.
Someone put files in various folders for some reason. One of the challenges with code reading - and archaeology - is that you have to be careful assigning intent to actions. Think about excavating a Minoan village in Greece. You see some interesting pottery shards that seem to tie this village to Chinese traders (say). But is it really that narrative? Or is it equally likely that what you think is happening is in fact someone who dug a pit in the middle ages, and threw the pottery shards in much later?
As you move through it, write comments and fix variable names. Assumes existence of unit tests. Why?
We discussed some of our past approaches to code reading.
These do what you would expect: begin by tracing the code at a low level; begin by looking at package and file organization; or begin by picking an interesting question (where does the credit card get sent?). Researchers have shown that we do all three when it comes to understanding programs.
We broke into teams to read the code for a piece of the system, and had a group discussion about what we learned.
Showed how to construct a mental model of what is happening. Go through, look for obvious code that can be ignored, highlight things I need to lookup (IOCP?). External calls to other files - how do these things link together?
If you haven’t seen them before, you might notice new CS concepts: generators, closures, callbacks,etc

Neil Ernst ©️ 2024-5