Skip to content

Commit 7afd928

Browse files
committed
Add didactic comments across examples
1 parent 82ef7e9 commit 7afd928

202 files changed

Lines changed: 948 additions & 547 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,11 @@ The public PowerShell and Bash scripts are thin wrappers over the shared Python
8888
- recommended `## Cross-Language Notes` before `## What To Check`
8989
- Every implemented level README should include required `## Learning Metadata` before `## Module Order` with `Difficulty`, `Estimated Time`, `Prerequisites`, and `Study Strategy`.
9090
- Checkpoint README structure should mirror the matching C++ checkpoint style, not the module README contract.
91-
- Every `example/main.*` file should include intent-first comments for:
92-
- program flow,
93-
- input/validation blocks,
94-
- core algorithm or transformation blocks,
95-
- important branching decisions,
96-
- output/verification sections.
91+
- Every hand-written code file under `example/` should include intent-first comments:
92+
- a short file header comment that explains what the example teaches
93+
- comments before program flow, validation, core transformation, branching, or output blocks when those blocks are non-trivial
94+
- language-specific notes when the example is an adaptation rather than a direct translation of the C++ concept
95+
- no empty scaffolding comments such as `Intent:` and no line-by-line narration of obvious syntax
9796
- Every exercise file must contain complete, runnable content.
9897
- Avoid external dependencies and test frameworks for C++ modules.
9998
- Avoid external dependencies and test frameworks for non-C++ checkpoints.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ Checkpoint artifacts under `languages/<language>/projects/*` and `languages/<lan
138138

139139
## Example Commenting Standard
140140

141-
Example files (`example/main.*`) should use intent-first comments to help new developers read code quickly:
141+
Hand-written example code files under `languages/*/*/*/example/` should use intent-first comments to help new developers read code quickly:
142142

143-
- Explain purpose, intent, and edge-case handling.
144-
- Place comments before meaningful logic blocks (not every single line).
143+
- Start each file with a short header comment that explains what the example teaches.
144+
- Place comments before meaningful logic blocks, validation paths, and output/verification sections.
145+
- Use comments to explain concepts, tradeoffs, and language-specific adaptations, not obvious syntax.
145146
- Keep comments short, practical, and in English.
147+
- Avoid empty scaffolding comments such as `Intent:` or line-by-line narration.
146148

147149
## Validation and CI
148150

languages/cpp/01-foundations/arrays-and-vectors/example/main.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
// This example demonstrates arrays and vectors concepts.
2-
// Example purpose: show the module flow with clear, beginner-friendly steps.
1+
// This example shows storing related values in ordered collections and iterating safely.
2+
// In C++, the example keeps value flow, references, and explicit control visible.
33

44
#include <iostream>
55
#include <vector>
66
using namespace std;
77

8+
// Run one deterministic scenario so the console output makes storing related values in ordered
9+
// collections and iterating safely easy to verify.
810
int main() {
9-
// Program flow: collect input, apply core logic, then print a verifiable result.
11+
// Build the sample state first, then let the later output confirm the behavior step by step.
1012
const int fixedScores[3] = {72, 88, 95};
1113

12-
// Intent: print intermediate or final output for quick behavior verification.
14+
// Print the observed state here so learners can connect the code path to a concrete result.
1315
cout << "Fixed array values: ";
14-
// Intent: iterate through data in a clear and deterministic order.
1516
for (int i = 0; i < 3; ++i) {
1617
cout << fixedScores[i];
17-
// Intent: guard invalid or edge-case paths before the main path continues.
1818
if (i < 2) {
1919
cout << ", ";
2020
}
@@ -23,7 +23,6 @@ int main() {
2323

2424
int count = 0;
2525
cout << "How many temperatures do you want to enter? ";
26-
// Intent: gather typed input first so later operations are predictable.
2726
cin >> count;
2827

2928
if (count <= 0) {

languages/cpp/01-foundations/arrays-and-vectors/example/vector-filter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This helper example focuses on isolating one collection transformation so the filtering rule
2+
// stands out.
3+
14
#include <iostream>
25
#include <vector>
36

languages/cpp/01-foundations/control-flow/example/main.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
// This example demonstrates control flow concepts.
2-
// Example purpose: show the module flow with clear, beginner-friendly steps.
1+
// This example shows choosing between branches and repeating work with predictable control flow.
2+
// In C++, the example keeps value flow, references, and explicit control visible.
33

44
#include <iostream>
55
using namespace std;
66

7+
// Run one deterministic scenario so the console output makes choosing between branches and
8+
// repeating work with predictable control flow easy to verify.
79
int main() {
8-
// Program flow: collect input, apply core logic, then print a verifiable result.
10+
// Build the sample state first, then let the later output confirm the behavior step by step.
911
int value = 0;
10-
// Intent: print intermediate or final output for quick behavior verification.
12+
// Print the observed state here so learners can connect the code path to a concrete result.
1113
cout << "Enter an integer: ";
12-
// Intent: gather typed input first so later operations are predictable.
1314
cin >> value;
1415

15-
// Intent: guard invalid or edge-case paths before the main path continues.
1616
if (value > 0) {
1717
cout << value << " is positive.\n";
1818
} else if (value < 0) {
@@ -29,7 +29,6 @@ int main() {
2929
cout << "Factorial is not defined for negative integers.\n";
3030
} else {
3131
unsigned long long factorial = 1;
32-
// Intent: iterate through data in a clear and deterministic order.
3332
for (int i = 1; i <= n; ++i) {
3433
factorial *= static_cast<unsigned long long>(i);
3534
}

languages/cpp/01-foundations/control-flow/example/menu-loop.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This helper example focuses on focusing on the repeated menu interaction without distracting
2+
// setup code.
3+
14
#include <iostream>
25

36
using namespace std;

languages/cpp/01-foundations/formatted-output-and-iomanip/example/main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
// This example demonstrates formatted output and iomanip concepts.
2-
// Example purpose: show the module flow with clear, beginner-friendly steps.
1+
// This example shows formatting values so output is easier to read and compare.
2+
// In C++, the example keeps value flow, references, and explicit control visible.
33

44
#include <iomanip>
55
#include <iostream>
66
using namespace std;
77

8+
// Run one deterministic scenario so the console output makes formatting values so output is easier
9+
// to read and compare easy to verify.
810
int main() {
9-
// Program flow: collect input, apply core logic, then print a verifiable result.
11+
// Build the sample state first, then let the later output confirm the behavior step by step.
1012
const char* item1 = "Notebook";
1113
const char* item2 = "Pen";
1214
const char* item3 = "Backpack";
@@ -15,7 +17,7 @@ int main() {
1517
const double p2 = 1.2;
1618
const double p3 = 30.0;
1719

18-
// Intent: print intermediate or final output for quick behavior verification.
20+
// Print the observed state here so learners can connect the code path to a concrete result.
1921
cout << left << setw(12) << "Item" << right << setw(10) << "Price" << '\n';
2022
cout << "----------------------\n";
2123

languages/cpp/01-foundations/functions/example/function-overload-basics.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
// This helper example focuses on showing one focused overload or helper so the main example stays
2+
// easy to scan.
3+
14
#include <iostream>
25
#include <string>
36

47
using namespace std;
58

9+
// Keep this helper separate so the main example can focus on the larger idea without extra noise.
610
void printValue(int value) { cout << "Integer value: " << value << '\n'; }
711

812
void printValue(double value) { cout << "Double value: " << value << '\n'; }

languages/cpp/01-foundations/functions/example/main.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// This example demonstrates functions concepts.
2-
// Example purpose: show the module flow with clear, beginner-friendly steps.
1+
// This example shows breaking behavior into reusable functions with clear inputs and outputs.
2+
// In C++, the example keeps value flow, references, and explicit control visible.
33

44
#include <iostream>
55
#include <vector>
66
using namespace std;
77

8+
// Define the reusable pieces first so the main flow can focus on one observable scenario.
89
int sum(int a, int b) { return a + b; }
910

1011
void swapByReference(int& left, int& right) {
@@ -14,12 +15,9 @@ void swapByReference(int& left, int& right) {
1415
}
1516

1617
void printVector(const vector<int>& values) {
17-
// Intent: print intermediate or final output for quick behavior verification.
1818
cout << "[";
19-
// Intent: iterate through data in a clear and deterministic order.
2019
for (size_t i = 0; i < values.size(); ++i) {
2120
cout << values[i];
22-
// Intent: guard invalid or edge-case paths before the main path continues.
2321
if (i + 1 < values.size()) {
2422
cout << ", ";
2523
}
@@ -37,8 +35,11 @@ void incrementByReference(int& number) {
3735
cout << "Inside incrementByReference: " << number << '\n';
3836
}
3937

38+
// Run one deterministic scenario so the console output makes breaking behavior into reusable
39+
// functions with clear inputs and outputs easy to verify.
4040
int main() {
41-
// Program flow: collect input, apply core logic, then print a verifiable result.
41+
// Build the sample state first, then let the later output confirm the behavior step by step.
42+
// Print the observed state here so learners can connect the code path to a concrete result.
4243
cout << "sum(4, 6) = " << sum(4, 6) << '\n';
4344

4445
int first = 10;

languages/cpp/01-foundations/operators-and-expressions/example/main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
// This example demonstrates operators and expressions concepts.
2-
// Example purpose: show the module flow with clear, beginner-friendly steps.
1+
// This example shows combining values through expressions and readable calculations.
2+
// In C++, the example keeps value flow, references, and explicit control visible.
33

44
#include <iostream>
55
using namespace std;
66

7+
// Run one deterministic scenario so the console output makes combining values through expressions
8+
// and readable calculations easy to verify.
79
int main() {
8-
// Program flow: collect input, apply core logic, then print a verifiable result.
10+
// Build the sample state first, then let the later output confirm the behavior step by step.
911
const int a = 17;
1012
const int b = 5;
1113

12-
// Intent: print intermediate or final output for quick behavior verification.
14+
// Print the observed state here so learners can connect the code path to a concrete result.
1315
cout << "a = " << a << ", b = " << b << "\n\n";
1416
cout << "a + b = " << (a + b) << '\n';
1517
cout << "a - b = " << (a - b) << '\n';

0 commit comments

Comments
 (0)