Code reading means examining source code to understand both what each line does and what the program accomplishes overall. section 4.1
Use two complementary views:
- Trace variables and control flow line by line to determine exactly what happens as the program runs. section 4.1
- Zoom out to identify the program’s overall purpose and how its parts work together. section 4.1
Reading a Scrabble function
A best_word function starts with an empty result and zero points, loops through a word list, scores each word, replaces the current best when needed, and returns the highest-scoring word. section 4.1
Reading code also supports debugging: when testing reveals an error, tracing the code can expose why it fails, even when generated fixes do not work. section 8.2
Listing 4.1 best_word function for Scrabble
def best_word(word_list):
"""
word_list is a list of words.
Return the word worth the most points.
"""
best_word = ""
best_points = 0
for word in word_list:
points = num_points(word)
if points > best_points:
best_word = word
best_points = points
return best_word
Inspect the complete best_word implementation to practice moving from individual statements to the function’s purpose. section 4.1



