Practice writing clear, professional code comments in English: verb tense, imperative style, brevity, and avoiding common mistakes.
0 / 17 completed
1 / 17
What verb form is recommended for single-line comments describing what a function does?
Third-person present tense is the standard for function and class docstrings: 'Returns the user by ID', 'Validates the input schema'. It reads as a factual description of what the function does.
2 / 17
What is wrong with this comment? // This function was written to handle edge cases
History-based comments ('was written to...', 'added for the Y feature') rot quickly. The code's git history captures this context better. Comments should describe what the code does or why a non-obvious choice was made.
3 / 17
Which of these is a good inline comment?
The best comments explain the non-obvious WHY: a specific constraint, a surprising limit, a workaround for a known bug. Restating what the code does (increment i, loop through users) adds no value.
4 / 17
What does 'imperative style' mean for docstring summaries?
PEP 257 (Python) recommends imperative style for docstring first lines: 'Do this', 'Return that'. Google style guides and many others agree. It reads like a command to the function: 'Fetch the user record...'
5 / 17
What is a 'TODO comment' and what information should it include?
TODO comments without ownership or context accumulate and are never resolved. Adding an owner, a brief description, and a ticket reference makes them actionable and traceable.
6 / 17
What is wrong with this comment style? // VERY IMPORTANT!!! Do not remove this line!!!
Shouting comments ('VERY IMPORTANT!!!') create alarm without explanation. Better: '// Required for CORS preflight — removing breaks cross-origin requests from the React app (see TICKET-456)'. The reason is what matters.
7 / 17
When should a comment NOT be written?
The worst comment is one that repeats what clear code already says. 'getUserById(id)' is self-documenting. Comments should add information the reader cannot derive from the code itself.
8 / 17
What is the correct way to write a deprecation notice in a code comment?
A useful deprecation comment names the replacement, states the version of removal, and links to a migration guide. This gives developers everything they need to migrate without searching for context.
9 / 17
Reviewer: 'This function calculates the total price of items in a shopping cart. It's slightly complex due to handling discounts and tax rates.'
Developer: (writes the following comment)
`// Calculate total cost, considering discounts and taxes.`
Which of these responses from Senior Dev would be most appropriate during this code review?
The developer's comment is good but could be improved. The senior developer is looking for a balance between clarity and conciseness – the original comment fulfills this well. Importantly, it avoids unnecessary technical jargon and focuses on *what* the function does, as requested by the reviewer. Option A highlights a valid concern about lack of detail, but the provided comment already addresses that sufficiently.
10 / 17
Reviewer: 'This function calculates the total price of items in a shopping cart. It's slightly complex due to handling discounts and tax rates.'
Developer: (writes the following comment)
`// Calculate total cost, considering discounts and taxes.`
Which of these responses from Senior Dev would be most appropriate during this code review?
The developer's comment is good but could be improved. The senior developer is looking for a balance between clarity and conciseness – the original comment fulfills this well. Importantly, it avoids unnecessary technical jargon and focuses on *what* the function does, as requested by the reviewer. Option A highlights a valid concern about lack of detail, but the provided comment already addresses that sufficiently.
11 / 17
Reviewer: 'This function calculates the total price of items in a shopping cart. It's slightly complex due to handling discounts and tax rates.'
Developer: (writes the following comment)
`// Calculate total cost, considering discounts and taxes.`
Which of these responses from Senior Dev would be most appropriate during this code review?
The developer's comment is good but could be improved. The senior developer is looking for a balance between clarity and conciseness – the original comment fulfills this well. Importantly, it avoids unnecessary technical jargon and focuses on *what* the function does, as requested by the reviewer. Option A highlights a valid concern about lack of detail, but the provided comment already addresses that sufficiently.
12 / 17
Reviewer: 'This function calculates the total price of items in a shopping cart. It's slightly complex due to handling discounts and tax rates.'
Developer: (writes the following comment)
`// Calculate total cost, considering discounts and taxes.`
Which of these responses from Senior Dev would be most appropriate during this code review?
The developer's comment is good but could be improved. The senior developer is looking for a balance between clarity and conciseness – the original comment fulfills this well. Importantly, it avoids unnecessary technical jargon and focuses on *what* the function does, as requested by the reviewer. Option A highlights a valid concern about lack of detail, but the provided comment already addresses that sufficiently.
13 / 17
Reviewer comments: 'This function processes user authentication. It's a critical component of our system and needs to be thoroughly documented.'
Developer writes the following comment:
`// Authenticate the user, using JWT...`
Which of the following best describes the style of this comment?
This comment utilizes an imperative style, which is generally suitable for short summaries. However, given the reviewer's emphasis on criticality and security, a more descriptive approach highlighting key aspects like JWT usage and potential vulnerabilities would be preferable. The 'Insufficient' option correctly identifies the lack of crucial context.
14 / 17
Slack message from a senior engineer to a junior developer:
'Can you add a comment explaining why we use this specific algorithm? It's not immediately obvious and could confuse future developers.'
Which of the following is the MOST appropriate type of comment to respond with?
The senior engineer's request highlights the importance of *why* a particular decision was made – not just *what* it does. The suggested comment directly addresses this by explaining the reasoning and acknowledging potential considerations like performance. Options A and B are purely technical descriptions lacking context; option C is too terse, while D is incorrect as it focuses on simplicity rather than justification.
15 / 17
PR description for a change to a database query.
'This PR optimizes the query for faster retrieval of customer data. The original query was slow and impacting performance.'
What is the BEST way to augment this description with a code comment within the SQL query itself?
The PR description already mentions optimization and the specific change (adding an index). The code comment should directly reflect that action within the SQL itself. Option A is too general. Option B describes *how* to do it but not the impact. Option D simply states a fact without providing context or explanation – it's redundant with the PR description.
16 / 17
Standup update from a developer:
'I'm working on refactoring the payment processing module. I've added comments to explain the logic and address potential future modifications.'
What is the PRIMARY goal of adding these comments in this scenario?
During a stand-up update, the focus is on communication and collaboration within the immediate team. Comments are most valuable when they clarify the developer's thought process and aid in understanding the code for other developers working on the same module – this allows for easier discussion and potential problem solving. The other options represent secondary or less relevant purposes.
17 / 17
API response (JSON):
{
'status': 'success',
'data': {
'message': 'User created successfully'
}
}
Which of the following is a suitable comment to add *above* this JSON object in the code?
The comment should provide context for the API call itself – what action triggered this response. Describing error handling or simply stating 'success' doesn't explain *why* that success occurred. The JSON data itself contains the specific message, so a broader explanation of the endpoint is needed.
What will I practice in "Code Comment Language Style (English)"?
This is a Code Comments exercise set. It walks through 17 scenario-based multiple-choice questions built around real usage of Code Comments terminology that IT professionals encounter on the job.
Is this exercise free to use?
Yes. Every exercise on CoderSlingo, including this one, is free to complete with no account, sign-up, or paywall.
How many questions are in this exercise?
This set contains 17 questions. Each one shows immediate feedback and a detailed explanation after you answer, so you learn the correct usage right away rather than waiting for a final score.
Do I need prior experience to complete this exercise?
No prior experience is required. Each question includes a full explanation covering the reasoning behind the correct answer, so the exercise itself teaches the Code Comments vocabulary as you go.
Can I retry the exercise if I get questions wrong?
Yes — use the "Try again" button on the results screen to reset your answers and go through all the questions again. There is no limit on attempts.
Is my progress saved?
Your answers and score for the current session are tracked in the browser as you go. No account or login is needed, and there is nothing to install.
What if I don't understand a term used in a question?
Read the explanation shown after you answer each question — it breaks down the correct term in plain English with a real-world example. You can also check the site Glossary for quick definitions.
How is this different from reading a blog article on the topic?
Exercises like this one are interactive drills that test and reinforce specific vocabulary through multiple-choice questions, while blog articles explain concepts in prose. Practising here after reading builds active recall, not just passive recognition.
Where can I find more Code Comments exercises?
See the Code Comments exercises hub for the full set of related pages, or browse all exercise categories from the main Exercises index.
Can I use this exercise to prepare for a technical interview?
Yes — Code Comments vocabulary comes up often in technical discussions and interviews. Pair this exercise with our dedicated Interview Preparation section for role-specific practice.