A few weeks ago, I posed a question on Instagram: Do you have your students comment on their program code? The response was a resounding “YES!”—a sentiment I wholeheartedly share. Commenting program code is crucial for both the programmer and anyone who reads or interacts with the code later. Let’s explore why commenting in programming is highly important.
The Programmer’s Perspective
I’ve been programming for nearly a decade. If I were to revisit code I wrote during my undergraduate years, I know I wouldn’t remember what each program was supposed to accomplish. Without comments, that old code becomes a puzzle requiring time and effort to decipher.
Commenting program code helps programmers create a record of their thought process. This practice can save hours of confusion when revisiting or revising older projects. For instance, adding a brief description of a function’s purpose or the logic behind a specific implementation can make it easier to understand the code later.
In the context of the AP® Computer Science A curriculum, understanding preconditions and postconditions is essential. A precondition outlines what must be true before a method or function runs, while a postcondition describes what should be true after execution. Including comments that specify these conditions can serve as a reminder to the programmer and aid in debugging.
The Reader’s Perspective
As someone who has been teaching computer science for five years, I spend a lot of time reading my students’ code. When students include comments above methods or complex sections, it helps me quickly grasp what the code is supposed to accomplish.
From a grading standpoint, commenting program code is invaluable. If a student states in a comment what their program is intended to do, and the program doesn’t achieve that goal, I can still assess their understanding and logic.
In real-world scenarios, commenting program code is even more critical. Many programming projects involve collaboration. Comments allow team members to understand one another’s contributions, facilitating seamless integration of the overall code.
Striking the Right Balance
There’s a sweet spot when it comes to commenting program code. Too few comments leave readers guessing about the code’s purpose and functionality. Too many comments, on the other hand, can clutter the code and make it harder to read. The goal is to include meaningful, concise comments that provide clarity without overwhelming the codebase.

AP Computer Science Principles Premium, 2025: Prep Book with 6 Practice Tests + Comprehensive Review + Online Practice (Barron’s AP Prep)
Be prepared for exam day with Barron’s. Trusted content from AP experts!
Barron’s AP Computer Science Principles Premium, 2025 includes in-depth content review and online practice. It’s the only book you’ll need to be prepared for exam day.
Commenting Program Code on AP® Exams
For the AP® Computer Science A exam, comments are not a requirement for free-response questions (FRQs). The focus is on testing a student’s knowledge of coding principles, not their ability to comment.
However, on the AP® Computer Science Principles exam, comments serve a different purpose. The Create task requires students to credit others for any borrowed code, graphics, or music. Commenting program code is an effective way to document these acknowledgments, ensuring students meet the requirements for proper attribution.
What Are Your Thoughts?
Do you encourage your students to comment on their program code? How do you teach them to find the balance between too few and too many comments? Share your strategies in the comments below—I’d love to learn from your experience!