Someone else's code. Even worse, thousands of lines, maybe hundreds of files of other peoples code. Is there a way to methodically read and understand other peoples work, build their mental models?
In this talk I will go through techniques I have developed throughout 18 years of programming. Hopefully, you will walk away with a plan on how to approach a new code base. But even more, I hope you walk away with a feeling of curiosity, wanting to get to know your fellow programmers through their code.
3. Patricia Aas - Consultant
T
S
Programmer, Application Security
Currently : T S
Previously : Vivaldi, Cisco Systems, Knowit, Opera Software
Master in Computer Science - main language Java
Pronouns: she/her
4. - So… You Got Someone
Else’s Code?
- Before You Start
- 10 Techniques
- Excellence
@pati_gallardo
7. If you approach other people's
code wanting to learn:
You will learn
If you approach to criticize:
You will criticize
@pati_gallardo
8. “Instead of condemning people,
let’s try to understand them.
Let’s try to figure out why they do what they do.
That’s a lot more profitable and intriguing than criticism;
and it breeds sympathy, tolerance and kindness.”
Dale Carnegie, How to Win Friends & Influence People
@pati_gallardo
11. With someone else's code we are lacking
The Mental Machine
Instead what we are faced with is
Possibly hundreds or thousands of files
@pati_gallardo
12. Running code is not linear,
reading code cannot be linear
either.
Also it doesn’t scale
@pati_gallardo
22. 1. Grepping
2. Where is this button?
3. Following input events
4. What do the tests do?
5. Refactoring
6. Reading “main”
7. The graphical layout
8. Runtime Investigation
9. Reading a class
10. Retelling or Rubber Ducking@pati_gallardo
24. Grep for strings you
see
- in the GUI
- on the commandline
- in the logs
@pati_gallardo
25. 1. Grepping
2. Where is this button?
3. Following input events
4. What do the tests do?
5. Refactoring
6. Reading “main”
7. The graphical layout
8. Runtime Investigation
9. Reading a class
10. Retelling or Rubber Ducking@pati_gallardo
27. - Grep for the button text
- Find the button
- Set a breakpoint on
onClick
- Click on the button
- Look at the stack
- Traverse up the widget
hierarchy@pati_gallardo
28. 1. Grepping
2. Where is this button?
3. Following input events
4. What do the tests do?
5. Refactoring
6. Reading “main”
7. The graphical layout
8. Runtime Investigation
9. Reading a class
10. Retelling or Rubber Ducking@pati_gallardo
30. Investigating Your GUI
framework
- Trace platform events
- Look at graphics output
- Find the platform
integration architecture
@pati_gallardo
31. 1. Grepping
2. Where is this button?
3. Following input events
4. What do the tests do?
5. Refactoring
6. Reading “main”
7. The graphical layout
8. Runtime Investigation
9. Reading a class
10. Retelling or Rubber Ducking@pati_gallardo
33. Integration / System Tests
- How to run it
- Use Cases
- Write tests to drive the code
you’re looking at
- Write tests to examine your
assumptions
@pati_gallardo
34. 1. Grepping
2. Where is this button?
3. Following input events
4. What do the tests do?
5. Refactoring
6. Reading “main”
7. The graphical layout
8. Runtime Investigation
9. Reading a class
10. Retelling or Rubber Ducking@pati_gallardo
37. 1. Grepping
2. Where is this button?
3. Following input events
4. What do the tests do?
5. Refactoring
6. Reading “main”
7. The graphical layout
8. Runtime Investigation
9. Reading a class
10. Retelling or Rubber Ducking@pati_gallardo
39. What drives execution
in this code?
- Mainloop & event handling
- Read top to bottom
- Take notes & draw
- Important objects/functions
- Watch for common types
- Recurse@pati_gallardo
40. 1. Grepping
2. Where is this button?
3. Following input events
4. What do the tests do?
5. Refactoring
6. Reading “main”
7. The graphical layout
8. Runtime Investigation
9. Reading a class
10. Retelling or Rubber Ducking@pati_gallardo
42. Window Layout
- Find the Main Layout
- Find the (implicit) State
Machine
- This is what changes the
window contents
- Maps often to Use Cases
@pati_gallardo
43. 1. Grepping
2. Where is this button?
3. Following input events
4. What do the tests do?
5. Refactoring
6. Reading “main”
7. The graphical layout
8. Runtime Investigation
9. Reading a class
10. Retelling or Rubber Ducking@pati_gallardo
45. Runtime Investigation
● Synchronous: Debugger is great!
● Asynchronous: Use log to learn where to break
● “Printf debugging”
● (Profiler)
@pati_gallardo
46. Rough Outline of Architectures
- Event driven : main loop, async, event handlers
- Request handling : one thread per request - mostly
synchronous
- Command line tool : mostly synchronous, takes input,
produces output
@pati_gallardo
47. - Use the debugger to
examine state and stacks
- Read the logs to see flow
- Use the tests to drive flow
- Add logging
- Add tests and assertions
- Add a feature
@pati_gallardo
48. 1. Grepping
2. Where is this button?
3. Following input events
4. What do the tests do?
5. Refactoring
6. Reading “main”
7. The graphical layout
8. Runtime Investigation
9. Reading a class
10. Retelling or Rubber Ducking@pati_gallardo
50. - Which interfaces does it
implement?
- Who uses it and how?
- Public functions are the
“mains” of a class
(Getters don’t count)
@pati_gallardo
51. 1. Grepping
2. Where is this button?
3. Following input events
4. What do the tests do?
5. Refactoring
6. Reading “main”
7. The graphical layout
8. Runtime Investigation
9. Reading a class
10. Retelling or Rubber Ducking@pati_gallardo
56. What is the predictor of team excellence?
Google's Project Aristotle concluded:
Psychological Safety
@pati_gallardo
57. “The term is meant to suggest neither a careless sense of
permissiveness, nor an unrelentingly positive affect but,
rather, a sense of confidence that the team will not
embarrass, reject, or punish someone for speaking up.
This confidence stems from mutual respect and trust
among team members.”
Psychological Safety and Learning Behavior in Work,
Amy Edmondson
60. Great code should be personal
We want people to take pride
in their work
Learn to appreciate other
people's code
Style is individual
@pati_gallardo