Skip to content

Commit d3ff6a8

Browse files
configlet create usage (#488)
* Document configlet create in add-initial-exercises * Add more documentation for new tracks
1 parent 3a27113 commit d3ff6a8

File tree

2 files changed

+106
-40
lines changed

2 files changed

+106
-40
lines changed

building/tracks/new/add-first-exercise.md

+76-33
Original file line numberDiff line numberDiff line change
@@ -23,52 +23,95 @@ The "Hello, World!" exercise has some special rules applied to it:
2323
- It has no `prerequisites`
2424
- It has no `practices`
2525

26-
### Updating the config
26+
### Determine file paths
2727

28-
Start by adding an entry to the `exercises.practice` array in the top-level `config.json` file.
28+
The "Hello, World!" exercise (and indeed, _all_ exercises on Exercism) requires a specific set of files:
2929

30-
```
31-
{
32-
"exercises": {
33-
"practice": [
34-
{
35-
"uuid": "",
36-
"slug": "hello-world",
37-
"name": "Hello World",
38-
"practices": [],
39-
"prerequisites": [],
40-
"difficulty": 1
41-
}
42-
]
43-
}
30+
- Documentation: explain to the student what they need to do (can be auto-generated).
31+
- Metadata: provides Exercism with some metadata on the exercise (can be mostly auto-generated).
32+
- Test suite: verifies a solution's correctness (track-specific).
33+
- Stub implementation: provided a starting point for students (track-specific).
34+
- Example implementation: provides an example implementation that passes all the tests (track-specific).
35+
- Additional files: ensure that the tests can run (track-specific, optional).
36+
37+
Before we can create the "Hello, World!" exercise, you need to make some decisions about the track-specific filenames and file paths (test suite, stub implementation, example implementation and any additional files).
38+
39+
The rule of thumb is to use names that are idiomatic for the language.
40+
Where there are no strong preferences, prefer shallower directory structures.
41+
The example implementation will need to be identifiable by the CI script, so it's advisable to choose a generic basename that all exercises can use, e.g. `example`, `sample`, or `reference-solution`.
42+
43+
#### Configuring file paths
44+
45+
Having chosen the track-specific file paths, you should configure them in the `files` key in the root `config.json` file.
46+
The `files` key will serve as the template for all exercises, which allows any tooling (some of which we'll use in a second) to know where to look for files.
47+
You can use various placeholders to allow for easy configuring of the exercise's slug (`hello-world` in this case).
48+
49+
##### Example
50+
51+
If your track uses PascalCase for its files, the `files` key might look like this:
52+
53+
```json
54+
"files": {
55+
"solution": [
56+
"%{pascal_slug}.cs"
57+
],
58+
"test": [
59+
"%{pascal_slug}Tests.cs"
60+
],
61+
"example": [
62+
".meta/Example.cs"
63+
]
4464
}
4565
```
4666

47-
You can use the [Configlet][configlet] tool to get a UUID.
48-
Download Configlet by running `bin/fetch-configlet` from the root of the repository.
49-
Then generate a UUID using the `bin/configlet uuid` command.
67+
```exercism/note
68+
The example file(s) should be stored within the `.meta` directory.
69+
```
5070

51-
### Generating required files
71+
For more information, check the [`files` key documentation](/docs/building/tracks/config-json#files).
5272

53-
To implement the "Hello, World!" exercise, you'll need to create several files.
54-
Which files exactly is described in the [Practice Exercises documentation](/docs/building/tracks/practice-exercises).
73+
### Creating files
5574

56-
Most of the files can be added automatically by running Configlet's `sync` command:
75+
Having specified the file path templates, you can then quickly scaffold the "Hello, World!" exercise's files by running the following commands from the track's root directory:
5776

77+
```shell
78+
bin/fetch-configlet
79+
bin/configlet create --practice-exercise hello-world
5880
```
59-
bin/configlet sync --update --yes --docs --metadata --exercise hello-world
60-
bin/configlet sync --update --tests include --exercise hello-world
61-
```
6281

63-
In addition to the generated files, you will to create a test suite, a stub solution that serves as the starting point for the student, and a sample solution that passes all the tests to verify it is possible to solve the exercise (CI will verify this).
82+
### Implement exercise
83+
84+
Once the scaffolded files have been created, you'll then have to:
85+
86+
- Add tests to the tests file
87+
- Add an example implementation
88+
- Define the stub file's contents
89+
- Within the exercise's `.meta/config.json` file:
90+
- Add the GitHub username of the exercise's authors to the `authors` key
91+
92+
#### Add tests
93+
94+
A key part of adding an exercise is adding tests.
95+
Rougly speaking, there are two options when implementing one of the above exercises:
96+
97+
1. Implement the tests from scratch, using the test cases from the [exercise's `canonical-data.json`][canonical-data.json]
98+
2. Port the tests from another track's implementation (tip: go to `https://exercism.org/exercises/hello-world` to get an overview of which tracks have implemented a specific exercise).
99+
100+
For the "Hello, World!" exercise, there will only be one test case, so either option should be fine.
101+
102+
#### Add example implementation
103+
104+
The example implementation file should contain the code requires to solve the tests.
105+
106+
#### Define the stub
64107

65-
In order to create these files, you need to make some decisions about filenames and file paths.
66-
The rule of thumb is to use names that are idiomatic for the language, and where there are no strong preferences prefer shallower directory structures.
67-
The sample solution will need to be identifiable by the CI script, so it's advisable to choose a generic basename that all exercises can use, e.g. `example`, `sample`, or `reference-solution`.
108+
The stub file should have an _almost_ working solution to the tests, but with the "Hello, World!" text replaced with "Goodbye, Mars!".
109+
Tip: just can copy-paste-modify the example solution.
68110

69-
### Configuring the exercise
111+
### Update the exercise's author(s)
70112

71-
One you've decided on the filenames and paths, edit the `exercises/practice/hello-world/.meta/config.json` file to reflect those choices.
72-
Also add your GitHub username to the `"authors"` array.
113+
Once you're done with the exercise, please add your your GitHub username to the `"authors"` array in the exercise's `.meta/config.json` file.
114+
This will ensure we correctly credit you with having created the exercise.
73115

74116
[configlet]: /docs/building/configlet
117+
[canonical-data.json]: (https://github.com/exercism/problem-specifications/blob/main/exercises/hello-world/canonical-data.json)

building/tracks/new/add-initial-exercises.md

+30-7
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,46 @@ To make this all a bit more concrete, this is what a sample selection of initial
103103

104104
## Implement exercises
105105

106+
### Scaffold exercise
107+
106108
Having selected the exercises you want include in your track, the next step is to implement them.
107-
Each of the above-mentioned exercises has three bits of information:
109+
You can quickly scaffold a new Practice Exercise by running the following commands from the track's root directory:
110+
111+
```shell
112+
bin/fetch-configlet
113+
bin/configlet create --practice-exercise <slug>
114+
```
115+
116+
For more information, check the [`configlet create` docs](/docs/building/configlet/create)
117+
118+
### Implement exercise
119+
120+
Once the scaffolded files have been created, you'll then have to:
121+
122+
- Add tests to the tests file
123+
- Add an example implementation
124+
- Define the stub file's contents
125+
- Within the exercise's `.meta/config.json` file:
126+
- Add the GitHub username of the exercise's authors to the `authors` key
127+
- Within the track's `config.json` file:
128+
- Check/update the exercise's difficulty
129+
- Add concepts to the `practices` key (only required when the track has concept exercises)
130+
- Add concepts to the `prerequisites` key (only required when the track has concept exercises)
108131

109-
1. `description.md`: explains what the exercise is about (required)
110-
2. `metadata.toml`: metadata like the exercise's blurb (required)
111-
3. `canonical-data.json`: a set of input/output combinations that describe the behavior of the exercise (optional)
132+
#### Add tests
112133

113-
There are two options when implementing one of the above exercises:
134+
A key part of adding an exercise is adding tests.
135+
Rougly speaking, there are two options when adding tests for one of the above exercises:
114136

115-
1. Implement the exercise from scratch, using the test cases in the `canonical-data.json` file.
116-
2. Port an implementation of the exercise from another track.
137+
1. Implement the tests from scratch, using the test cases from the exercise's `canonical-data.json` file as found in the [problem-specifications repo][problem-specifications-exercises].
138+
2. Port the tests from another track's implementation (tip: go to `https://exercism.org/exercises/<slug>` to get an overview of which tracks have implemented a specific exercise).
117139

118140
The second option can be particularly appealing, as it can give you results quickly.
119141
Keep in mind, though, that you should tweak the implementation to best fit your track.
120142
As an example, some tracks do not use classes but only work with functions.
121143
If your track usually works with objects though, you should adapt the implementation to what best fits your track.
122144

145+
[problem-specifications-exercises]: https://github.com/exercism/problem-specifications/tree/main/exercises/
123146
[allergies]: https://github.com/exercism/problem-specifications/tree/main/exercises/allergies
124147
[alphametics]: https://github.com/exercism/problem-specifications/tree/main/exercises/alphametics
125148
[bank-account]: https://github.com/exercism/problem-specifications/tree/main/exercises/bank-account

0 commit comments

Comments
 (0)