Skip to content

Commit 883a4ef

Browse files
Document approaches (#391)
Document approaches
1 parent edb4e28 commit 883a4ef

File tree

5 files changed

+337
-2
lines changed

5 files changed

+337
-2
lines changed

building/config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,13 @@
555555
"title": "Deprecated Exercises",
556556
"blurb": "Learn why and how to deprecate an Exercism exercise"
557557
},
558+
{
559+
"uuid": "e5b94b50-cff3-4fcb-8fbf-4a247202da97",
560+
"slug": "tracks/approaches",
561+
"path": "building/tracks/approaches.md",
562+
"title": "Approaches",
563+
"blurb": "Learn how to write approaches for exercises"
564+
},
558565
{
559566
"uuid": "8db530bb-e11b-4497-b088-5b4c997e09a2",
560567
"slug": "tracks/presentation",

building/tracks/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Tracks have two types of exercises:
2020
- Concept exercises: they are designed to teach one or more concepts to a student. Check the [documentation](/docs/building/tracks/concept-exercises) for more information.
2121
- Practice exercises: they are designed to practice learned concepts. Check the [documentation](/docs/building/tracks/practice-exercises) for more information.
2222

23+
Exercises can have approaches associated with them, which describe the different ways in which an exercise can be solved.
24+
Check the [documentation](/docs/building/tracks/approaches) for more information.
25+
2326
## Shared files
2427

2528
Some files are not specific to individual exercises, but are instead applicable to _all_ exercises. Check the [documentation](/docs/building/tracks/shared-files) for more information.

building/tracks/approaches.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Approaches
2+
3+
Each exercise can have approaches associated with them, which describe the different ways in which an exercise can be solved.
4+
5+
## Approach
6+
7+
An approach should explore how an exercise can be solved a certain way.
8+
9+
- Its contents should either:
10+
- Explore an idiomatic approach
11+
- Explore a non-idiomatic, but interesting approach
12+
- Contain a meta discussion (e.g. comparing the performance of approaches)
13+
- Include code samples
14+
- Feel free to dig deep into the topic
15+
- Link to useful resources (e.g. documentation)
16+
17+
## Approach overview
18+
19+
- Give context to the problem
20+
- Describe important points (e.g. gotchas) that apply to _all_ approaches
21+
- Discuss the most idiomatic approaches
22+
- Each approach should show a snippet illustrating the approach
23+
- Keep the content fairly high-level
24+
- Link to the idiomatic approach for more information
25+
- Discuss how to choose between the approaches
26+
- What are the trade-offs?
27+
- Are some approaches better suited for specific use cases?
28+
29+
## What exercises to write approaches for?
30+
31+
In general, [Practice Exercises](/docs/building/tracks/practice-exercises) are more suitable to write approaches for, as they usually can be solved in multiple ways.
32+
33+
For [Concept Exercises](/docs/building/tracks/concept-exercises), discussing the exemplar approach might be interesting. For example, you could show how the concept being taught makes certain code easier to write.

building/tracks/concept-exercises.md

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Concept Exercise metadata is defined in the `exercises.concept` key in the [conf
3030

3131
Each Concept Exercise has its own directory within the track's `exercises/concept` directory. The name of the Concept Exercise directory must match the `slug` property of the Concept Exercise, as defined in the [config.json file](/docs/building/tracks/config-json#concept-exercises).
3232

33-
A Concept Exercise has three types of files:
33+
A Concept Exercise has four types of files:
3434

3535
### Documentation files
3636

@@ -47,6 +47,15 @@ These files are _not_ presented to the student, but used to define metadata of t
4747
- `.meta/config.json`: contains meta information on the exercise (required)
4848
- `.meta/design.md`: describe the design of the exercise (required)
4949

50+
### Approach files
51+
52+
These files describe approaches for the exercise.
53+
54+
- `.approaches/introduction.md`: introduction to the most common approaches for the exercise (optional)
55+
- `.approaches/config.json`: metadata for the approaches (optional)
56+
- `.approaches/<approach-slug>/content.md`: description of the approach (optional)
57+
- `.approaches/<approach-slug>/snippet.txt`: snippet showcasing the approach (optional)
58+
5059
### Exercise files
5160

5261
The language-specific files, like the implementation and test files. The names of these files are track-specific.
@@ -62,6 +71,12 @@ The language-specific files, like the implementation and test files. The names o
6271
exercises
6372
└── concept
6473
└── cars-assemble
74+
├── .approaches
75+
| ├── performance (approach)
76+
| | ├── content.md
77+
| | └── snippet.txt
78+
| ├── config.json
79+
| └── introduction.md
6580
├── .docs
6681
| ├── introduction.md
6782
| ├── instructions.md
@@ -347,6 +362,137 @@ Note that:
347362

348363
---
349364

365+
### File: `.approaches/introduction.md`
366+
367+
**Purpose:** Introduction to the most common approaches for the exercise
368+
369+
**Presence:** Optional
370+
371+
This file describes the most common approaches for the exercise.
372+
Check the [documentation](/docs/building/tracks/approaches) for more information on what should go in this file.
373+
374+
#### Example
375+
376+
````markdown
377+
# Introduction
378+
379+
The key to this exercise is to deal with C# strings being immutable, which means that a `string`'s value cannot be changed.
380+
Therefore, to reverse a string you'll need to create a _new_ `string`.
381+
382+
## Using LINQ
383+
384+
```csharp
385+
public static string Reverse(string input)
386+
{
387+
return new string(input.Reverse().ToArray());
388+
}
389+
```
390+
391+
For more information, check the [LINQ approach][approach-linq].
392+
393+
## Which approach to use?
394+
395+
If readability is your primary concern (and it usually should be), the LINQ-based approach is hard to beat.
396+
````
397+
398+
---
399+
400+
### File: `.approaches/config.json`
401+
402+
**Purpose:** Metadata for the approaches
403+
404+
**Presence:** Optional (required when an approach introduction or approach exists)
405+
406+
This file contains meta information on the exercise:
407+
408+
- `introduction`: The GitHub username(s) of the exercise approach introduction's author(s) (optional)
409+
410+
- `authors`: The GitHub username(s) of the exercise approach introduction's author(s) (required)
411+
- Including reviewers if their reviews substantially change the exercise approach introduction (to the extent where it feels like "you got there together")
412+
- `contributors`: The GitHub username(s) of the exercise approach introduction's contributor(s) (optional)
413+
- Including reviewers if their reviews are meaningful/actionable/actioned.
414+
415+
- `approaches`: An array listing the detailed approaches (optional)
416+
- `uuid`: a V4 UUID that uniquely identifies the approach. The UUID must be unique both within the track as well as across all tracks, and must never change
417+
- `slug`: the approach's slug, which is a lowercased, kebab-case string. The slug must be unique across all approach slugs within the track. Its length must be <= 255.
418+
- `title`: the approach's title. Its length must be <= 255.
419+
- `blurb`: A short description of this approach. Its length must be <= 350. Markdown is _not_ supported (required)
420+
- `authors`: The GitHub username(s) of the exercise approach's author(s) (required)
421+
- Including reviewers if their reviews substantially change the exercise approach (to the extent where it feels like "you got there together")
422+
- `contributors`: The GitHub username(s) of the exercise approach's contributor(s) (optional)
423+
- Including reviewers if their reviews are meaningful/actionable/actioned.
424+
425+
#### Example
426+
427+
```json
428+
{
429+
"introduction": {
430+
"authors": ["erikschierboom"]
431+
},
432+
"approaches": [
433+
{
434+
"uuid": "448fb2b4-18ab-4e55-aa54-ad4ed6d5f7f6",
435+
"slug": "performance",
436+
"title": "Optimizing performance",
437+
"blurb": "Explore how to most efficiently reverse a string and what the trade-offs are.",
438+
"authors": ["erikschierboom"]
439+
}
440+
]
441+
}
442+
```
443+
444+
---
445+
446+
### File: `.approaches/<approach-slug>/content.md`
447+
448+
**Purpose:** Detailed description of the approach
449+
450+
**Presence:** Optional (required for approaches)
451+
452+
This file contains a detailed description of the approach.
453+
Check the [documentation](/docs/building/tracks/approaches) for more information on what should go in this file.
454+
455+
#### Example
456+
457+
```markdown
458+
# Performance
459+
460+
In this document, we'll find out which approach is the most performant one.
461+
462+
## Benchmark results
463+
464+
| Method | Mean | Error | StdDev | Median | Allocated |
465+
| -----: | --------: | --------: | --------: | --------: | --------: |
466+
| Linq | 29.133 ns | 0.5865 ns | 0.5486 ns | 28.984 ns | 80 B |
467+
| Array | 4.806 ns | 0.4999 ns | 1.4739 ns | 3.967 ns | - |
468+
```
469+
470+
---
471+
472+
### File: `.approaches/<approach-slug>/snippet.txt`
473+
474+
**Purpose:** Snippet showcasing the approach
475+
476+
**Presence:** Optional (required for approaches)
477+
478+
This file contains a small snippet that showcases the approach.
479+
The snippet is shown on an exercise's approaches overview page.
480+
481+
Its number of lines must be <= 8.
482+
483+
#### Example
484+
485+
```csharp
486+
Span<char> chars = stackalloc char[input.Length];
487+
for (var i = 0; i < input.Length; i++)
488+
{
489+
chars[input.Length - 1 - i] = input[i];
490+
}
491+
return new string(chars);
492+
```
493+
494+
---
495+
350496
### File: Stub implementation
351497

352498
**Purpose:** Provide a starting point for students.

0 commit comments

Comments
 (0)